- pick: waveClaimScan 拦截订单整体跳过领料(不置 claim_status=fin,未打印不阻隔领料);query 领料前置校验仅统计非拦截未领料订单(拦截未领料不阻隔拣货);createWavePickTask 新增 excludeUnclaimed,普通波次(source=0)计算拣货数量(order_count/任务订单/筐)时剔除未领料订单 - wave: 波次号改为 wms_number_sequence 原子取号(upsert + LAST_INSERT_ID,seed 对齐当日历史最大序),wave_no 唯一索引 uniq_wave_no,并发撞号自动重取(最多 3 次) - print: 面单自定义区首行「商品总数【n】」(items_total 优先),团购波次商品明细行尾「波次总单数×商品数量」 - returnUnpack: 列表新增 has_video/video_enable/videos 视频字段与筛选,补视频列表权限迁移 - stock: 商品新增 need_recheck(是否需要复核)字段,导入归一化与导出列支持,补迁移 - docs: 同步 methods/system.json 与 methods/changes/system.json 变更记录(恢复遗漏的已提交记录)
332 lines
8.1 KiB
JavaScript
332 lines
8.1 KiB
JavaScript
'use strict';
|
||
|
||
module.exports = app => {
|
||
const { STRING, BIGINT, DECIMAL, TEXT, DATE, CHAR, INTEGER, ENUM, TINYINT } = app.Sequelize;
|
||
|
||
const StockWarehouse = app.model.define('stock_warehouse', {
|
||
id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
comment: '主键ID',
|
||
},
|
||
item_code: {
|
||
type: STRING(50),
|
||
allowNull: false,
|
||
comment: '商品编码',
|
||
},
|
||
goods_code: {
|
||
type: STRING(50),
|
||
allowNull: true,
|
||
comment: '货物编码',
|
||
},
|
||
store_id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
allowNull: false,
|
||
comment: '货主ID',
|
||
},
|
||
item_name: {
|
||
type: STRING(255),
|
||
allowNull: false,
|
||
comment: '商品名称',
|
||
},
|
||
sku_property: {
|
||
type: STRING(100),
|
||
comment: 'SKU规格',
|
||
},
|
||
stock_unit: {
|
||
type: STRING(20),
|
||
allowNull: false,
|
||
comment: '库存单位',
|
||
},
|
||
packing_requirements: {
|
||
type: TEXT,
|
||
comment: '打包要求',
|
||
},
|
||
|
||
brand_name: {
|
||
type: STRING(100),
|
||
allowNull: true,
|
||
validate: {
|
||
len: [ 0, 50 ],
|
||
},
|
||
},
|
||
length: {
|
||
type: DECIMAL(10, 2),
|
||
defaultValue: 0.00,
|
||
comment: '长度',
|
||
},
|
||
width: {
|
||
type: DECIMAL(10, 2),
|
||
defaultValue: 0.00,
|
||
comment: '宽度',
|
||
},
|
||
height: {
|
||
type: DECIMAL(10, 2),
|
||
defaultValue: 0.00,
|
||
comment: '高度',
|
||
},
|
||
volume: {
|
||
type: INTEGER(11).UNSIGNED,
|
||
defaultValue: 0,
|
||
comment: '体积',
|
||
},
|
||
gross_weight: {
|
||
type: INTEGER(11),
|
||
defaultValue: 0,
|
||
comment: '毛重(g)',
|
||
},
|
||
net_weight: {
|
||
type: INTEGER(11),
|
||
defaultValue: 0,
|
||
comment: '净重(g)',
|
||
},
|
||
item_type: {
|
||
type: STRING(10),
|
||
allowNull: false,
|
||
comment: '商品类型',
|
||
},
|
||
tag_price: {
|
||
type: DECIMAL(10, 2),
|
||
defaultValue: 0.00,
|
||
comment: '标价',
|
||
},
|
||
retail_price: {
|
||
type: DECIMAL(10, 2),
|
||
defaultValue: 0.00,
|
||
comment: '零售价',
|
||
},
|
||
is_sn_mgmt: {
|
||
type: CHAR(1),
|
||
defaultValue: 'N',
|
||
comment: '是否序列号管理',
|
||
},
|
||
is_shelf_life_mgmt: {
|
||
type: CHAR(1),
|
||
defaultValue: 'N',
|
||
comment: '是否保质期管理',
|
||
},
|
||
is_batch_mgmt: {
|
||
type: CHAR(1),
|
||
defaultValue: 'N',
|
||
comment: '是否批次管理',
|
||
},
|
||
need_recheck: {
|
||
type: CHAR(1),
|
||
allowNull: false,
|
||
defaultValue: 'Y',
|
||
comment: '是否需要复核:Y=需要复核,N=不需要复核',
|
||
},
|
||
create_at: {
|
||
type: DATE,
|
||
allowNull: false,
|
||
comment: '创建时间',
|
||
},
|
||
level: {
|
||
type: ENUM('A', 'B', 'C'),
|
||
allowNull: true,
|
||
defaultValue: 'N',
|
||
comment: '是否需要发票',
|
||
},
|
||
update_at: {
|
||
type: DATE,
|
||
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
|
||
comment: '更新时间',
|
||
},
|
||
is_valid: {
|
||
type: CHAR(1),
|
||
defaultValue: 'Y',
|
||
comment: '是否有效',
|
||
},
|
||
is_images: {
|
||
type: CHAR(1),
|
||
defaultValue: 'Y',
|
||
comment: '是否有照片',
|
||
},
|
||
warehouse_id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
comment: '仓库ID',
|
||
},
|
||
delete_at: {
|
||
type: DATE,
|
||
comment: '删除时间',
|
||
},
|
||
quantity: {
|
||
type: INTEGER(11),
|
||
defaultValue: 0,
|
||
comment: '库存数量',
|
||
},
|
||
locked_quantity: {
|
||
type: INTEGER(11),
|
||
defaultValue: 0,
|
||
comment: '锁定数量',
|
||
},
|
||
prohibited_id: {
|
||
type: INTEGER.UNSIGNED,
|
||
comment: '违禁品类型id',
|
||
},
|
||
enable_box_spec: {
|
||
type: TINYINT(1),
|
||
defaultValue: 0,
|
||
},
|
||
quantity_per_box: {
|
||
type: INTEGER(11),
|
||
defaultValue: 0,
|
||
},
|
||
box_gross_weight: {
|
||
type: INTEGER(11),
|
||
defaultValue: 0,
|
||
comment: '箱毛重(g)',
|
||
},
|
||
box_net_weight: {
|
||
type: INTEGER(11),
|
||
defaultValue: 0,
|
||
comment: '箱净重(g)',
|
||
},
|
||
box_height: {
|
||
type: DECIMAL(10, 2),
|
||
defaultValue: 0.00,
|
||
},
|
||
box_length: {
|
||
type: DECIMAL(10, 2),
|
||
defaultValue: 0.00,
|
||
},
|
||
box_width: {
|
||
type: DECIMAL(10, 2),
|
||
defaultValue: 0.00,
|
||
},
|
||
box_volume: {
|
||
type: INTEGER(11).UNSIGNED,
|
||
defaultValue: 0,
|
||
},
|
||
inbound_min_days: {
|
||
type: INTEGER(11),
|
||
defaultValue: 0,
|
||
comment: '入库最小天数要求',
|
||
},
|
||
outbound_min_days: {
|
||
type: INTEGER(11),
|
||
defaultValue: 0,
|
||
comment: '出库最小天数要求',
|
||
},
|
||
shelf_life_days: {
|
||
type: INTEGER(11),
|
||
defaultValue: 0,
|
||
comment: '保质期天数',
|
||
},
|
||
remaining_threshold_days: {
|
||
type: INTEGER(11),
|
||
defaultValue: 0,
|
||
comment: '剩余有效期阈值天数',
|
||
},
|
||
deleted_at: {
|
||
type: DATE,
|
||
defaultValue: null,
|
||
},
|
||
}, {
|
||
tableName: 'wms_stock_warehouse',
|
||
freezeTableName: true,
|
||
timestamps: false,
|
||
paranoid: true,
|
||
comment: '仓库商品库存主表',
|
||
indexes: [
|
||
{
|
||
name: 'uk_item_code',
|
||
unique: true,
|
||
fields: [ 'item_code', 'warehouse_id', 'store_id', 'deleted_at' ],
|
||
},
|
||
{
|
||
name: 'idx_create_time',
|
||
fields: [ 'create_at' ],
|
||
},
|
||
{
|
||
name: 'idx_is_valid',
|
||
fields: [ 'is_valid' ],
|
||
},
|
||
{
|
||
name: 'warehouse_id',
|
||
fields: [ 'warehouse_id' ],
|
||
},
|
||
],
|
||
});
|
||
|
||
/**
|
||
* 商品详情缓存 key 前缀。
|
||
* 与 app/service/systems/stock_warehouse.js 中保持一致。
|
||
*/
|
||
const STOCK_DETAIL_CACHE_PREFIX = 'cache:stock_detail';
|
||
|
||
/**
|
||
* 构建商品详情缓存 key。
|
||
* @param {number} warehouseId 仓库ID
|
||
* @param {number} stockId 仓库商品ID
|
||
* @return {string} 缓存 key
|
||
*/
|
||
function buildStockDetailCacheKey(warehouseId, stockId) {
|
||
return `${STOCK_DETAIL_CACHE_PREFIX}:${warehouseId}:${stockId}`;
|
||
}
|
||
|
||
/**
|
||
* 资料变更后自动清除商品详情缓存。
|
||
* 直接在 afterUpdate hook 中使用 async/await,缓存删除很快不会阻塞主流程。
|
||
* @param {Object} instance Sequelize 模型实例
|
||
* @return {Promise<void>}
|
||
*/
|
||
async function invalidateStockDetailCacheAfterUpdate(instance) {
|
||
try {
|
||
const warehouseId = instance.get('warehouse_id');
|
||
const stockId = instance.get('id');
|
||
if (warehouseId && stockId) {
|
||
const cacheKey = buildStockDetailCacheKey(warehouseId, stockId);
|
||
if (typeof app.delCacheAsync === 'function') {
|
||
await app.delCacheAsync(cacheKey);
|
||
app.logger.info(`[StockWarehouse.afterUpdate] 已清除商品详情缓存: ${cacheKey}`);
|
||
}
|
||
}
|
||
} catch (err) {
|
||
app.logger.error(`[StockWarehouse.afterUpdate] 清除商品详情缓存失败: ${err.message}`);
|
||
}
|
||
}
|
||
|
||
// 注册 afterUpdate hook:商品资料更新时自动清除详情缓存
|
||
StockWarehouse.addHook('afterUpdate', 'invalidateStockDetailCache', invalidateStockDetailCacheAfterUpdate);
|
||
|
||
StockWarehouse.associate = function() {
|
||
const { StoreWarehouse, StockBarcode, ProhibitedType, StockStore, Storage } = app.model;
|
||
// store_stock 关联依赖 store_id + warehouse_id 复合语义,单列关联仅作为 include 入口。
|
||
StockWarehouse.belongsTo(StoreWarehouse, {
|
||
foreignKey: 'store_id', // 当前表的外键字段
|
||
targetKey: 'store_id', // 关联表业务键(非主键)
|
||
as: 'store_stock',
|
||
constraints: false,
|
||
});
|
||
StockWarehouse.hasMany(StockBarcode, {
|
||
foreignKey: 'stock_id', // StockBarcodes表中的外键字段
|
||
as: 'barcodes',
|
||
});
|
||
StockWarehouse.belongsTo(ProhibitedType, {
|
||
foreignKey: 'prohibited_id', // 当前表的外键字段
|
||
targetKey: 'id', // 关联表的主键字段
|
||
as: 'prohibited',
|
||
});
|
||
StockWarehouse.hasMany(StockStore, {
|
||
foreignKey: 'stock_id', // 当前表的外键字段
|
||
as: 'store_out_stock',
|
||
});
|
||
|
||
StockWarehouse.hasMany(Storage, {
|
||
foreignKey: 'stock_id', // 当前表的外键字段
|
||
as: 'storage',
|
||
});
|
||
|
||
const { StockTransaction } = app.model;
|
||
StockWarehouse.hasMany(StockTransaction, {
|
||
foreignKey: 'stock_id',
|
||
as: 'transactions',
|
||
});
|
||
|
||
};
|
||
|
||
return StockWarehouse;
|
||
};
|