oms/backend/test/app/lib/dgjOrderPlatformRule.test.js
liufumingren 0e222789dd feat(order): 1688 单按分销渠道换算电商平台(抖音小店/淘宝/其他)
店管家侧没有 Alibaba(1688)面单模板,1688 单实际要用下游渠道的电子面单,
按平台 1688 找模板必然取号失败。拉单落库时按硬规则换算(dgj.normalizeOrder):

| 原始平台 | 判定(Tags / OrderTags) | 落库平台 |
|---|---|---|
| 1688(PlatformType=Alibaba) | Tag=OutChannel 且 TagValue=douyin | 抖音小店 DYXD |
| 1688 | 有 OutChannel 但渠道未映射 | 其他 OTHER(渠道留痕,等后续映射) |
| 1688 | 无 OutChannel(非分销单) | 淘宝 TB |
| 其它平台 | —— | 原平台不变 |

- 原始报文完整保留:orders.external_data 仍存店管家整包(含 Tags),platform_type 保留 Alibaba
- 状态表 extend_props 增加 original_platform_code='1688' 与 distribute_channel=<渠道原值>,便于追溯
- 历史数据由迁移 20261107020000-convert-1688-orders-to-real-waybill-platform 按同一规则换算
  (8 张状态表 + orders 镜像表,迁移不做反向)
- 新增单测覆盖:抖音分销→DYXD、非分销→TB、未知渠道→OTHER(并断言原始报文保留)、其它平台不受影响
- 文档 店管家取号-旧系统提取.md §4.2.1 补充规则表与留痕字段说明

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-07 05:40:37 +08:00

84 lines
3.4 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('其它平台不受该硬规则影响', () => {
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');
});
});