From 62dcf04e953dabb8f162d41bc8641f540f7201cf Mon Sep 17 00:00:00 2001 From: sky121113 Date: Mon, 23 Feb 2026 13:49:36 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=AA=BF=E6=95=B4=E5=80=89?= =?UTF-8?q?=E5=BA=AB=E8=87=AA=E5=8B=95=E5=BB=BA=E7=AB=8B=E6=A9=9F=E5=88=B6?= =?UTF-8?q?=EF=BC=8C=E7=B5=B1=E4=B8=80=E4=BD=BF=E7=94=A8=E9=96=80=E5=B8=82?= =?UTF-8?q?=E5=80=89=E9=A1=9E=E5=9E=8B=20(retail)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Enums/WarehouseType.php | 2 -- .../Inventory/Services/InventoryService.php | 16 +++++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/Enums/WarehouseType.php b/app/Enums/WarehouseType.php index dbfee57..c099684 100644 --- a/app/Enums/WarehouseType.php +++ b/app/Enums/WarehouseType.php @@ -10,7 +10,6 @@ enum WarehouseType: string case VENDING = 'vending'; // 販賣機倉/IoT case TRANSIT = 'transit'; // 在途倉/移動倉 case QUARANTINE = 'quarantine'; // 瑕疵倉/報廢倉 - case SYSTEM_SALES = 'system_sales'; // 系統自動建立的銷售倉 public function label(): string { @@ -21,7 +20,6 @@ enum WarehouseType: string self::VENDING => '販賣機 (IoT設備)', self::TRANSIT => '在途倉 (物流車)', self::QUARANTINE => '瑕疵倉 (報廢/檢驗)', - self::SYSTEM_SALES => '系統銷售倉', }; } } diff --git a/app/Modules/Inventory/Services/InventoryService.php b/app/Modules/Inventory/Services/InventoryService.php index f0b081f..430c51a 100644 --- a/app/Modules/Inventory/Services/InventoryService.php +++ b/app/Modules/Inventory/Services/InventoryService.php @@ -599,11 +599,21 @@ class InventoryService implements InventoryServiceInterface */ public function findOrCreateWarehouseByName(string $warehouseName) { + // 1. 優先查找名稱完全匹配且啟用的倉庫(不限類型) + $warehouse = Warehouse::where('name', $warehouseName) + ->where('is_active', true) + ->first(); + + if ($warehouse) { + return $warehouse; + } + + // 2. 若找不到對應倉庫,則統一進入「整合銷售倉」(類型:retail) return Warehouse::firstOrCreate( - ['name' => $warehouseName], + ['name' => '整合銷售倉'], [ - 'code' => 'SALES-' . strtoupper(bin2hex(random_bytes(4))), - 'type' => 'system_sales', + 'code' => 'INT-RETAIL-001', + 'type' => 'retail', 'is_active' => true, ] );