From 1c679f0215aa4e1ee9f75eb12ec2113c02e0f2df Mon Sep 17 00:00:00 2001 From: chenxi Date: Wed, 30 Sep 2026 16:43:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A5=E5=BA=93=E6=98=8E=E7=BB=86=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E7=AE=80=E7=A7=B0=E5=8C=B9=E9=85=8D=E8=A7=84=E5=88=99?= =?UTF-8?q?=EF=BC=9A=E4=BB=93=E5=BA=93=E5=90=8D=E5=8C=B9=E9=85=8D=EF=BC=8C?= =?UTF-8?q?=E5=90=AB=E4=BB=A3=E5=8F=91=E4=BB=93=E5=AD=97=E6=A0=B7=E7=9A=84?= =?UTF-8?q?=E6=8C=89=E4=BB=93=E5=82=A8=E6=96=B9=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/ImportInventoryInboundDetail.php | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/app/Console/Commands/ImportInventoryInboundDetail.php b/app/Console/Commands/ImportInventoryInboundDetail.php index baa58da0..212aab56 100644 --- a/app/Console/Commands/ImportInventoryInboundDetail.php +++ b/app/Console/Commands/ImportInventoryInboundDetail.php @@ -25,8 +25,8 @@ class ImportInventoryInboundDetail extends Command $forcedMonth = trim((string) ($this->option('month') ?? '')); $now = now(); - $shortNames = $this->shortNameMap(); - $this->info('仓库名称映射:' . count($shortNames) . ' 个仓库名可唯一匹配'); + $maps = $this->shortNameMap(); + $this->info('仓库名称映射:仓库名 ' . count($maps['warehouse']) . ' 个、仓储方 ' . count($maps['provider']) . ' 个可唯一匹配'); // 原样导入:以本次文件为准整体重建,不做去重、不做加工。 DB::connection($connection)->table($table)->delete(); @@ -58,7 +58,13 @@ class ImportInventoryInboundDetail extends Command continue; } - $shortName = $warehouse !== '' ? ($shortNames[$warehouse] ?? '') : ''; + // 一般用"仓库"匹配仓库简称;含"代发仓"字样的按"仓储方"匹配。 + $shortName = ''; + if ($warehouse !== '') { + $shortName = str_contains($warehouse, '代发仓') + ? ($maps['provider'][$warehouse] ?? $maps['warehouse'][$warehouse] ?? '') + : ($maps['warehouse'][$warehouse] ?? ''); + } if ($shortName !== '') { $mapped++; } @@ -114,7 +120,10 @@ class ImportInventoryInboundDetail extends Command return self::SUCCESS; } - /** @return array 仓库名 => 仓库简称(仅唯一匹配的) */ + /** + * @return array{warehouse:array,provider:array} + * 仅保留能唯一匹配的键 + */ private function shortNameMap(): array { $rows = InventoryWarehouseNameMapping::withoutGlobalScopes() @@ -128,16 +137,14 @@ class ImportInventoryInboundDetail extends Command $grouped[$warehouse][] = trim((string) $row->warehouse_short_name); } - $map = []; + $byWarehouse = []; foreach ($grouped as $warehouse => $names) { $unique = array_values(array_unique($names)); if (count($unique) === 1 && $unique[0] !== '') { - $map[$warehouse] = $unique[0]; + $byWarehouse[$warehouse] = $unique[0]; } } - // 明细表里“仓库”一列有时填的是仓储方名称(例如"工厂-沐野竹木代发仓"), - // 仓库名匹配不到时再按仓储方唯一匹配一次。 $byProvider = []; foreach ($rows as $row) { $provider = trim((string) $row->warehouse_provider); @@ -147,16 +154,13 @@ class ImportInventoryInboundDetail extends Command $byProvider[$provider][] = trim((string) $row->warehouse_short_name); } foreach ($byProvider as $provider => $names) { - if (isset($map[$provider])) { - continue; - } $unique = array_values(array_unique($names)); if (count($unique) === 1 && $unique[0] !== '') { - $map[$provider] = $unique[0]; + $byProvider[$provider] = $unique[0]; } } - return $map; + return ['warehouse' => $byWarehouse, 'provider' => $byProvider]; } private function monthOf(string $value): string