oms/backend/database/migrations/20260915000400-order-deliveries-station-fields.js
liufumingren 11e7b26ced feat(backend): 发货单模块与 WMS 定时推送队列
- 发货单主表/明细表(order_deliveries / order_delivery_items)控制器与模型
- 表头金额与明细派生字段重算(utils/recalcOrderDelivery.js)
- 状态流转:审核/驳回/取消/恢复/作废、批量审核、批量切换仓库
- 审核入队 + 定时推送:service/orderDeliveryPush.js(乐观锁 CAS 防重、失败重试上限 3 次、业务失败退回待审核)+ schedule/orderDeliveryPush.js
- 收件人 AI 智能识别(service/ai.js,DeepSeek)
- 相关迁移:建表、站内字段、明细表、订单类型默认值、快递字典、菜单种子、历史数据搬迁
2026-09-13 02:23:47 +08:00

87 lines
3.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';
/**
* 发货单表补充「站内字段」(OMS 自用,不参与对外报文):
* - 统计:item_total 商品总数(明细 plan_qty 合计)、item_kind 商品种类数
* —— 对应 WMS 发货单 items_total / items_count,口径对齐出入库单
* - 状态流转:
* audit_by / audit_time 审核(待处理 1 → 已审核 2)
* void_at / void_by / void_reason 作废(已审核 2 → 已作废 5),与出入库单约定一致
* - 主体隔离:principal_id / shop_id / warehouse_id 已在建表时具备,此处仅补组合索引
* (列表默认按主体 + 状态过滤;warehouse_id/shop_id 的归属校验在控制器实现)
*/
module.exports = {
async up(queryInterface, Sequelize) {
const cols = await queryInterface.describeTable('order_deliveries');
if (!cols.item_total) {
await queryInterface.addColumn('order_deliveries', 'item_total', {
type: Sequelize.DECIMAL(12, 3),
allowNull: false,
defaultValue: 0,
comment: '商品总数(明细计划数量合计)',
});
}
if (!cols.item_kind) {
await queryInterface.addColumn('order_deliveries', 'item_kind', {
type: Sequelize.INTEGER.UNSIGNED,
allowNull: false,
defaultValue: 0,
comment: '商品种类数(不重复商品数)',
});
}
if (!cols.audit_by) {
await queryInterface.addColumn('order_deliveries', 'audit_by', {
type: Sequelize.BIGINT.UNSIGNED,
allowNull: true,
comment: '审核人ID(关联 users,状态流转:待处理→已审核时写入)',
});
}
if (!cols.audit_time) {
await queryInterface.addColumn('order_deliveries', 'audit_time', {
type: Sequelize.DATE,
allowNull: true,
comment: '审核时间',
});
}
if (!cols.void_at) {
await queryInterface.addColumn('order_deliveries', 'void_at', {
type: Sequelize.DATE,
allowNull: true,
comment: '作废时间(状态 5=已作废)',
});
}
if (!cols.void_by) {
await queryInterface.addColumn('order_deliveries', 'void_by', {
type: Sequelize.BIGINT.UNSIGNED,
allowNull: true,
comment: '作废人ID(关联 users)',
});
}
if (!cols.void_reason) {
await queryInterface.addColumn('order_deliveries', 'void_reason', {
type: Sequelize.STRING(255),
allowNull: true,
comment: '作废原因',
});
}
const indexes = await queryInterface.showIndex('order_deliveries').catch(() => []);
const hasIndex = name => Array.isArray(indexes) && indexes.some(idx => idx.name === name);
if (!hasIndex('idx_od_principal_status')) {
await queryInterface.addIndex('order_deliveries', {
fields: [ 'principal_id', 'status' ],
name: 'idx_od_principal_status',
});
}
},
async down(queryInterface) {
const cols = await queryInterface.describeTable('order_deliveries');
for (const c of [ 'void_reason', 'void_by', 'void_at', 'audit_time', 'audit_by', 'item_kind', 'item_total' ]) {
if (cols[c]) await queryInterface.removeColumn('order_deliveries', c);
}
await queryInterface.removeIndex('order_deliveries', 'idx_od_principal_status').catch(() => {});
},
};