'use strict'; /** * 发货单明细模型(子表商品明细),对应 order_delivery_items 表 * * 字段口径对齐奇门 `request.orderLines.orderLine` 与 WMS 侧明细落库结构(见迁移注释): * - plan_qty 必须 > 0;item_id / item_code 至少一个 * - order_line_no 缺省按行序号;inventory_type OMS 落 ZP/CC(推送时映射 ZC/CC) * @param {Egg.Application} app egg application * @return {object} orderDeliveryItem model */ module.exports = app => { const { BIGINT, STRING, DECIMAL, JSON, DATE } = app.Sequelize; const OrderDeliveryItem = app.model.define('order_delivery_item', { id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' }, principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' }, order_delivery_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属发货单ID(order_deliveries.id)' }, // 历史数据来源:order_items.id(仅搬迁数据有值) legacy_order_item_id: { type: BIGINT.UNSIGNED, comment: '历史数据来源:order_items.id(非搬迁数据为 NULL)' }, order_line_no: { type: STRING(20), allowNull: false, defaultValue: '', comment: '行号(orderLineNo,缺省按行序号)' }, item_id: { type: BIGINT.UNSIGNED, comment: 'WMS 内部商品ID(itemId,取自 warehouse_products.wms_item_id)' }, item_code: { type: STRING(100), comment: '商品编码(itemCode)' }, item_name: { type: STRING(255), comment: '商品名称(itemName)' }, plan_qty: { type: DECIMAL(12, 3), allowNull: false, defaultValue: 0, comment: '计划数量(planQty,必须 > 0)' }, actual_price: { type: DECIMAL(12, 2), comment: '实际单价(actualPrice)' }, retail_price: { type: DECIMAL(12, 2), comment: '零售价(retailPrice)' }, ext_code: { type: STRING(100), comment: '外部编码(extCode)' }, inventory_type: { type: STRING(10), allowNull: false, defaultValue: 'ZP', comment: '库存类型:ZP=正品 CC=残次(对齐 WMS 行级 inventoryType,推送时映射 ZC/CC)', }, source_order_code: { type: STRING(50), comment: '来源订单编码(sourceOrderCode)' }, sub_source_order_code: { type: STRING(50), comment: '子来源订单编码(subSourceOrderCode)' }, stock_id: { type: BIGINT.UNSIGNED, comment: 'WMS 仓库库存ID(stockId,手工建单直传)' }, extend_props: { type: JSON, comment: '扩展属性(extendProps)' }, created_at: { type: DATE, comment: '创建时间' }, updated_at: { type: DATE, comment: '更新时间' }, }, { tableName: 'order_delivery_items', comment: '发货单明细(子表商品明细)', }); OrderDeliveryItem.associate = () => { app.model.OrderDeliveryItem.belongsTo(app.model.OrderDelivery, { foreignKey: 'order_delivery_id', as: 'order' }); app.model.OrderDeliveryItem.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' }); }; return OrderDeliveryItem; };