WMS_MAIN/database/migrations/20260813120000-create-wms-return-unpack.js
liufumingren 38b29be776 feat: 新增退回拆包模块(returnUnpack)与序列表原子取号
- 新增 wms_return_unpack 主表/明细/视频 与 wms_return_query_log 表(model + 迁移)
- 新增序列表 wms_number_sequence,单号取号改为 INSERT...ON DUPLICATE KEY 原子递增(含历史 seed 对齐)
- 补齐 wms_order_delivery 基表缺失 25 列(修复 Unknown column)
- 权限固定 ID 540-549 + 角色授权迁移
- 修复 returnReceived.create 出参 record 包装;修复 afterSale 发件人查询列名(name→company_name)
- detail 接口按设计走 548 权限校验
2026-08-13 21:40:50 +08:00

146 lines
5.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';
/**
* 创建退回拆包主表 wms_return_unpack。
*
* 字段:仓库隔离 warehouse_id、拆包单号 unpack_no(RP+YYYYMMDD+6位序号)、
* 关联退回收到单 return_received_id(非必填)、运单号 waybill_code、拆包日期 unpack_date、
* 起止时间 start_time/end_time、拆包人 unpacker_id/unpacker_name、状态 status/detail_status、
* 汇总 total_items/total_quantity、原单关联 order_express_id/order_id/store_id(非必填)、
* 摄像头列表 camera_ids(JSON)、备注 remark。
*
* 索引:
* uk_unpack_no(单号唯一)
* idx_warehouse_unpack_date(仓库+日期隔离查询)
* idx_return_received_id / idx_waybill_code / idx_order_express_id
* idx_unpacker_id / idx_start_time / idx_store_id
*/
const TABLE_NAME = 'wms_return_unpack';
module.exports = {
// eslint-disable-next-line no-unused-vars
async up(queryInterface, Sequelize) {
const { BIGINT, STRING, INTEGER, DATE } = Sequelize;
await queryInterface.createTable(TABLE_NAME, {
id: {
type: BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '主键',
},
warehouse_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '仓库ID(数据隔离维度)',
},
unpack_no: {
type: STRING(50),
allowNull: false,
comment: '拆包单号,RP+YYYYMMDD+6位序号',
},
return_received_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '关联退回收到表 wms_return_received.id;非必填',
},
waybill_code: {
type: STRING(50),
allowNull: false,
comment: '拆包的运单号(退回包裹运单号)',
},
unpack_date: {
type: DATE,
allowNull: false,
comment: '拆包日期',
},
start_time: {
type: DATE,
allowNull: true,
comment: '拆包开始时间',
},
end_time: {
type: DATE,
allowNull: true,
comment: '拆包结束时间',
},
unpacker_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '拆包人员工号ID(employees_id)',
},
unpacker_name: {
type: STRING(50),
allowNull: false,
comment: '拆包人员工号名称快照(employees_name / real_name)',
},
status: {
type: STRING(20),
allowNull: false,
defaultValue: 'unpacking',
comment: '拆包状态:unpacking/completed/cancelled',
},
detail_status: {
type: STRING(30),
allowNull: false,
defaultValue: 'none_recognized',
comment: '明细识别状态:none_recognized/partial_recognized/all_recognized',
},
total_items: {
type: INTEGER(11),
allowNull: false,
defaultValue: 0,
comment: '物品种类数(明细行数)',
},
total_quantity: {
type: INTEGER(11),
allowNull: false,
defaultValue: 0,
comment: '物品总数量(明细数量合计)',
},
order_express_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '原运单ID,关联 wms_order_express.id;原单退回时回填',
},
order_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '原订单ID,便于快速匹配;原单退回时回填',
},
store_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '货主ID,原单退回/识别到系统商品时回填',
},
camera_ids: {
type: Sequelize.JSON,
allowNull: true,
comment: '摄像头ID列表,如 [1,2,3](参考 wms_pack_task.device_ids)',
},
remark: {
type: STRING(500),
allowNull: true,
comment: '备注',
},
created_at: { type: DATE, allowNull: false },
updated_at: { type: DATE, allowNull: false },
});
await queryInterface.addIndex(TABLE_NAME, [ 'unpack_no' ], { unique: true, name: 'uk_unpack_no' });
await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id', 'unpack_date' ], { name: 'idx_warehouse_unpack_date' });
await queryInterface.addIndex(TABLE_NAME, [ 'return_received_id' ], { name: 'idx_return_received_id' });
await queryInterface.addIndex(TABLE_NAME, [ 'waybill_code' ], { name: 'idx_waybill_code' });
await queryInterface.addIndex(TABLE_NAME, [ 'order_express_id' ], { name: 'idx_order_express_id' });
await queryInterface.addIndex(TABLE_NAME, [ 'unpacker_id' ], { name: 'idx_unpacker_id' });
await queryInterface.addIndex(TABLE_NAME, [ 'start_time' ], { name: 'idx_start_time' });
await queryInterface.addIndex(TABLE_NAME, [ 'store_id' ], { name: 'idx_store_id' });
},
// eslint-disable-next-line no-unused-vars
async down(queryInterface, Sequelize) {
await queryInterface.dropTable(TABLE_NAME);
},
};