- 发货单主表/明细表(order_deliveries / order_delivery_items)控制器与模型 - 表头金额与明细派生字段重算(utils/recalcOrderDelivery.js) - 状态流转:审核/驳回/取消/恢复/作废、批量审核、批量切换仓库 - 审核入队 + 定时推送:service/orderDeliveryPush.js(乐观锁 CAS 防重、失败重试上限 3 次、业务失败退回待审核)+ schedule/orderDeliveryPush.js - 收件人 AI 智能识别(service/ai.js,DeepSeek) - 相关迁移:建表、站内字段、明细表、订单类型默认值、快递字典、菜单种子、历史数据搬迁
54 lines
3.1 KiB
JavaScript
54 lines
3.1 KiB
JavaScript
'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)',
|
||
},
|
||
owner_code: { type: STRING(50), comment: '货主编码(ownerCode)' },
|
||
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;
|
||
};
|