oms/backend/app/model/order.js
liufumingren 69b26bf7cc feat(platform): 统一系统预设平台编码,外部平台标识按预设转换
- 新增 app/lib/platformCode.js:17 个预设平台(1688/DW/DYCS/DYGX/DYXD/JD/KS/MAOCHAO/
  MTYYJK/OFFLINE/OTHER/PDD/SPH/TB/TGC/TM/XHS)+ 别名表(中英文、大小写)+ 未知落 OTHER
- 店管家硬编码 PlatformType → 预设映射(Pinduoduo→PDD、TouTiao→DYXD、WxVideo→SPH、
  Alibaba→1688、Taobao→TB、KuaiShou→KS、Tmall→TM、JingDong→JD…)
- 拉单落库统一:orders.platform_type、order_status_*.source_platform_code/name
  写预设编码与本系统中文名(推 WMS 的 sourcePlatformCode/Name 同源)
- 店铺商品 platform_type 同样落预设编码
- 新增 scripts/migrate-platform-codes.js(npm run platforms:migrate):
  按同一口径迁移历史数据,默认 dry-run;已执行迁移 14 类(订单 27 / 店铺商品 44 / 状态表 15+13)
- 前端新增 constants/platform.ts(code→中文名):店铺商品「平台类型」列显示中文名,
  订单详情新增「来源平台」行
- 新增 platformCode 单测(5 项,含未知平台落 OTHER)

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

52 lines
3.2 KiB
JavaScript
Raw Permalink 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';
/**
* 订单模型,对应 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: '平台类型:系统预设平台编码(PDD/DYXD/SPH…)' },
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;
};