WMS_MAIN/app/model/order_stockout_items.js
liufumingren 5ef99e3bed 1
2026-07-01 14:00:59 +08:00

146 lines
3.5 KiB
JavaScript
Raw 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';
/**
* 出库单明细表 Model。
*
* 对应数据库表 `wms_order_stockout_items`,存储奇门 stockout.create 接口中
* 每个 <orderLine> 节点的明细数据。
*
* 与主表 `wms_order_stockout` 通过 `order_id` 外键关联(CASCADE 删除)。
* 与库存表 `wms_stock_warehouse` 通过 `stock_id` 外键关联(RESTRICT 删除)。
* @param {import('egg').Application} app - Egg 应用实例
*/
module.exports = app => {
const { STRING, INTEGER, BIGINT, DATE, JSON: JSON_TYPE } = app.Sequelize;
const OrderStockoutItems = app.model.define('wms_order_stockout_items', {
id: {
type: BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
comment: '主键ID',
},
order_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '出库单ID,外键关联 wms_order_stockout.id',
},
out_biz_code: {
type: STRING(255),
allowNull: true,
comment: '外部业务编码(幂等键)',
},
order_line_no: {
type: STRING(50),
allowNull: false,
comment: '订单行号(对应奇门 orderLineNo)',
},
owner_code: {
type: STRING(50),
allowNull: true,
comment: '货主编码(对应奇门 ownerCode)',
},
item_code: {
type: STRING(50),
allowNull: true,
comment: '商品编码(对应奇门 itemCode)',
},
item_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: 'WMS商品ID(对应奇门 itemId)',
},
item_name: {
type: STRING(200),
allowNull: true,
comment: '商品名称',
},
plan_qty: {
type: INTEGER(12),
allowNull: true,
comment: '计划数量(对应奇门 planQty)',
},
actual_qty: {
type: INTEGER(12),
allowNull: false,
defaultValue: 0,
comment: '实发数量',
},
inventory_type: {
type: STRING(50),
allowNull: true,
comment: '库存类型(ZP正品/CC残次等)',
},
stock_id: {
type: BIGINT(20),
allowNull: true,
comment: '库存ID,外键关联 wms_stock_warehouse.id',
},
extend_props: {
type: JSON_TYPE,
allowNull: true,
comment: '扩展属性',
},
created_at: {
type: DATE,
allowNull: false,
comment: '创建时间',
},
updated_at: {
type: DATE,
allowNull: false,
comment: '更新时间',
},
}, {
tableName: 'wms_order_stockout_items',
comment: '出库明细表',
timestamps: false,
indexes: [
{
name: 'uk_order_line_no',
unique: true,
fields: [ 'order_id', 'order_line_no' ],
},
{
name: 'idx_order_id',
fields: [ 'order_id' ],
},
{
name: 'idx_stock_id',
fields: [ 'stock_id' ],
},
{
name: 'idx_item_code',
fields: [ 'item_code' ],
},
{
name: 'idx_out_biz_code',
fields: [ 'out_biz_code' ],
},
],
});
/**
* 关联关系定义。
* - 关联出库单主表
* - 关联商品 SKU(wms_stock_warehouse)
*/
OrderStockoutItems.associate = function() {
const { OrderStockoutItems, OrderStockout, StockWarehouse } = app.model;
// 关联出库单
OrderStockoutItems.belongsTo(OrderStockout, {
foreignKey: 'order_id',
as: 'order',
});
// 关联商品 SKU
OrderStockoutItems.belongsTo(StockWarehouse, {
foreignKey: 'stock_id',
as: 'stock',
});
};
return OrderStockoutItems;
};