oms/backend/app/model/inboundOrder.js
liufumingren ec81f8b3cd feat(backend): 入库单/出库单全流程与 WMS 对接
- 入库单、出库单控制器与模型(状态流转、审核、驳回换号、作废、删除约束)
- 明细共用 stock_items:应/已数量、行级库存类型 ZP/CC、明细锁定
- lib/wms:单据类型常量(orderTypes)、奇门/openapi 客户端(qimenClient)、签名(sign)
- 库存联动:utils/stock.js、utils/completeInbound.js(入库完成加库存,幂等)
- 驳回换号:utils/rejectBillNo.js;旧 orders 模块同步调整
- 相关迁移:入库单 WMS 字段/审核/推送结果、明细计划与实际数量、单据类型落 WMS 编码、出库库存扣减标记等
2026-09-13 02:23:44 +08:00

65 lines
4.1 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';
/**
* 入库单模型,对应 inbound_orders 表(单据头)
* @param {Egg.Application} app egg application
* @return {object} inboundOrder model
*/
module.exports = app => {
const { BIGINT, STRING, TINYINT, DECIMAL, INTEGER, DATE } = app.Sequelize;
const InboundOrder = app.model.define('inbound_order', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
bill_no: { type: STRING(50), allowNull: false, comment: '入库单号' },
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' },
shop_id: { type: BIGINT.UNSIGNED, comment: '来源店铺/仓库ID' },
inbound_type: {
type: STRING(20),
allowNull: false,
defaultValue: 'CGRK',
comment: 'WMS 入库单类型:B2BRK B2B入库 / SCRK 生产入库 / LYRK 领用入库 / CCRK 残次品入库 / CGRK 采购入库 / DBRK 调拨入库 / QTRK 其他入库',
},
status: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1待入库 2已入库 3已取消' },
supplier: { type: STRING(255), comment: '供应商名称' },
supplier_code: { type: STRING(50), comment: '供应商编码' },
operator: { type: STRING(50), comment: '操作人名称' },
operator_code: { type: STRING(50), comment: '操作员编码' },
operate_time: { type: DATE, comment: '操作时间' },
purchase_order_code: { type: STRING(50), comment: '采购单号(orderType=CGRK 时使用)' },
expect_start_time: { type: DATE, comment: '预期到货开始时间' },
expect_end_time: { type: DATE, comment: '最迟预期到货时间' },
logistics_code: { type: STRING(50), comment: '物流公司编码(SF/YTO/ZTO 等)' },
logistics_name: { type: STRING(200), comment: '物流公司名称' },
express_code: { type: STRING(50), comment: '运单号' },
sender_info: { type: JSON, allowNull: true, comment: '发件人信息(WMS senderInfo)' },
receiver_info: { type: JSON, allowNull: true, comment: '收件人信息(WMS receiverInfo)' },
extend_props: { type: JSON, allowNull: true, comment: '扩展属性(WMS extendProps):{ key: value }' },
created_by: { type: BIGINT.UNSIGNED, comment: '创建人ID(关联 users)' },
warehouse_id: { type: BIGINT.UNSIGNED, comment: '仓库ID(关联 warehouses)' },
item_total: { type: DECIMAL(12, 3), allowNull: false, defaultValue: 0, comment: '商品总数(明细数量合计)' },
item_kind: { type: INTEGER.UNSIGNED, allowNull: false, defaultValue: 0, comment: '商品种类数(不重复商品数)' },
total_amount: { type: DECIMAL(12, 2), allowNull: false, defaultValue: 0, comment: '单据总金额' },
remark: { type: STRING(255), comment: '备注' },
audit_by: { type: BIGINT.UNSIGNED, allowNull: true, comment: '审核人ID(关联 users)' },
audit_time: { type: DATE, allowNull: true, comment: '审核时间' },
pushed_at: { type: DATE, allowNull: true, comment: 'WMS 推送时间' },
wms_push_result: { type: JSON, allowNull: true, comment: 'WMS 推送结果(外部单号/返回码/消息/原始报文)' },
void_at: { type: DATE, allowNull: true, comment: '作废时间(状态 5=已作废)' },
void_by: { type: BIGINT.UNSIGNED, allowNull: true, comment: '作废人ID(关联 users)' },
void_reason: { type: STRING(255), allowNull: true, comment: '作废原因' },
created_at: { type: DATE, comment: '创建时间' },
updated_at: { type: DATE, comment: '更新时间' },
});
InboundOrder.associate = () => {
app.model.InboundOrder.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
app.model.InboundOrder.belongsTo(app.model.Shop, { foreignKey: 'shop_id', as: 'shop' });
app.model.InboundOrder.belongsTo(app.model.Warehouse, { foreignKey: 'warehouse_id', as: 'warehouse' });
app.model.InboundOrder.belongsTo(app.model.User, { foreignKey: 'created_by', as: 'creator' });
app.model.InboundOrder.belongsTo(app.model.User, { foreignKey: 'audit_by', as: 'auditor' });
app.model.InboundOrder.belongsTo(app.model.User, { foreignKey: 'void_by', as: 'voider' });
};
return InboundOrder;
};