oms/backend/app/model/outboundOrder.js
liufumingren 39c19a4de7 feat(backend): 出入库记录与库存锁定链路、出库单快递/收件人与推送队列
- 出入库记录(库存流水):新增 stock_records 表/模型/只读接口(列表 + 业务动作选项)与「出入库记录」菜单;
  库存变动统一收敛到 app/utils/stockRecord.js#applyStockChange,与流水写入同事务(含变动前后总/锁定/可用数量)
- 发货单:审核(1→2) 按明细锁定库存、发货确认(3→4) 扣减、推送失败退回/驳回/取消/作废释放(新增 stock_locked 列);
  恢复(9→1) 时曾推送过的单据换号(WMS 取消后原单号仍被占用,沿用旧号重推会被判「订单已存在」)
- 出库单:新增快递(express_code/express_name)、收件人(receiver_*) 与多运单号(express_codes) 字段;
  推送报文补齐 logisticsCode/receiverInfo;新增出库单推送服务与定时任务
- 快递:多运单号回填、仓库快递映射(warehouse_express_mappings) 与快递字典补录等迁移
- 契约:补充出入库记录、出库单快递/收件人等定义(swagger.json 为本地生成、不入库)
2026-09-14 00:59:23 +08:00

73 lines
5.2 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, JSON } = 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: '备注' },
// ---------- 快递公司(推送 stockout.create 的 deliveryOrder.logisticsCode) ----------
express_code: { type: STRING(50), comment: '快递公司编码:推送为 deliveryOrder.logisticsCode,出库确认回传后按 WMS 实际承运覆盖(可能转快递)' },
express_name: { type: STRING(200), comment: '快递公司名称:推送时按字典解析,出库确认回传后按 WMS 实际承运覆盖' },
// ---------- 收件人(奇门 receiverInfo 扁平落库,列名对齐 WMS wms_order_stockout) ----------
receiver_name: { type: STRING(50), comment: '收件人姓名(receiverInfo.name)' },
receiver_company: { type: STRING(200), comment: '收件人公司名称(receiverInfo.company)' },
receiver_tel: { type: STRING(50), comment: '收件人固定电话(receiverInfo.tel)' },
receiver_mobile: { type: STRING(50), comment: '收件人移动电话(receiverInfo.mobile)' },
receiver_email: { type: STRING(100), comment: '收件人邮箱(receiverInfo.email)' },
receiver_country_code: { type: STRING(50), comment: '收件人国家二字码(receiverInfo.countryCode)' },
receiver_province: { type: STRING(50), comment: '收件人省份(receiverInfo.province)' },
receiver_city: { type: STRING(50), comment: '收件人城市(receiverInfo.city)' },
receiver_area: { type: STRING(50), comment: '收件人区县(receiverInfo.area)' },
receiver_town: { type: STRING(50), comment: '收件人街道/镇(receiverInfo.town)' },
receiver_detail_address: { type: STRING(200), comment: '收件人详细地址(receiverInfo.detailAddress)' },
receiver_zip_code: { type: STRING(50), comment: '收件人邮编(receiverInfo.zipCode)' },
receiver_id: { type: STRING(50), comment: '收件人证件号(receiverInfo.id)' },
stock_deducted: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 0, comment: '发货通知(notify.delivery)是否已扣减库存:1是 0否(幂等)' },
stock_locked: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 0, comment: '推送锁定库存标记:1=已锁定(重试不重复锁定,确认扣减/释放后置 0),0=未锁定' },
waybill_codes: { type: JSON, allowNull: true, comment: '运单号集合(WMS 出库确认 packages.package[].expressCode,多包裹时为数组;列名对齐 wms_order_stockout)' },
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;
};