first version
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\StoreModel;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* 门店工厂(确定性序列数据,无需 Faker)
|
||||
*
|
||||
* @extends Factory<StoreModel>
|
||||
*/
|
||||
class StoreModelFactory extends Factory
|
||||
{
|
||||
protected $model = StoreModel::class;
|
||||
|
||||
private static int $sequence = 0;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
$seq = ++self::$sequence;
|
||||
|
||||
return [
|
||||
'name' => '测试门店' . $seq,
|
||||
'code' => 'S' . str_pad((string) $seq, 6, '0', STR_PAD_LEFT),
|
||||
'level_id' => 0,
|
||||
'contact' => '联系人' . $seq,
|
||||
'phone' => '138' . str_pad((string) $seq, 8, '0', STR_PAD_LEFT),
|
||||
'address' => '测试地址' . $seq . '号',
|
||||
'payment_cycle_days' => $seq % 8,
|
||||
'status' => StoreModel::STATUS_NORMAL,
|
||||
'remark' => '',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 停用门店
|
||||
*/
|
||||
public function disabled(): static
|
||||
{
|
||||
return $this->state(fn () => ['status' => StoreModel::STATUS_DISABLED]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定回款周期(天)
|
||||
*/
|
||||
public function paymentCycle(int $days): static
|
||||
{
|
||||
return $this->state(fn () => ['payment_cycle_days' => $days]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user