oms/backend/test/app/lib/dgjOrderPlatformRule.test.js
liufumingren 6ffe7cc889 fix(waybill): 1688 分销单换算后按原始平台回读订单(域名回退)
平台换算只用于「选对模板」,订单行仍留在店管家原始平台分区,域名必须按
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>
2026-11-07 05:44:57 +08:00

92 lines
4.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const { assert } = require('egg-mock/bootstrap');
const DgjService = require('../../../app/lib/printPlatform/dgj');
/** 构造一个最小可用的店管家平台服务(normalizeOrder 不触网) */
function buildService() {
return new DgjService({ platform: { code: 'dgj', name: '店管家' }, account: { token: 't', cookie: 'c' } });
}
/**
* 造一条店管家订单行
* @param overrides
*/
function buildRow(overrides = {}) {
return {
LogicOrderId: '10000279767413',
PlatformOrderId: '5127406131122008631',
PlatformType: 'Alibaba',
ShopId: '7398588',
ShopName: '13668975305(意洁)',
ErpState: 'waitsellersend',
CreateTime: '2026-11-06 10:00:00',
UpdateTime: '2026-11-06 10:05:00',
TotalAmount: 10,
ToName: '张三',
ToPhone: '13800000000',
SubOrders: [{ OrderItemId: '1', ProductID: '100', Count: 1, Price: 10, OrderItemCode: 'SKU-1' }],
...overrides,
};
}
describe('printPlatform/dgj normalizeOrder 平台换算硬规则', () => {
const service = buildService();
it('1688 抖音分销单 → 抖音小店', () => {
const row = buildRow({
Tags: [{ Tag: 'OutChannel', TagValue: 'douyin', Platform: 'Alibaba' }],
});
const order = service.normalizeOrder(row);
console.log('抖音分销:', order.platform_code, order.platform_name, order.distribute_channel, order.original_platform_code);
assert.strictEqual(order.platform_code, 'DYXD');
assert.strictEqual(order.platform_name, '抖音小店');
assert.strictEqual(order.distribute_channel, 'douyin');
assert.strictEqual(order.original_platform_code, '1688');
// 原始平台类型仍留痕
assert.strictEqual(order.platform_type, 'Alibaba');
});
it('1688 非分销单(无 OutChannel 标签)→ 淘宝', () => {
const order = service.normalizeOrder(buildRow({ Tags: [] }));
console.log('非分销:', order.platform_code, order.platform_name, order.distribute_channel);
assert.strictEqual(order.platform_code, 'TB');
assert.strictEqual(order.platform_name, '淘宝');
assert.strictEqual(order.distribute_channel, null);
assert.strictEqual(order.original_platform_code, '1688');
});
it('1688 未识别的分销渠道 → 其他(保留渠道与原始报文)', () => {
const order = service.normalizeOrder(buildRow({
Tags: [{ Tag: 'OutChannel', TagValue: 'thyny_plaintext' }],
}));
console.log('未知渠道:', order.platform_code, order.platform_name, order.distribute_channel);
assert.strictEqual(order.platform_code, 'OTHER');
assert.strictEqual(order.platform_name, '其他');
assert.strictEqual(order.distribute_channel, 'thyny_plaintext');
assert.strictEqual(order.original_platform_code, '1688');
// 原始报文完整保留(后续再做渠道映射时要用)
assert.deepStrictEqual(order.raw.Tags, [{ Tag: 'OutChannel', TagValue: 'thyny_plaintext' }]);
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');
const douyin = service.normalizeOrder(buildRow({ PlatformType: 'TouTiao', Tags: [] }));
assert.strictEqual(douyin.platform_code, 'DYXD');
const pdd = service.normalizeOrder(buildRow({ PlatformType: 'Pinduoduo', Tags: [] }));
assert.strictEqual(pdd.platform_code, 'PDD');
});
});