fix(stock): getStoreStocks 修复 store_id 过滤失效导致跨货主/跨仓库数据泄漏
- store_id/warehouse_id/软删条件原先放在 LEFT JOIN(required:false) 的 include.where 上,只进 ON 子句无法过滤主表 wms_stock_store,传 store_id 仍返回跨货主商品 - 过滤条件改为直接落在主表 where,count/findAll 同条件,total 恢复准确 - 返回的 store_id 字段补取 warehouse_stock.store_id,并加空列表访问保护 - 订单创建报错"库存记录不存在"补上商品编码 item_code,并区分场景改为"仓库已解绑,请联系仓库关联绑定"
This commit is contained in:
parent
e8f9ccad95
commit
a3ec20098f
@ -1647,7 +1647,8 @@ class DeliveryOrderService extends Service {
|
||||
const stockId = Number(wms_stock.stock_id) || 0;
|
||||
|
||||
if (!stockId) {
|
||||
errors.push(`第${i + 1}行: 商品《${wms_stock.item_name}》库存记录不存在`);
|
||||
// 此时 stock_store 存在但未绑定库存记录(stock_id 为空),即仓库侧已解绑
|
||||
errors.push(`第${i + 1}行: 商品《${wms_stock.item_name}》编码《${wms_stock.item_code}》仓库已解绑,请联系仓库关联绑定`);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@ -2832,9 +2832,15 @@ class stockStoreService extends Service {
|
||||
deleted_at: null,
|
||||
is_valid: 'Y',
|
||||
};
|
||||
const StockStoreWhere = {};
|
||||
// 过滤条件必须落在主表(wms_stock_store),include 为 LEFT JOIN 时
|
||||
// 条件只会进 ON 子句,无法过滤主表,会导致跨货主/跨仓库数据泄漏。
|
||||
const StockStoreWhere = {
|
||||
warehouse_id: warehouseId,
|
||||
delete_at: null,
|
||||
is_valid: 'Y',
|
||||
};
|
||||
if (store_id) {
|
||||
StockWarehouseWhere.store_id = store_id;
|
||||
StockStoreWhere.store_id = store_id;
|
||||
}
|
||||
if (item_code) {
|
||||
const processedValue = item_code.split(',');
|
||||
@ -2858,19 +2864,13 @@ class stockStoreService extends Service {
|
||||
[ total, barcodes ] = await Promise.all([
|
||||
ctx.model.StockStore.count({
|
||||
where: StockStoreWhere,
|
||||
attributes: [
|
||||
'item_code', 'item_name', 'app_key', 'create_from', 'id', 'stock_id',
|
||||
],
|
||||
include: [{
|
||||
model: ctx.model.StockWarehouse,
|
||||
as: 'warehouse_stock',
|
||||
attributes: [ 'id' ],
|
||||
attributes: [ 'id', 'store_id' ],
|
||||
where: StockWarehouseWhere,
|
||||
required: false,
|
||||
}],
|
||||
limit: parseInt(pageSize),
|
||||
offset: parseInt(offset),
|
||||
raw: true,
|
||||
}),
|
||||
ctx.model.StockStore.findAll({
|
||||
where: StockStoreWhere,
|
||||
@ -2880,7 +2880,7 @@ class stockStoreService extends Service {
|
||||
include: [{
|
||||
model: ctx.model.StockWarehouse,
|
||||
as: 'warehouse_stock',
|
||||
attributes: [ 'id' ],
|
||||
attributes: [ 'id', 'store_id' ],
|
||||
where: StockWarehouseWhere,
|
||||
required: false,
|
||||
}],
|
||||
@ -2916,7 +2916,7 @@ class stockStoreService extends Service {
|
||||
item_name: item.item_name,
|
||||
};
|
||||
});
|
||||
const get_store_id = warehouseStock ? warehouseStock.store_id : barcodes[0]['warehouse_stock.store_id'];
|
||||
const get_store_id = warehouseStock ? warehouseStock.store_id : (barcodes[0] ? barcodes[0]['warehouse_stock.store_id'] : null);
|
||||
return {
|
||||
rows: results,
|
||||
store_id: get_store_id,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user