oms/backend/app/model/outboundOrder.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

51 lines
3.0 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';
/**
* 出库单模型,对应 outbound_orders 表(单据头)
* @param {Egg.Application} app egg application
* @return {object} outboundOrder model
*/
module.exports = app => {
const { BIGINT, STRING, TINYINT, DECIMAL, INTEGER, DATE } = app.Sequelize;
const OutboundOrder = app.model.define('outbound_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' },
outbound_type: {
type: STRING(20),
allowNull: false,
defaultValue: 'PTCK',
comment: 'WMS 出库单类型:PTCK 普通出库单 / DBCK 调拨出库 / B2BCK B2B出库 / QTCK 其他出库 / CGTH 采购退货出库单',
},
status: { type: TINYINT, allowNull: false, defaultValue: 1, comment: '状态:1待出库 2已出库 3已取消' },
customer: { type: STRING(255), comment: '客户/收货方' },
operator: { type: STRING(50), comment: '操作人' },
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: '备注' },
stock_deducted: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 0, comment: '发货通知(notify.delivery)是否已扣减库存:1是 0否(幂等)' },
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: '更新时间' },
});
OutboundOrder.associate = () => {
app.model.OutboundOrder.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
app.model.OutboundOrder.belongsTo(app.model.Shop, { foreignKey: 'shop_id', as: 'shop' });
app.model.OutboundOrder.belongsTo(app.model.Warehouse, { foreignKey: 'warehouse_id', as: 'warehouse' });
app.model.OutboundOrder.belongsTo(app.model.User, { foreignKey: 'created_by', as: 'creator' });
app.model.OutboundOrder.belongsTo(app.model.User, { foreignKey: 'void_by', as: 'voider' });
};
return OutboundOrder;
};