oms/backend/app/model/orderIndex.js
liufumingren e6d3f1ba8d fix(external-print): 来源订单号改用店管家系统编号(LogicOrderId)
问题:外部打单平台订单的来源订单号 / 去重键取的是 PlatformOrderId(平台单号),
但平台单号并不唯一(同一平台单可拆成多条逻辑单),唯一标识是店管家的「系统编号」LogicOrderId。
例如 订单编号 261023-105376715090914 的系统编号是 695351624597601813。

- normalizeOrder:external_order_id / order_no 改用 LogicOrderId(缺失时回落平台单号),
  平台单号以 platform_order_no 单独带出
- 订单表 extend_props 增加 platform_order_no,便于按店管家「订单编号」对账
- 订单详情抽屉新增「平台订单号」一行(有值才显示)
- 新增 scripts/migrate-logic-order-id.js(npm run orders:migrate-logic-id):
  把历史订单的来源订单号从平台单号迁移到系统编号,同时改写 orders / order_index /
  各状态表 / order_status_items / 配送单,并补写 extend_props.platform_order_no;默认 dry-run
- 修正 orders.external_order_id、order_index.parent_order_no、orderFields 的字段注释

已执行迁移 20 条(备份见会话 files/backup-before-logic-order-id-migration.json),
迁移后重新拉单 created=0 / updated=14,确认不会产生重复订单。

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

33 lines
1.7 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 { ORDER_INDEX_TABLE } = require('../lib/orderStatus');
/**
* 订单索引表(order_index)
*
* 订单的**全局唯一 ID 以本表为准**:各状态表与历史表的主键都取自本表 id,
* 另通过 current_table 记录订单当前所在状态表、current_status 记录当前状态,
* 便于「不依赖具体状态表」地定位任一订单(批量流转时按索引表分组处理)。
* @param {Egg.Application} app egg application
* @return {object} orderIndex model
*/
module.exports = app => {
const { BIGINT, STRING, DATE } = app.Sequelize;
const OrderIndex = app.model.define(ORDER_INDEX_TABLE, {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键(订单全局唯一 ID)' },
order_no: { type: STRING(50), allowNull: false, comment: '订单号' },
parent_order_no: { type: STRING(50), comment: '来源订单号(外部平台唯一单号;店管家为系统编号 LogicOrderId)' },
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID(主体隔离)' },
current_table: { type: STRING(16), allowNull: false, defaultValue: 'pending', comment: '当前所在表:pending/exception/outsourcing/delivery/history' },
current_status: { type: STRING(16), allowNull: false, defaultValue: 'pending', comment: '当前状态:pending 待审核 / exception 异常 / outsourcing 委外中 / delivery 配送 / history 历史' },
created_at: { type: DATE, comment: '创建时间(用于超 3 个月自动归档判断)' },
updated_at: { type: DATE, comment: '更新时间' },
}, {
tableName: ORDER_INDEX_TABLE,
comment: '订单索引表(订单 ID 以此为准)',
});
return OrderIndex;
};