'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; };