refactor: 調整倉庫自動建立機制,統一使用門市倉類型 (retail)
This commit is contained in:
@@ -10,7 +10,6 @@ enum WarehouseType: string
|
|||||||
case VENDING = 'vending'; // 販賣機倉/IoT
|
case VENDING = 'vending'; // 販賣機倉/IoT
|
||||||
case TRANSIT = 'transit'; // 在途倉/移動倉
|
case TRANSIT = 'transit'; // 在途倉/移動倉
|
||||||
case QUARANTINE = 'quarantine'; // 瑕疵倉/報廢倉
|
case QUARANTINE = 'quarantine'; // 瑕疵倉/報廢倉
|
||||||
case SYSTEM_SALES = 'system_sales'; // 系統自動建立的銷售倉
|
|
||||||
|
|
||||||
public function label(): string
|
public function label(): string
|
||||||
{
|
{
|
||||||
@@ -21,7 +20,6 @@ enum WarehouseType: string
|
|||||||
self::VENDING => '販賣機 (IoT設備)',
|
self::VENDING => '販賣機 (IoT設備)',
|
||||||
self::TRANSIT => '在途倉 (物流車)',
|
self::TRANSIT => '在途倉 (物流車)',
|
||||||
self::QUARANTINE => '瑕疵倉 (報廢/檢驗)',
|
self::QUARANTINE => '瑕疵倉 (報廢/檢驗)',
|
||||||
self::SYSTEM_SALES => '系統銷售倉',
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -599,11 +599,21 @@ class InventoryService implements InventoryServiceInterface
|
|||||||
*/
|
*/
|
||||||
public function findOrCreateWarehouseByName(string $warehouseName)
|
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(
|
return Warehouse::firstOrCreate(
|
||||||
['name' => $warehouseName],
|
['name' => '整合銷售倉'],
|
||||||
[
|
[
|
||||||
'code' => 'SALES-' . strtoupper(bin2hex(random_bytes(4))),
|
'code' => 'INT-RETAIL-001',
|
||||||
'type' => 'system_sales',
|
'type' => 'retail',
|
||||||
'is_active' => true,
|
'is_active' => true,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user