问题:外部打单平台订单的来源订单号 / 去重键取的是 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>
52 lines
3.2 KiB
JavaScript
52 lines
3.2 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 订单模型,对应 orders 表
|
||
* 含本系统主状态 status、外部 WMS 状态 wms_status、上交状态 submit_status
|
||
* @param {Egg.Application} app egg application
|
||
* @return {object} order model
|
||
*/
|
||
module.exports = app => {
|
||
const { BIGINT, STRING, TINYINT, DECIMAL, JSON, DATE } = app.Sequelize;
|
||
|
||
const Order = app.model.define('order', {
|
||
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
|
||
order_no: { type: STRING(50), allowNull: false, comment: '业务订单号' },
|
||
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' },
|
||
shop_id: { type: BIGINT.UNSIGNED, comment: '所属店铺ID,为空表示未关联店铺' },
|
||
external_print_account_id: { type: BIGINT.UNSIGNED, comment: '来源外部打单账号ID' },
|
||
external_order_id: { type: STRING(64), comment: '平台订单唯一标识(店管家为系统编号 LogicOrderId,平台单号见 external_data)' },
|
||
platform_type: { type: STRING(32), comment: '平台类型:TouTiao/Taobao/Pinduoduo 等' },
|
||
platform_status: { type: STRING(32), comment: '平台侧订单状态' },
|
||
external_shop_id: { type: STRING(64), comment: '平台侧店铺ID(店管家 ShopId)' },
|
||
external_shop_name: { type: STRING(128), comment: '平台侧店铺名称' },
|
||
external_created_at: { type: DATE, comment: '平台侧订单创建时间' },
|
||
external_updated_at: { type: DATE, comment: '平台侧订单更新时间' },
|
||
synced_at: { type: DATE, comment: '最近一次从平台同步的时间' },
|
||
external_data: { type: JSON, comment: '平台返回的订单原始结构' },
|
||
order_type: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '订单类型' },
|
||
status: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '主状态:1待处理 2处理中 3已完成 4已取消' },
|
||
wms_status: { type: STRING(50), comment: '外部WMS状态' },
|
||
wms_order_no: { type: STRING(50), comment: '外部WMS单号' },
|
||
wms_synced_at: { type: DATE, comment: '最近一次WMS同步时间' },
|
||
submit_status: { type: TINYINT, allowNull: false, defaultValue: 0, comment: '上交状态:0未上交 1上交中 2已上交 3上交失败' },
|
||
submit_order_no: { type: STRING(50), comment: '上交后返回的单号' },
|
||
submit_at: { type: DATE, comment: '上交时间' },
|
||
submit_msg: { type: STRING(255), comment: '上交结果/失败原因' },
|
||
total_amount: { type: DECIMAL(12, 2), allowNull: false, defaultValue: 0, comment: '订单金额' },
|
||
pay_amount: { type: DECIMAL(12, 2), comment: '实付金额' },
|
||
receiver: { type: JSON, comment: '收货人信息 JSON:{ name, phone, address }' },
|
||
remark: { type: STRING(255), comment: '备注' },
|
||
created_at: { type: DATE, comment: '创建时间' },
|
||
updated_at: { type: DATE, comment: '更新时间' },
|
||
});
|
||
|
||
Order.associate = () => {
|
||
app.model.Order.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
|
||
app.model.Order.belongsTo(app.model.Shop, { foreignKey: 'shop_id', as: 'shop' });
|
||
app.model.Order.hasMany(app.model.OrderItem, { foreignKey: 'order_id', as: 'items' });
|
||
};
|
||
|
||
return Order;
|
||
};
|