- 新增 order_sn_codes 关联表(order_id = order_index.id,一行一个 SN,唯一键兜底去重) - deliveryorder.confirm 解析 orderLines[].snList / 包裹内商品 snList,幂等写入(仅委外中/已配送的订单) - 订单列表新增 sn_codes 多值筛选(逗号/换行分隔,最多 200 个,精确匹配反查) - 订单详情返回 sn_codes;订单导出支持「序列号」筛选 - 前端订单页新增「序列号」批量筛选与详情序列号明细 - 补充 WMS 回传报文说明与 lib 单测 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
46 lines
2.4 KiB
JavaScript
46 lines
2.4 KiB
JavaScript
'use strict';
|
||
|
||
const { ORDER_SN_TABLE } = require('../lib/orderStatus');
|
||
|
||
/**
|
||
* 订单序列号(SN)关联表模型(order_sn_codes)
|
||
*
|
||
* WMS 回传发货确认(deliveryorder.confirm)时明细行可能带 `snList`,由
|
||
* app/lib/orderSnCodes.js 解析后落到本表:一行一个 SN,`order_id` 指向 order_index.id
|
||
* (订单在状态表之间流转时 ID 不变,故转表无需搬 SN)。订单查询按 SN 反查订单时
|
||
* 走 `idx_osc_principal_sn`(principal_id + sn_code)。
|
||
* @param {Egg.Application} app egg application
|
||
* @return {object} orderSnCode model
|
||
*/
|
||
module.exports = app => {
|
||
const { BIGINT, STRING, DATE } = app.Sequelize;
|
||
|
||
const OrderSnCode = app.model.define('order_sn_code', {
|
||
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
|
||
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID(主体隔离)' },
|
||
order_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '订单ID(order_index.id,全局唯一)' },
|
||
order_no: { type: STRING(50), comment: '订单号(冗余,便于排查 / 导出)' },
|
||
order_line_no: { type: STRING(20), comment: '回传明细行号(orderLineNo)' },
|
||
item_id: { type: BIGINT.UNSIGNED, comment: '商品ID(itemId)' },
|
||
item_code: { type: STRING(100), comment: '商品编码(itemCode)' },
|
||
item_name: { type: STRING(255), comment: '商品名称(itemName)' },
|
||
package_code: { type: STRING(50), comment: '包裹号(packageCode)' },
|
||
express_code: { type: STRING(50), comment: '运单号(expressCode)' },
|
||
warehouse_id: { type: BIGINT.UNSIGNED, comment: '仓库ID(app_key 定位到的仓库)' },
|
||
sn_code: { type: STRING(255), allowNull: false, comment: '序列号(SN 原值,去空白;反查订单用)' },
|
||
source: { type: STRING(20), allowNull: false, defaultValue: 'wms', comment: '来源:wms=仓库回传(预留手工补录)' },
|
||
created_at: { type: DATE, comment: '创建时间' },
|
||
updated_at: { type: DATE, comment: '更新时间' },
|
||
}, {
|
||
tableName: ORDER_SN_TABLE,
|
||
comment: '订单序列号(SN)关联表(WMS 发货确认回传的 snList)',
|
||
});
|
||
|
||
OrderSnCode.associate = () => {
|
||
app.model.OrderSnCode.belongsTo(app.model.OrderIndex, { foreignKey: 'order_id', as: 'order' });
|
||
app.model.OrderSnCode.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
|
||
};
|
||
|
||
return OrderSnCode;
|
||
};
|