WMS_MAIN/database/migrations/20260813120100-create-wms-return-unpack-detail.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

111 lines
3.6 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_detail。
*
* 字段:关联主表 unpack_id、仓库冗余 warehouse_id、扫描条码 barcode(可空,仅记录)、
* 系统商品 stock_id(可空,关联 wms_stock_warehouse.id)、识别标记 is_recognized、
* 快照 item_code/item_name/spec/product_snapshot、数量 quantity、产品状态 product_status、备注 remark。
*
* 索引:
* idx_unpack_id(按拆包单查明细,最高频)
* idx_warehouse_barcode(仓库+条码)
* idx_stock_id(按系统商品反查)
* idx_barcode(按条码查询)
*
* 说明:同一拆包单内可能多次扫描同一条码,明细不设 barcode 唯一约束。
*/
const TABLE_NAME = 'wms_return_unpack_detail';
module.exports = {
// eslint-disable-next-line no-unused-vars
async up(queryInterface, Sequelize) {
const { BIGINT, STRING, INTEGER, DATE, TEXT, TINYINT } = Sequelize;
await queryInterface.createTable(TABLE_NAME, {
id: {
type: BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '主键',
},
unpack_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '关联拆包主表 wms_return_unpack.id',
},
warehouse_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '仓库ID(冗余,隔离查询)',
},
barcode: {
type: STRING(100),
allowNull: true,
comment: '扫描条码(前端可选传入,仅作记录;后端不用于识别)',
},
stock_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '关联 wms_stock_warehouse.id;识别到系统商品时回填,非识别为空',
},
is_recognized: {
type: TINYINT(1),
allowNull: false,
defaultValue: 0,
comment: '是否识别:1=识别到系统商品,0=非识别物品',
},
item_code: {
type: STRING(50),
allowNull: true,
comment: '商品编码快照(识别时回填)',
},
item_name: {
type: STRING(255),
allowNull: true,
comment: '物品名称(识别时回填;非识别时可手工补录)',
},
spec: {
type: STRING(100),
allowNull: true,
comment: '规格快照(sku_property)',
},
quantity: {
type: INTEGER(11),
allowNull: false,
defaultValue: 1,
comment: '数量',
},
product_status: {
type: STRING(20),
allowNull: false,
defaultValue: 'normal',
comment: '产品状态:normal-正常,damaged-破损',
},
product_snapshot: {
type: TEXT,
allowNull: true,
comment: '商品信息快照(JSON),识别时回填,防止商品资料变更后历史丢失',
},
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_id' ], { name: 'idx_unpack_id' });
await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id', 'barcode' ], { name: 'idx_warehouse_barcode' });
await queryInterface.addIndex(TABLE_NAME, [ 'stock_id' ], { name: 'idx_stock_id' });
await queryInterface.addIndex(TABLE_NAME, [ 'barcode' ], { name: 'idx_barcode' });
},
// eslint-disable-next-line no-unused-vars
async down(queryInterface, Sequelize) {
await queryInterface.dropTable(TABLE_NAME);
},
};