生产实测:1688 单的 `OutChannel=thyny`(密文淘宝分销单,订单号形如 5127404439433014429) 没有进渠道映射表,落库成了「其他(OTHER)」,取号时匹配不到菜鸟模板 (2 单:dgj-10000290937711 等)。业务确认 thyny 就是淘宝分销渠道。 - DISTRIBUTE_CHANNEL_PLATFORM 增加 thyny → TB - 单测:密文 thyny → TB / 淘宝;未识别渠道改用 chaoshibianli → OTHER(thyny 已有映射) - 文档 §4.2 换算表、§4.2.6「已确认的渠道映射」、.github/copilot-instructions.md 同步 存量:这 2 单重新拉单即从 OTHER 变成淘宝,可用 YUNDA(TB → 12362952 菜鸟韵达一联4)取号。 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
169 lines
7.8 KiB
JavaScript
169 lines
7.8 KiB
JavaScript
'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 明文抖音分销单(douyin_plaintext)→ 淘宝(店管家没有抖店原单号,抖店面单取不到)', () => {
|
||
const row = buildRow({
|
||
ExtField1: 'douyin',
|
||
Tags: [{ Tag: 'OutChannel', TagType: 'Order', TagValue: 'douyin_plaintext' }],
|
||
OrderTags: [{ Tag: 'OutChannel', TagType: 'Order', TagValue: 'douyin_plaintext' }],
|
||
});
|
||
const order = service.normalizeOrder(row);
|
||
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, 'douyin_plaintext');
|
||
});
|
||
|
||
it('1688 明文快手分销单(kuaishou_plaintext)→ 淘宝', () => {
|
||
const order = service.normalizeOrder(buildRow({
|
||
ExtField1: 'kuaishou',
|
||
Tags: [{ Tag: 'OutChannel', TagType: 'Order', TagValue: 'kuaishou_plaintext' }],
|
||
}));
|
||
assert.strictEqual(order.platform_code, 'TB');
|
||
assert.strictEqual(order.distribute_channel, 'kuaishou_plaintext');
|
||
});
|
||
|
||
it('1688 分销单没有 OutChannel 标签时用 ExtField1 兜底识别渠道', () => {
|
||
const order = service.normalizeOrder(buildRow({ ExtField1: 'douyin', Tags: [] }));
|
||
console.log('ExtField1 兜底:', order.platform_code, order.distribute_channel);
|
||
assert.strictEqual(order.platform_code, 'DYXD');
|
||
assert.strictEqual(order.distribute_channel, 'douyin');
|
||
});
|
||
|
||
it('1688 单既无标签又无 ExtField1 仍按淘宝(非分销单)', () => {
|
||
const order = service.normalizeOrder(buildRow({ ExtField1: '', Tags: [], OrderTags: [] }));
|
||
assert.strictEqual(order.platform_code, 'TB');
|
||
assert.strictEqual(order.distribute_channel, null);
|
||
});
|
||
|
||
it('其它平台的 ExtField1(快手单里是哈希)不会被当成分销渠道', () => {
|
||
const order = service.normalizeOrder(buildRow({ PlatformType: 'KuaiShou', ExtField1: 'cb82842eb4b1a919', Tags: [] }));
|
||
assert.strictEqual(order.platform_code, 'KS');
|
||
assert.strictEqual(order.distribute_channel, null);
|
||
});
|
||
|
||
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 快手分销单 → 快手(KS),生产有快手模板', () => {
|
||
const order = service.normalizeOrder(buildRow({
|
||
ExtField1: 'kuaishou',
|
||
Tags: [{ Tag: 'OutChannel', TagType: 'Order', TagValue: 'kuaishou' }],
|
||
}));
|
||
console.log('快手分销:', order.platform_code, order.platform_name, order.distribute_channel);
|
||
assert.strictEqual(order.platform_code, 'KS');
|
||
assert.strictEqual(order.platform_name, '快手');
|
||
assert.strictEqual(order.distribute_channel, 'kuaishou');
|
||
assert.strictEqual(order.original_platform_code, '1688');
|
||
});
|
||
|
||
it('1688 淘宝分销单(密文 thyny)→ 淘宝取号', () => {
|
||
const order = service.normalizeOrder(buildRow({
|
||
PlatformOrderId: '5127404439433014429',
|
||
ExtField1: 'thyny',
|
||
Tags: [{ Tag: 'OutChannel', TagType: 'Order', TagValue: 'thyny' }],
|
||
OrderTags: [{ Tag: 'OutChannel', TagType: 'Order', TagValue: 'thyny' }],
|
||
}));
|
||
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, 'thyny');
|
||
assert.strictEqual(order.original_platform_code, '1688');
|
||
});
|
||
|
||
it('1688 未识别的分销渠道 → 其他(保留渠道与原始报文)', () => {
|
||
const order = service.normalizeOrder(buildRow({
|
||
Tags: [{ Tag: 'OutChannel', TagValue: 'chaoshibianli' }],
|
||
}));
|
||
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, 'chaoshibianli');
|
||
assert.strictEqual(order.original_platform_code, '1688');
|
||
// 原始报文完整保留(后续再做渠道映射时要用)
|
||
assert.deepStrictEqual(order.raw.Tags, [{ Tag: 'OutChannel', TagValue: 'chaoshibianli' }]);
|
||
assert.strictEqual(order.platform_type, 'Alibaba');
|
||
});
|
||
|
||
it('1688 未识别的**明文**渠道也按淘宝出(没有原单信息,只能用淘宝面单)', () => {
|
||
const order = service.normalizeOrder(buildRow({
|
||
Tags: [{ Tag: 'OutChannel', TagValue: 'thyny_plaintext' }],
|
||
}));
|
||
assert.strictEqual(order.platform_code, 'TB');
|
||
assert.strictEqual(order.distribute_channel, 'thyny_plaintext');
|
||
assert.strictEqual(order.raw.Tags[0].TagValue, 'thyny_plaintext');
|
||
});
|
||
|
||
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');
|
||
});
|
||
});
|