- 修正所有模組 Controller 的 Model 引用路徑 (App\Modules\...) - 更新 ProductionOrder 與 ProductionOrderItem 模型結構以符合新版邏輯 - 修復 resources/js/utils/format.ts 在處理空值時導致 toLocaleString 崩潰的問題 - 清除全域路徑與 Controller 遷移殘留檔案
71 lines
2.9 KiB
PHP
71 lines
2.9 KiB
PHP
<?php
|
||
|
||
namespace Database\Factories;
|
||
|
||
use App\Modules\Inventory\Models\Category;
|
||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||
|
||
/**
|
||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Modules\Inventory\Models\Product>
|
||
*/
|
||
class ProductFactory extends Factory
|
||
{
|
||
/**
|
||
* Define the model's default state.
|
||
*
|
||
* @return array<string, mixed>
|
||
*/
|
||
public function definition(): array
|
||
{
|
||
// 定義豐富的中文測試資料庫
|
||
$productNames = [
|
||
'高山烏龍茶', '茉莉綠茶', '特級紅茶', '四季春茶', '阿薩姆紅茶', '錫蘭紅茶', '普洱茶',
|
||
'珍珠粉圓', '波霸粉圓', '椰果', '仙草凍', '愛玉凍', '布丁', '紅豆', '綠豆',
|
||
'果糖', '黑糖漿', '蜂蜜', '蔗糖液', '煉乳',
|
||
'奶精粉', '鮮奶油', '全脂鮮乳', '低脂鮮乳', '燕麥奶',
|
||
'檸檬原汁', '百香果漿', '芒果果泥', '草莓果醬', '柳橙濃縮汁',
|
||
'塑膠杯 (700cc)', '紙杯 (500cc)', '封口膜', '粗吸管', '細吸管', '杯蓋',
|
||
'外帶提袋 (單杯)', '外帶提袋 (雙杯)', '吸管套', '杯架'
|
||
];
|
||
|
||
$brands = [
|
||
'統一', '光泉', '味全', '雀巢', '立頓', '天仁', '台糖', '義美', '開元', '瑞穗', '六甲田莊', '南亞塑膠'
|
||
];
|
||
|
||
$specs = [
|
||
'業務用 5kg裝', '100入/袋', '業務號 3L', '特級品', 'A級', '家庭號 2L', '10kg/箱', '500g/罐'
|
||
];
|
||
|
||
$units = ['包', '罐', '瓶', '箱', '袋', '個', '支', '公斤', '公升'];
|
||
$baseUnit = $this->faker->randomElement($units);
|
||
|
||
$largeUnits = ['箱', '袋', '桶', '磨', '組'];
|
||
$largeUnit = $this->faker->randomElement($largeUnits);
|
||
|
||
$purchaseUnits = ['箱', '棧板', '車'];
|
||
$purchaseUnit = $this->faker->randomElement($purchaseUnits);
|
||
|
||
// 隨機取得一個 Category,若沒有則略過
|
||
$category = Category::inRandomOrder()->first();
|
||
|
||
// 為了讓名稱不重複,可以加個隨機形容詞或編號,或者直接用 faker 但指定語系 (若 env 不能改)
|
||
// 這裡我們混搭:隨機選一個品名 + 隨機品牌 + 隨機規格,組成較真實的商品描述概念
|
||
|
||
$name = $this->faker->randomElement($productNames);
|
||
$brand = $this->faker->randomElement($brands);
|
||
$spec = $this->faker->randomElement($specs);
|
||
|
||
return [
|
||
'code' => strtoupper($this->faker->unique()->bothify('??###')),
|
||
'name' => $name . ' (' . $brand . ')', // 例如:高山烏龍茶 (天仁)
|
||
'category_id' => $category ? $category->id : null,
|
||
'brand' => $brand,
|
||
'specification' => $spec,
|
||
'base_unit' => $baseUnit,
|
||
'large_unit' => $largeUnit,
|
||
'conversion_rate' => $this->faker->numberBetween(10, 1000),
|
||
'purchase_unit' => $purchaseUnit,
|
||
];
|
||
}
|
||
}
|