diff --git a/app/Console/Commands/ComputeProductMonthlyWeightedAverage.php b/app/Console/Commands/ComputeProductMonthlyWeightedAverage.php index c194624d..d0c1c29b 100644 --- a/app/Console/Commands/ComputeProductMonthlyWeightedAverage.php +++ b/app/Console/Commands/ComputeProductMonthlyWeightedAverage.php @@ -43,7 +43,8 @@ class ComputeProductMonthlyWeightedAverage extends Command $updates = []; foreach ($rows as $row) { - $code = trim((string) $row->product_code); + // 普通商品资料与进销存的商品编码大小写不一致,统一按大写匹配。 + $code = mb_strtoupper(trim((string) $row->product_code)); $costPrice = is_array($cost) ? ($cost[$code] ?? null) : null; $workPrice = is_array($work) ? ($work[$code] ?? null) : null; $changePrice = is_array($change) ? ($change[$code] ?? null) : null; @@ -95,7 +96,7 @@ class ComputeProductMonthlyWeightedAverage extends Command foreach (array_chunk($codes, 2000) as $chunk) { foreach (DB::connection($connection)->table('ops_jst_sku') ->whereIn('sku_id', $chunk)->whereNotNull('cost_price')->get(['sku_id', 'cost_price']) as $row) { - $map[trim((string) $row->sku_id)] = (float) $row->cost_price; + $map[mb_strtoupper(trim((string) $row->sku_id))] = (float) $row->cost_price; } } @@ -119,7 +120,7 @@ class ComputeProductMonthlyWeightedAverage extends Command ->orderBy('effectTime') ->get(['skuCode', 'purchasePrice', 'effectTime']); foreach ($rows as $row) { - $map[trim((string) $row->skuCode)] = [ + $map[mb_strtoupper(trim((string) $row->skuCode))] = [ 'price' => (float) $row->purchasePrice, 'effect' => $row->effectTime === null ? null : (string) $row->effectTime, ]; @@ -142,7 +143,7 @@ class ComputeProductMonthlyWeightedAverage extends Command ->orderBy('effectStartTime') ->get(['skucode', 'afterPrice', 'effectStartTime']); foreach ($rows as $row) { - $map[trim((string) $row->skucode)] = [ + $map[mb_strtoupper(trim((string) $row->skucode))] = [ 'price' => (float) $row->afterPrice, 'time' => $row->effectStartTime === null ? null : (string) $row->effectStartTime, ];