first version

This commit is contained in:
liu
2026-07-23 20:41:25 +08:00
parent 00a0938a1b
commit 10cff754a4
211 changed files with 11577 additions and 842 deletions
@@ -0,0 +1,42 @@
<?php
namespace Database\Factories;
use App\Models\StoreOrderItemModel;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* 门店订单明细工厂(order_id / store_id / product_id 需调用方指定;
* amount 未显式指定时按 price × quantity 自动计算;无需 Faker
*
* @extends Factory<StoreOrderItemModel>
*/
class StoreOrderItemModelFactory extends Factory
{
protected $model = StoreOrderItemModel::class;
public function definition(): array
{
return [
'order_id' => 0,
'store_id' => 0,
'product_id' => 0,
'product_name' => '测试商品',
'product_spec' => '500g/袋',
'price' => number_format(random_int(100, 5000) / 100, 2, '.', ''),
'quantity' => number_format(random_int(100, 10000) / 100, 2, '.', ''),
'weight' => 0,
'amount' => 0,
'remark' => '',
];
}
public function configure(): static
{
return $this->afterMaking(function (StoreOrderItemModel $item): void {
if ((float) $item->amount === 0.0 && (float) $item->price > 0 && (float) $item->quantity > 0) {
$item->amount = bcmul((string) $item->price, (string) $item->quantity, 2);
}
});
}
}