oms/backend/database/migrations/20260915001400-add-express-codes.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

46 lines
2.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.express_codes / order_deliveries.express_codes(JSON 数组)
*
* 背景:WMS 出库确认(stockout.confirm)与发货确认(deliveryorder.confirm)的报文中
* `packages.package` 是**数组**(一单可拆多个包裹、每个包裹一个运单号,如 CK_4 一单两个运单号)。
* 但 OMS 侧 order_deliveries.express_code 是单值列(只落第一个运单号),outbound_orders 更是没有运单号列,
* 多运单只能翻 wms_push_result.confirm.packages[] 的 JSON,无法在列表/筛选/导出/对外接口里用。
* 故两表各加一个 express_codes(JSON 数组)留存全部运单号;单值字段(express_code)保留,
* 继续表示「首个运单号」,兼容既有口径与前端展示。
*
* 幂等:迁移可重复执行(先 describeTable 判断列是否存在)。
*/
module.exports = {
async up(queryInterface, Sequelize) {
const outboundColumns = await queryInterface.describeTable('outbound_orders');
if (!outboundColumns.express_codes) {
await queryInterface.addColumn('outbound_orders', 'express_codes', {
type: Sequelize.JSON,
allowNull: true,
comment: '运单号集合(WMS 出库确认 packages.package[].expressCode,多包裹时为数组)',
after: 'stock_deducted',
});
}
const deliveryColumns = await queryInterface.describeTable('order_deliveries');
if (!deliveryColumns.express_codes) {
await queryInterface.addColumn('order_deliveries', 'express_codes', {
type: Sequelize.JSON,
allowNull: true,
comment: '运单号集合(WMS 发货确认 packages.package[].expressCode,多包裹时为数组)',
after: 'express_code',
});
}
},
async down(queryInterface) {
const outboundColumns = await queryInterface.describeTable('outbound_orders');
if (outboundColumns.express_codes) await queryInterface.removeColumn('outbound_orders', 'express_codes');
const deliveryColumns = await queryInterface.describeTable('order_deliveries');
if (deliveryColumns.express_codes) await queryInterface.removeColumn('order_deliveries', 'express_codes');
},
};