oms/backend/database/migrations/20260915001500-order-deliveries-shop-sync.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

50 lines
2.3 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';
/**
* 发货单(订单)回传平台店铺的同步状态与重试次数:
* order_deliveries.shop_sync_status 0未同步 1同步中 2同步成功 3同步失败
* order_deliveries.shop_sync_retry_count 回传失败后的累计重试次数
*
* 背景:发货单完成后需要把发货结果(运单号/发货状态)回传平台店铺(shops 表对应的淘宝/抖音等)。
* 此前 OMS 侧只有 `wms_push_result`(JSON,推送 WMS 的结果)与 `pushed_at`(最近一次 WMS 推送时间),
* 没有任何「回传平台店铺」的状态列可查(链路尚未实现),故先落字段与状态机基线,
* 实际回传(OMS → 平台)后续接入时直接读写这两列即可。
*
* 口径来源:app/lib/shopSyncStatus.js(枚举单一来源,前端/服务端共用)
* 范围:**只** order_deliveries —— 入库单(inbound_orders)的库存由 OMS 侧自行管理、
* 出库单(outbound_orders)也不涉及平台店铺回传,均不加这两个字段。
*
* 幂等:迁移可重复执行(先 describeTable 判断列是否存在)。
*/
module.exports = {
async up(queryInterface, Sequelize) {
const columns = await queryInterface.describeTable('order_deliveries');
if (!columns.shop_sync_status) {
await queryInterface.addColumn('order_deliveries', 'shop_sync_status', {
type: Sequelize.TINYINT.UNSIGNED,
allowNull: false,
defaultValue: 0,
comment: '回传平台店铺状态:0未同步 1同步中 2同步成功 3同步失败',
after: 'stock_locked',
});
}
if (!columns.shop_sync_retry_count) {
await queryInterface.addColumn('order_deliveries', 'shop_sync_retry_count', {
type: Sequelize.INTEGER.UNSIGNED,
allowNull: false,
defaultValue: 0,
comment: '回传平台店铺的重试次数(每次失败后 +1,重试成功不清零以便追溯)',
after: 'shop_sync_status',
});
}
},
async down(queryInterface) {
const columns = await queryInterface.describeTable('order_deliveries');
if (columns.shop_sync_retry_count) await queryInterface.removeColumn('order_deliveries', 'shop_sync_retry_count');
if (columns.shop_sync_status) await queryInterface.removeColumn('order_deliveries', 'shop_sync_status');
},
};