diff --git a/app/service/systemMethods/stock/transaction.js b/app/service/systemMethods/stock/transaction.js index 006b3be..1c06b0e 100644 --- a/app/service/systemMethods/stock/transaction.js +++ b/app/service/systemMethods/stock/transaction.js @@ -166,6 +166,7 @@ class StockTransactionMethodService extends MainService { orderId, sort: sortOption, pagination, + mode: 'store', }); return this.success('ok', result); diff --git a/app/service/systems/stock_transaction.js b/app/service/systems/stock_transaction.js index 2e0f6e7..918201d 100644 --- a/app/service/systems/stock_transaction.js +++ b/app/service/systems/stock_transaction.js @@ -433,18 +433,27 @@ class StockTransactionService extends Service { ? rawStockIds.map(item => Number(item)).filter(item => Number.isInteger(item) && item > 0) : []; const normalizedKeyword = String(keyword || '').trim(); + let keywordResolvedEmpty = false; if (normalizedKeyword && resolvedStockIds.length === 0) { const isStoreMode = mode === 'store'; const primaryDimCol = isStoreMode ? 'store_id' : 'warehouse_id'; const primaryDimVal = isStoreMode ? Number(storeId) : Number(warehouseId); if (primaryDimVal > 0) { resolvedStockIds = await this._resolveKeywordToStockIds(normalizedKeyword, primaryDimCol, primaryDimVal); + if (resolvedStockIds.length === 0) { + // keyword 无匹配商品,避免退化为查询全部流水 + keywordResolvedEmpty = true; + } } } const whereClauses = []; const replacements = {}; + if (keywordResolvedEmpty) { + whereClauses.push('1 = 0'); + } + // 数据范围限定:仓库侧或货主侧 if (warehouseId !== undefined && warehouseId !== null) { whereClauses.push('t.warehouse_id = :warehouseId'); @@ -686,12 +695,17 @@ class StockTransactionService extends Service { ? rawStockIds.map(item => Number(item)).filter(item => Number.isInteger(item) && item > 0) : []; const normalizedKeyword = String(keyword || '').trim(); + let keywordResolvedEmpty = false; if (normalizedKeyword && resolvedStockIds.length === 0) { const isStoreMode = mode === 'store'; const primaryDimCol = isStoreMode ? 'store_id' : 'warehouse_id'; const primaryDimVal = isStoreMode ? Number(storeId) : Number(warehouseId); if (primaryDimVal > 0) { resolvedStockIds = await this._resolveKeywordToStockIds(normalizedKeyword, primaryDimCol, primaryDimVal); + if (resolvedStockIds.length === 0) { + // keyword 无匹配商品,避免退化为导出全部流水 + keywordResolvedEmpty = true; + } } } @@ -699,6 +713,10 @@ class StockTransactionService extends Service { const whereClauses = []; const replacements = {}; + if (keywordResolvedEmpty) { + whereClauses.push('1 = 0'); + } + // 数据范围限定 if (warehouseId !== undefined && warehouseId !== null) { whereClauses.push('t.warehouse_id = :warehouseId');