数据链路盘点

mercury 原始层 → SaaS 中间表 → REST API → Web · 2026-09-18 · 财务源表化改造后

一句话结论:屏蔽层存在(SaaS 侧 27+ 张中间表就是"清洗后的干净库",Web 不直接读 mercury raw)。真正的问题不是"缺一层",而是中间表有多套、口径没对齐——这次 onno 漏单就是 amazon_orders(订单视图灌)与 finance_monthly(财务事件灌)两张中间表口径不一致导致的。
raw 原始层(mercury) SaaS 中间表(清洗/转换) API / Web(消费)

01链路总图

raw 原始层 · mercury (222)
zipforce_amazon.spapi_orders / spapi_finances / spapi_settlements / spapi_order_items / spapi_refunds
onno_amazon.spapi_* · fittingirls_amazon.spapi_*
zipforce_noon.* / onno_noon.*
shared.mapping_zipforce / mapping_onno / mapping_fittingirls
mercury 视图 · 清洗逻辑①
v_onno_orders_unified
v_fittingirls_order_finance_detail
v_inventory_health / v_asin_daily
ingest222 灌入时转换
汇率fx · 状态 · 品牌 · SKU聚合
SaaS 中间表 · 清洗逻辑②
amazon_orders / order_fees
finance_monthly / monthly_pl
amazon_settlement_monthly / amazon_refund_monthly
ads_* / noon_* / rankings_daily / inventory_health / sku_mapping / products
REST API → Web
finance.py 等(源表直读 amazon_orders+order_fees)
FastAPI → Next.js

关键:清洗逻辑散落在两处——mercury 视图(①)和 ingest222 灌入 SQL(②)。口径没人统一管,是漂移根源。

02中间表明细(27+ 张,按平台分组)

SaaS 中间表mercury 源转换消费方
amazon_ordersraw v_onno_orders_unified 等视图汇率fx→revenue_usd · days_waiting · is_abnormal · SKU聚合sku_list · 状态中文API 财务/订单/看板
order_feesraw spapi_finances + noon费用 abs() · 逐单 commission/fba/promo/other(USD)API 财务
finance_monthlyraw spapi_financesSKU×marketplace×月聚合 · 汇率fx · 漏onno已弃用 财务已改源表
monthly_plraw spapi_finances + settlements三方对账口径(posted_date)· 项目×月 P&LAPI /finance/monthly(保留)
amazon_settlement_monthlyraw spapi_settlements按月聚合回款 payout_usdAPI 财务
amazon_refund_monthlyraw spapi_refunds按月/SKU 聚合退货 unitsAPI 财务
ads_daily / amazon_ads_daily / noon_ads_dailyraw ads_* 各表按日/SKU/国家聚合 spend/salesAPI 广告
noon_orders / noon_inventory / noon_sku_*raw noon_orders / inventory_aging / ads_skusNoon 专用口径 · n2p SKU映射 · 库龄桶API Noon 模块
sku_mapping / productsraw shared.mapping_*品牌映射(zipforce/onno/fittingirls)· 成本 cost_rmbAPI 全站
sales_hourly / rankings_daily / inventory_healthraw spapi_* / rankings / inventory_fba分时订单 · 排名 · 库存健康(stock_days/状态)API 看板

03核心转换口径(写死)

口径规则位置
汇率折算revenue_usd = amount / fx(currency)222 官方 fx() 函数
有效订单order_status NOT IN ('Canceled','Cancelled')ingest222 + 接口统一
品牌映射shared.mapping_{zipforce,onno,fittingirls}sku_mapping
净额net = revenue_usd − commission − fba − promo − otherorder_fees(USD)
SKU 拆分金额/费用按 sku_list 逗号展开平摊(多SKU单约9%)接口层
country→marketplacemarketplaces 表映射(GB→UK 特例)接口层
灌入方式upsert(ON CONFLICT DO UPDATE)· amazon_orders 全量时 DELETE 幽灵行ingest222 · 每日 04:30

04对照理想架构的缺口

缺口① 清洗逻辑分散在两处。mercury 视图(①)+ ingest222 SQL(②)各管一摊,改一处不知道影响哪些表。这次 onno 漏单就是 amazon_orders 与 finance_monthly 口径不一致的直接后果。
缺口② 无订单状态快照。amazon_orders 是当前状态,历史报表会随后续退款/状态变更漂移(说明书第6节的快照机制可解)。
缺口③ 无系统化对账审计。有 audit_log 但无金额勾稽/库存平衡等规则引擎(说明书第9节)。
缺口④ 无原始报文溯源。raw 在 mercury,SaaS 不存完整 API 报文(说明书第12节的对象存储方案)。

05建议(等你拍板)

本页为盘点文档,供决策参考。具体改造范围与时机由用户拍板后执行。