oms/backend/database/migrations/20261103000300-backfill-platform-order-no.js
liufumingren 5376dff3de feat(order): 平台订单号落库 oaid_order_source_code 并在订单列表展示
- 拉单写入状态表时,把店管家「订单编号」(PlatformOrderId)落 oaid_order_source_code
  (来源订单号仍是平台「系统编号」),随单推 WMS 的 deliveryOrder.oaidOrderSourceCode
- 新增迁移 20261103000300:把历史行 extend_props.platform_order_no 回填到
  oaid_order_source_code(已执行:pending 17 条 / void 12 条)
- 订单列表新增「平台订单号」列(手工单显示 -),订单详情、导出列同步使用该字段
- 前端 OrderStatusItem 补充 oaid_order_source_code 类型

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

41 lines
1.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';
/**
* 外部打单平台订单:把平台「订单编号」(PlatformOrderId)回填到 oaid_order_source_code。
*
* 背景:来源订单号(order_index.parent_order_no)已改用店管家「系统编号」LogicOrderId,
* 平台自己的「订单编号」只存在 extend_props.platform_order_no 里;该值需要随单推给 WMS,
* 因此统一落到 oaid_order_source_code(推单时映射为 deliveryOrder.oaidOrderSourceCode)。
*
* 只回填 oaid_order_source_code 为空、且 extend_props 里带 platform_order_no 的行,
* 手工单(无 extend_props.platform_order_no)不受影响。
*/
const STATUS_TABLES = [
'order_status_pending',
'order_status_queued',
'order_status_exception',
'order_status_outsourcing',
'order_status_delivery',
'order_status_void',
'order_status_canceled',
'order_status_history',
];
module.exports = {
async up(queryInterface) {
for (const table of STATUS_TABLES) {
await queryInterface.sequelize.query(
`UPDATE \`${table}\`
SET oaid_order_source_code = JSON_UNQUOTE(JSON_EXTRACT(extend_props, '$.platform_order_no'))
WHERE oaid_order_source_code IS NULL
AND extend_props IS NOT NULL
AND JSON_EXTRACT(extend_props, '$.platform_order_no') IS NOT NULL`
);
}
},
async down() {
// 数据回填不做回滚(回滚会丢掉平台单号,且不影响表结构)
},
};