oms/backend/app/lib/platformCode.js
liufumingren 72c886bca6 平台字典新增 Shopify(SHOPIFY)
- platformCode.js:预设编码加 SHOPIFY(名称 Shopify),别名 shopify / 独立站 → SHOPIFY
- 前端 constants/platform.ts 同步(平台下拉、订单列表名称展示同源)
- dxm 订单报文的 platform=shopify 不再落到 OTHER,重拉后 platform_type / source_platform_code = SHOPIFY
- 测试:预设表 17→18,补 shopify 解析用例;dxm 单测平台编码断言同步
- 文档 5.0 补平台编码口径
- 本地已验证:重拉 60 单后 59 张待审核单 source_platform_code=SHOPIFY(name=Shopify),orders 60 行 platform_type=SHOPIFY

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

155 lines
4.1 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';
/**
* 系统预设平台编码。
*
* 外部打单平台(店管家等)返回的是各自的平台标识(Pinduoduo / TouTiao / WxVideo…),
* 订单落库、推送 WMS(奇门 sourcePlatformCode/sourcePlatformName)需要统一口径,
* 因此全系统只认这里的一套预设编码,外部标识通过别名表映射过来。
*/
const PLATFORM_PRESETS = [
{ code: '1688', name: '阿里巴巴' },
{ code: 'DW', name: '得物' },
{ code: 'DYCS', name: '抖音超市' },
{ code: 'DYGX', name: '抖音供销' },
{ code: 'DYXD', name: '抖音小店' },
{ code: 'JD', name: '京东' },
{ code: 'KS', name: '快手' },
{ code: 'MAOCHAO', name: '天猫超市' },
{ code: 'MTYYJK', name: '美团医药健康' },
{ code: 'OFFLINE', name: '线下' },
{ code: 'OTHER', name: '其他' },
{ code: 'PDD', name: '拼多多' },
{ code: 'SHOPIFY', name: 'Shopify' },
{ code: 'SPH', name: '视频号' },
{ code: 'TB', name: '淘宝' },
{ code: 'TGC', name: '淘工厂' },
{ code: 'TM', name: '天猫' },
{ code: 'XHS', name: '小红书' },
];
/** 预设编码 -> 名称 */
const PLATFORM_NAME_BY_CODE = new Map(PLATFORM_PRESETS.map(item => [ item.code, item.name ]));
/** 未知平台统一落到「其他」 */
const PLATFORM_UNKNOWN_CODE = 'OTHER';
/**
* 外部标识 / 中文名 -> 预设编码(全部按小写比对)。
* 只放通用别名;各打单平台自己的枚举(如店管家 PlatformType)在对应 service 里硬编码。
*/
const PLATFORM_ALIASES = {
// 1688 / 阿里巴巴
1688: '1688',
ali: '1688',
alibaba: '1688',
阿里巴巴: '1688',
// 得物
dw: 'DW',
dewu: 'DW',
得物: 'DW',
// 抖音系
dycs: 'DYCS',
抖音超市: 'DYCS',
dygx: 'DYGX',
抖音供销: 'DYGX',
dyxd: 'DYXD',
douyin: 'DYXD',
doudian: 'DYXD',
toutiao: 'DYXD',
抖店: 'DYXD',
抖音: 'DYXD',
抖音小店: 'DYXD',
// 京东
jd: 'JD',
jingdong: 'JD',
京东: 'JD',
// 快手
ks: 'KS',
kuaishou: 'KS',
快手: 'KS',
// 天猫超市
maochao: 'MAOCHAO',
tmcs: 'MAOCHAO',
天猫超市: 'MAOCHAO',
// 美团医药健康
mtyyjk: 'MTYYJK',
meituan: 'MTYYJK',
美团: 'MTYYJK',
美团医药健康: 'MTYYJK',
// 线下 / 其他
offline: 'OFFLINE',
线下: 'OFFLINE',
other: 'OTHER',
其他: 'OTHER',
// 拼多多
pdd: 'PDD',
pinduoduo: 'PDD',
拼多多: 'PDD',
// Shopify(店小秘等跨境平台的 platform=shopify)
shopify: 'SHOPIFY',
独立站: 'SHOPIFY',
// 视频号
sph: 'SPH',
wxvideo: 'SPH',
wechatvideo: 'SPH',
视频号: 'SPH',
// 淘宝
tb: 'TB',
taobao: 'TB',
淘宝: 'TB',
// 淘工厂
tgc: 'TGC',
taobaofactory: 'TGC',
淘工厂: 'TGC',
// 天猫
tm: 'TM',
tmall: 'TM',
天猫: 'TM',
// 小红书
xhs: 'XHS',
xiaohongshu: 'XHS',
redbook: 'XHS',
小红书: 'XHS',
};
/**
* 解析外部平台标识为预设编码:先查别名表,本身就是预设编码时直接返回,未知落到 OTHER
* @param {*} raw 外部平台标识(大小写、中英文均可)
* @return {string} 预设编码
*/
function resolvePlatformCode(raw) {
const key = String(raw == null ? '' : raw).trim().toLowerCase();
if (!key) return PLATFORM_UNKNOWN_CODE;
if (PLATFORM_NAME_BY_CODE.has(key.toUpperCase())) return key.toUpperCase();
return PLATFORM_ALIASES[key] || PLATFORM_UNKNOWN_CODE;
}
/**
* 预设编码对应的中文名,未知编码原样返回(便于排查)
* @param {*} code 平台编码
* @return {string} 平台名称
*/
function platformNameOf(code) {
const key = String(code == null ? '' : code).trim().toUpperCase();
return PLATFORM_NAME_BY_CODE.get(key) || String(code == null ? '' : code);
}
/**
* 解析为「编码 + 名称」:订单表 source_platform_code / source_platform_name 直接落这两个值
* @param {*} raw 外部平台标识
* @return {{code: string, name: string}} 预设平台
*/
function resolvePlatform(raw) {
const code = resolvePlatformCode(raw);
return { code, name: platformNameOf(code) };
}
module.exports = {
PLATFORM_PRESETS,
PLATFORM_UNKNOWN_CODE,
resolvePlatform,
resolvePlatformCode,
platformNameOf,
};