渠道标签成对出现:密文 `douyin`/`kuaishou`(订单带原单号,能用抖店/快手电子面单); 明文 `*_plaintext`(店管家侧没有原单信息,`Order.ExtraJson.extField7` 为空, 抖店/快手面单会被平台拒绝:ErrCode=15002「非抖店订单,无法使用抖音电子面单取号打印」)。 实测佐证: - 店管家 UI 对明文单的打印弹窗默认模板是「【菜鸟】国内邮政小包一联3」(13873834), 正是我们库里 TB 平台下的模板,`LoadWaybillAccountDetailInfo` 也用 expressCode=POSTB - 1688 单用菜鸟(TB)面单在生产成功过 11+ 单;TB + custom_code=YUNDA 唯一命中 12362952,不会撞多模板 改动: - 新增 isPlaintextDistributeChannel(`*_plaintext` 结尾) - normalizeOrder 的 1688 换算:明文 → TB;密文走 DISTRIBUTE_CHANNEL_PLATFORM (douyin→DYXD、kuaishou→KS);未映射的非明文渠道仍 → OTHER;无渠道 → TB - 渠道原值仍留痕在 extend_props.distribute_channel(如 douyin_plaintext) - 单测:douyin_plaintext/kuaishou_plaintext/thyny_plaintext → TB,thyny → OTHER(12 例) - 文档 §4.2 换算表与 §4.4.1 同步说明「明文单为什么按淘宝出」 存量:生产仅 2 张明文单,待审核单重新拉单即变淘宝(另一张已作废)。 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
155 lines
7.1 KiB
JavaScript
155 lines
7.1 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 未识别的分销渠道 → 其他(保留渠道与原始报文)', () => {
|
||
const order = service.normalizeOrder(buildRow({
|
||
Tags: [{ Tag: 'OutChannel', TagValue: 'thyny' }],
|
||
}));
|
||
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');
|
||
assert.strictEqual(order.original_platform_code, '1688');
|
||
// 原始报文完整保留(后续再做渠道映射时要用)
|
||
assert.deepStrictEqual(order.raw.Tags, [{ Tag: 'OutChannel', TagValue: 'thyny' }]);
|
||
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');
|
||
});
|
||
});
|