fix(dgj): 1688 抖音分销单的渠道值带明文后缀被误判为「其他」
店管家对同一分销渠道会给成对的标签值(明文/密文两套写法),实测同一条抖音 分销单出现 `douyin` 与 `douyin_plaintext` 两种;平台换算用的是全等比较 `distributeChannel === 'douyin'`,于是 `douyin_plaintext` 落到「未知渠道」分支, 平台被换算成 OTHER,取号报「平台OTHER(其他)暂无面单模板」。 生产实测(Alibaba 70 单):douyin 56 单正确;douyin_plaintext 2 单被误判 (dgj-10000289308857、dgj-10000288822218,取号记录里都是无模板失败)。 - 新增 normalizeDistributeChannel:按 `_` 取主名(douyin_plaintext → douyin), chaoshibianli_plaintext / thyny_plaintext 同理;标签原值仍原样留痕 - 渠道→平台改用显式映射表 DISTRIBUTE_CHANNEL_PLATFORM(douyin → DYXD) - ExtField1 兜底:仅 1688 分销单、且没有 OutChannel 标签时用它识别渠道 (其它平台的 ExtField1 是哈希,实测快手单为 cb82842eb4b1a919,已排除) - 单测补 4 例:明文后缀、ExtField1 兜底、无渠道仍按淘宝、其它平台哈希不误判 存量订单无需 SQL:待审核单重新拉一次单即按新口径更新平台字段。 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
20147fb391
commit
8dbb0b59a5
@ -649,6 +649,26 @@ function parseOrderTime(value) {
|
||||
return Number.isNaN(date.getTime()) ? null : date;
|
||||
}
|
||||
|
||||
/** 分销渠道 → 系统平台编码:1688 分销单取号必须用下游渠道的面单模板 */
|
||||
const DISTRIBUTE_CHANNEL_PLATFORM = {
|
||||
douyin: 'DYXD',
|
||||
};
|
||||
|
||||
/**
|
||||
* 归一化分销渠道标识
|
||||
*
|
||||
* 店管家对同一个渠道会给**成对的标签值**(明文 / 密文两套写法),
|
||||
* 实测同一条抖音分销单出现 `douyin` 与 `douyin_plaintext` 两种,
|
||||
* 只按全等比较会把 `douyin_plaintext` 当成未知渠道判成「其他」。这里取 `_` 前的主名。
|
||||
* @param {*} value 渠道标识
|
||||
* @return {string} 归一化后的渠道标识(小写),空值返回空串
|
||||
*/
|
||||
function normalizeDistributeChannel(value) {
|
||||
const text = String(value == null ? '' : value).trim().toLowerCase();
|
||||
if (!text) return '';
|
||||
return text.split('_')[0].trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单明细的平台规格ID:不同平台字段口径不一致
|
||||
* (抖店/淘宝用 SkuId 存规格ID,视频号则用 SkuCode 存规格ID、SkuId 存规格名称)
|
||||
@ -2410,16 +2430,15 @@ class DgjService extends PrintPlatformService {
|
||||
const platform = resolveOrderPlatform(data.PlatformType);
|
||||
const distributeChannel = this.resolveOrderDistributeChannel(data);
|
||||
// 硬规则(分销代发业务口径):1688 单不按 1688 出号,统一换算成实际取号渠道
|
||||
// - 抖音分销单(OutChannel=douyin)→ 抖音小店(DYXD)
|
||||
// - 其它分销渠道(OutChannel=未知值)→ 其他(OTHER),原始报文与渠道留痕,等待后续映射
|
||||
// - 抖音分销单(OutChannel=douyin / douyin_plaintext)→ 抖音小店(DYXD)
|
||||
// - 其它分销渠道(OutChannel=未知值,如 kuaishou/thyny)→ 其他(OTHER),原始报文与渠道留痕,等待后续映射
|
||||
// - 非分销单(无 OutChannel 标签)→ 淘宝(TB)
|
||||
// 否则按 1688 永远匹配不到面单模板,取号必失败
|
||||
let platformCode = platform.code;
|
||||
let platformName = platform.name;
|
||||
if (platform.code === '1688') {
|
||||
let targetCode = 'TB';
|
||||
if (distributeChannel === 'douyin') targetCode = 'DYXD';
|
||||
else if (distributeChannel) targetCode = 'OTHER';
|
||||
const mapped = DISTRIBUTE_CHANNEL_PLATFORM[normalizeDistributeChannel(distributeChannel)];
|
||||
const targetCode = mapped || (distributeChannel ? 'OTHER' : 'TB');
|
||||
const target = resolvePlatform(targetCode);
|
||||
platformCode = target.code;
|
||||
platformName = target.name;
|
||||
@ -2466,10 +2485,12 @@ class DgjService extends PrintPlatformService {
|
||||
* 取订单的分销渠道(Tags/OrderTags 里 `Tag=OutChannel` 的 `TagValue`)
|
||||
*
|
||||
* 1688 分销/代发采购单会带这个标签,值是对下游渠道的标识(实测 `douyin`、
|
||||
* `chaoshibianli_plaintext`、`thyny_plaintext` 等)。分销单必须用下游渠道的电子面单,
|
||||
* 所以「平台」要按下游渠道算,不能按 1688 算,否则取号永远匹配不到模板。
|
||||
* `douyin_plaintext`、`chaoshibianli_plaintext`、`thyny_plaintext`、`kuaishou` 等)。
|
||||
* 分销单必须用下游渠道的电子面单,所以「平台」要按下游渠道算,不能按 1688 算,
|
||||
* 否则取号永远匹配不到模板。标签里的明文/密文后缀由 `normalizeDistributeChannel` 归一化。
|
||||
* 少数分销单没有 OutChannel 标签,但 `ExtField1` 记了同一个渠道名(实测 `douyin`),一并兜底。
|
||||
* @param {Object} data 店管家订单原始结构
|
||||
* @return {string} 分销渠道标识(小写),无则空串
|
||||
* @return {string} 分销渠道标识(原样保留标签值,无则空串)
|
||||
*/
|
||||
resolveOrderDistributeChannel(data) {
|
||||
const tags = [
|
||||
@ -2481,6 +2502,12 @@ class DgjService extends PrintPlatformService {
|
||||
const value = String(tag.TagValue || '').trim().toLowerCase();
|
||||
if (value) return value;
|
||||
}
|
||||
// 只知道渠道名、没有 OutChannel 标签的 1688 分销单:ExtField1 记的是同一个渠道标识
|
||||
// (其它平台的 ExtField1 是别的含义,实测快手单里是哈希,不能当渠道)
|
||||
if (resolveOrderPlatform(data && data.PlatformType).code === '1688') {
|
||||
const fallback = String((data && data.ExtField1) || '').trim().toLowerCase();
|
||||
if (fallback && /^[a-z][a-z0-9-]{1,31}$/.test(fallback)) return fallback;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
@ -47,6 +47,39 @@ describe('printPlatform/dgj normalizeOrder 平台换算硬规则', () => {
|
||||
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, 'DYXD');
|
||||
assert.strictEqual(order.platform_name, '抖音小店');
|
||||
// 渠道原值留痕(归一化只用于平台换算)
|
||||
assert.strictEqual(order.distribute_channel, 'douyin_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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user