diff --git a/app/service/systems/delivery_order.js b/app/service/systems/delivery_order.js index 6f4d64d..066a215 100644 --- a/app/service/systems/delivery_order.js +++ b/app/service/systems/delivery_order.js @@ -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; } diff --git a/app/service/systems/stock_store.js b/app/service/systems/stock_store.js index 684440e..1d7f2b6 100644 --- a/app/service/systems/stock_store.js +++ b/app/service/systems/stock_store.js @@ -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,