51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\StoreOrderModel;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* 门店订单工厂(store_id 需调用方指定;无需 Faker)
|
|
*
|
|
* @extends Factory<StoreOrderModel>
|
|
*/
|
|
class StoreOrderModelFactory extends Factory
|
|
{
|
|
protected $model = StoreOrderModel::class;
|
|
|
|
private static int $sequence = 0;
|
|
|
|
public function definition(): array
|
|
{
|
|
$seq = ++self::$sequence;
|
|
|
|
return [
|
|
'order_no' => 'SO' . str_pad((string) $seq, 12, '0', STR_PAD_LEFT),
|
|
'store_id' => 0,
|
|
'order_date' => now()->toDateString(),
|
|
'total_quantity' => 0,
|
|
'total_weight' => 0,
|
|
'total_amount' => 0,
|
|
'status' => StoreOrderModel::STATUS_PENDING,
|
|
'remark' => '',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 指定订货日期
|
|
*/
|
|
public function onDate(string $date): static
|
|
{
|
|
return $this->state(fn () => ['order_date' => $date]);
|
|
}
|
|
|
|
/**
|
|
* 已汇总(已被采购单归集)
|
|
*/
|
|
public function summarized(): static
|
|
{
|
|
return $this->state(fn () => ['status' => StoreOrderModel::STATUS_SUMMARIZED]);
|
|
}
|
|
}
|