From 6ffe7cc889442cc47cd3efc01d4b0dd9ca7924db Mon Sep 17 00:00:00 2001 From: liufumingren Date: Sat, 7 Nov 2026 05:44:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(waybill):=201688=20=E5=88=86=E9=94=80?= =?UTF-8?q?=E5=8D=95=E6=8D=A2=E7=AE=97=E5=90=8E=E6=8C=89=E5=8E=9F=E5=A7=8B?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E5=9B=9E=E8=AF=BB=E8=AE=A2=E5=8D=95=EF=BC=88?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E5=9B=9E=E9=80=80=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 平台换算只用于「选对模板」,订单行仍留在店管家原始平台分区,域名必须按 extend_props.original_platform_code 推导,否则会用错域名被判「平台已查不到」。 - fetchWaybillNo:新增 originalPlatformCode,用原始平台算订单域名;waybillGet 从 extend_props 透传 - fetchRowsForVerify:拉单核对/自动作废按原始平台选域名,并给候选行补 extend_props - checkPlatformFinished:审核前已发货校验按原始平台选域名 - externalSendSync.resolveTarget:发货回传 PlatformType 优先按原始平台 实测同一条 1688 分销单:fxali 命中(ErpState=waitsellersend),fxdd 查不到。 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- backend/app/lib/printPlatform/dgj.js | 8 ++++++-- backend/app/lib/waybillGet.js | 3 +++ backend/app/service/externalPrintOrder.js | 15 ++++++++++++--- backend/app/service/externalSendSync.js | 12 +++++++++++- backend/test/app/lib/dgjOrderPlatformRule.test.js | 8 ++++++++ 店管家取号-旧系统提取.md | 7 +++++++ 6 files changed, 47 insertions(+), 6 deletions(-) diff --git a/backend/app/lib/printPlatform/dgj.js b/backend/app/lib/printPlatform/dgj.js index da733da..11c0884 100644 --- a/backend/app/lib/printPlatform/dgj.js +++ b/backend/app/lib/printPlatform/dgj.js @@ -2230,8 +2230,12 @@ class DgjService extends PrintPlatformService { const templateId = String(template.template_id || (template.raw && template.raw.Id) || '').trim(); if (!templateId) throw new Error('取号缺少面单模板ID:请先在「外部打单平台 → 快递接口」为编码绑定模板'); - // 订单/取号走「订单域名」,与模板域名不同(视频号订单只在 fxali 能查到) - const host = resolveOrderHost(template.platform_type); + // 订单/取号走「订单域名」,与模板域名不同(视频号订单只在 fxali 能查到)。 + // 1688 分销单在 OMS 里被换算成抖音小店/淘宝(为了选对模板),但订单行仍在 Alibaba 分区, + // 域名必须按「订单原始平台」算,否则回读订单行会查错域名 + const originalCode = String(options.originalPlatformCode || '').trim(); + const originalPlatformType = originalCode ? DgjService.resolvePlatformType(originalCode) : ''; + const host = resolveOrderHost(originalPlatformType || template.platform_type); let traceId = ''; try { diff --git a/backend/app/lib/waybillGet.js b/backend/app/lib/waybillGet.js index 7188bd8..21a3fa0 100644 --- a/backend/app/lib/waybillGet.js +++ b/backend/app/lib/waybillGet.js @@ -553,6 +553,8 @@ async function callPlatform(ctx, { principalId, warehouseId, code, expressCode, const caiNiaoAuthInfoId = template.cai_niao_auth_info_id == null ? null : Number(template.cai_niao_auth_info_id); const orderPlain = order.get ? order.get({ plain: true }) : { ...order }; + // 1688 分销单被换算成抖音小店/淘宝后,取号域名仍要按原始平台(否则回读订单行查错域名) + const extendProps = orderPlain.extend_props && typeof orderPlain.extend_props === 'object' ? orderPlain.extend_props : {}; // 包裹序号:报文显式指定优先(拆单场景),否则按单号尾部 `_N` 推导 const explicitIndex = pickPackageIndex(item); const packageIndex = explicitIndex === null ? resolvePackageIndex(code) : explicitIndex; @@ -560,6 +562,7 @@ async function callPlatform(ctx, { principalId, warehouseId, code, expressCode, template: template.get ? template.get({ plain: true }) : template, expressCode, platformCode, + originalPlatformCode: extendProps.original_platform_code || '', packageIndex, }); const waybill = normalizeWaybill(fetched); diff --git a/backend/app/service/externalPrintOrder.js b/backend/app/service/externalPrintOrder.js index df1b88f..30d6016 100644 --- a/backend/app/service/externalPrintOrder.js +++ b/backend/app/service/externalPrintOrder.js @@ -234,7 +234,7 @@ class ExternalPrintOrderService extends Service { shop_id: shop.id, place_order_time: { [Op.between]: [ start, end ] }, }, - attributes: [ 'id', 'order_no', 'parent_order_no', 'place_order_time', 'source_platform_code' ], + attributes: [ 'id', 'order_no', 'parent_order_no', 'place_order_time', 'source_platform_code', 'extend_props' ], raw: true, }); const targets = candidates @@ -291,7 +291,11 @@ class ExternalPrintOrderService extends Service { const byHost = new Map(); for (const row of targets) { - const host = resolveHost(String(row.source_platform_code || '')); + // 域名必须按「订单实际所在平台」算:1688 分销单在 OMS 里被换算成抖音小店/淘宝(为了选对模板), + // 但订单行仍在 Alibaba 分区(fxali),用换算后的编码回读会查错域名 → 被误判「平台已查不到」而作废 + const raw = row.extend_props && typeof row.extend_props === 'object' ? row.extend_props : {}; + const originalCode = String(raw.original_platform_code || '').trim(); + const host = resolveHost(originalCode || String(row.source_platform_code || '')); if (!host) continue; if (!byHost.has(host)) byHost.set(host, []); byHost.get(host).push(String(row.parent_order_no)); @@ -373,7 +377,12 @@ class ExternalPrintOrderService extends Service { attributes: [ 'id', 'platform_type', 'dbname' ], order: [[ 'id', 'ASC' ]], }); - const platformType = template ? template.platform_type : resolvePlatformType(platformCode); + // 平台类型只用于选「订单域名」:1688 分销单被换算成抖音小店/淘宝后,订单行仍在 Alibaba 分区, + // 必须按原始平台算,否则回读会查错域名 → 查不到订单 → 校验形同失效 + const raw = order.extend_props && typeof order.extend_props === 'object' ? order.extend_props : {}; + const originalCode = String(raw.original_platform_code || '').trim(); + const originalPlatformType = originalCode ? resolvePlatformType(originalCode) : ''; + const platformType = originalPlatformType || (template ? template.platform_type : resolvePlatformType(platformCode)); if (!platformType) return result; result.applicable = true; diff --git a/backend/app/service/externalSendSync.js b/backend/app/service/externalSendSync.js index c551ddd..f9eff46 100644 --- a/backend/app/service/externalSendSync.js +++ b/backend/app/service/externalSendSync.js @@ -230,7 +230,17 @@ class ExternalSendSyncService extends Service { attributes: [ 'id', 'platform_type', 'dbname' ], order: [[ 'id', 'ASC' ]], }); - const platformType = template ? template.platform_type : (typeof resolvePlatformType === 'function' ? resolvePlatformType(platformCode) : ''); + // PlatformType(决定回传发货用哪个域名)优先按「订单原始平台」:1688 分销单在 OMS 里被换算成 + // 抖音小店/淘宝(为了选对模板),但订单行仍在 Alibaba 分区(fxali),按换算后的平台找会查错域名 + const raw = order.extend_props && typeof order.extend_props === 'object' ? order.extend_props : {}; + const originalCode = String(raw.original_platform_code || '').trim(); + let platformType = ''; + if (originalCode && typeof resolvePlatformType === 'function') { + platformType = resolvePlatformType(originalCode) || ''; + } + if (!platformType) { + platformType = template ? template.platform_type : (typeof resolvePlatformType === 'function' ? resolvePlatformType(platformCode) : ''); + } if (!platformType) return null; return { service, account, platformType, dbname: template ? template.dbname : '', platformCode }; } diff --git a/backend/test/app/lib/dgjOrderPlatformRule.test.js b/backend/test/app/lib/dgjOrderPlatformRule.test.js index d4a5804..5930042 100644 --- a/backend/test/app/lib/dgjOrderPlatformRule.test.js +++ b/backend/test/app/lib/dgjOrderPlatformRule.test.js @@ -70,6 +70,14 @@ describe('printPlatform/dgj normalizeOrder 平台换算硬规则', () => { assert.strictEqual(order.platform_type, 'Alibaba'); }); + it('换算后取号/回读仍按原始平台选订单域名', () => { + // 1688 分销单换算成抖音小店,但订单数据仍在 1688 域名下 + assert.strictEqual(DgjService.resolveOrderHost(DgjService.resolvePlatformType('1688')), 'fxali.dgjapp.com'); + // 真实抖音单/淘宝单各自域名不变(淘宝与 1688 同域,走兜底 fxali) + assert.strictEqual(DgjService.resolveOrderHost(DgjService.resolvePlatformType('DYXD')), 'fxdd.dgjapp.com'); + assert.strictEqual(DgjService.resolveOrderHost(DgjService.resolvePlatformType('TB')), 'fxali.dgjapp.com'); + }); + it('其它平台不受该硬规则影响', () => { const taobao = service.normalizeOrder(buildRow({ PlatformType: 'Taobao', Tags: [] })); assert.strictEqual(taobao.platform_code, 'TB'); diff --git a/店管家取号-旧系统提取.md b/店管家取号-旧系统提取.md index beb5057..edb9875 100644 --- a/店管家取号-旧系统提取.md +++ b/店管家取号-旧系统提取.md @@ -180,6 +180,13 @@ Filters[2] TableAlias=pfn FieldType=int TableName=PathFlowNode Name=UpFxUs `orders.external_data` 保留店管家完整报文(含 `Tags`),后续做渠道映射时直接可用。 历史数据由迁移 `20261107020000-convert-1688-orders-to-real-waybill-platform` 按同一规则换算。 +⚠️ **域名口径(换算后必须按原始平台算)**:订单行始终留在店管家原始平台的分区(1688 → `Alibaba` → `fxali.dgjapp.com`), +换算是为了「选对模板」,不能连带改域名。因此凡是「按订单读/写平台数据」的地方都用 +`extend_props.original_platform_code` 推导 PlatformType 与域名:取号回读订单行(`fetchWaybillNo` 的 `originalPlatformCode`)、 +拉单核对/作废(`fetchRowsForVerify`)、审核前已发货校验(`checkPlatformFinished`)、发货回传(`externalSendSync.resolveTarget`)。 +实测同一条 1688 分销单:`fxali` 命中(`ErpState=waitsellersend`),`fxdd` 查不到——用错的域名会被判「平台已查不到」而误作废。 +模板查找仍按换算后的平台编码(`source_platform_code`),因为模板必须与下游渠道一致。 + #### 4.2.2「所在区」的刷新(手动 + 定时) `DbAreas` 会随平台迁移分区、商家解绑而变化,声明过期会让拉单查错分区或漏单,因此 `shopAreaSync` 负责刷新: