59 lines
2.3 KiB
PHP
59 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use App\Models\{PatientRecord, Patient, Keyword};
|
|
use Slowlyo\OwlAdmin\Models\AdminUser;
|
|
use App\Enums\OrderStatus;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\PatientRecord>
|
|
*/
|
|
class PatientRecordFactory extends Factory
|
|
{
|
|
protected $model = PatientRecord::class;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
$faker = $this->faker;
|
|
$sell_price = $faker->numberBetween(100, 200);
|
|
$patient = Patient::inRandomOrder()->first();
|
|
$type = $patient->type;
|
|
$doctor_ratio = data_get($type->options, 'doctor_ratio', 0);
|
|
$inviter_ratio = data_get($type->options, 'inviter_ratio', 0);
|
|
$saler_ratio = data_get($type->options, 'saler_ratio', 0);
|
|
return [
|
|
'patient_id' => $patient->id,
|
|
'user_id' => $patient->user_id,
|
|
'type_id' => $type->id,
|
|
'illness_type_id' => Keyword::where('type_key', PatientRecord::ILLNESS_TYPE_KEY)->inRandomOrder()->value('id'),
|
|
'treat_at' => $faker->dateTimeBetween('-7 days'),
|
|
'doctor_id' => AdminUser::inRandomOrder()->value('id'),
|
|
'doctor_ratio' => $doctor_ratio,
|
|
'doctor_money' => floor($sell_price * $doctor_ratio) / 100,
|
|
'inviter_id' => $patient->inviter_id,
|
|
'inviter_ratio' => $inviter_ratio,
|
|
'inviter_money' => $patient->inviter_id ? floor($sell_price * $inviter_ratio) / 100 : 0,
|
|
'saler_id' => $patient->saler_id,
|
|
'saler_ratio' => $saler_ratio,
|
|
'saler_money' => $patient->saler_id ? floor($sell_price * $saler_ratio) / 100 : 0,
|
|
'content' => '逐渐恢复',
|
|
'origin_price' => $faker->numberBetween(200, 300),
|
|
'sell_price' => $faker->numberBetween(100, 200),
|
|
'order_status' => OrderStatus::Success->value,
|
|
'notify_at' => $faker->dateTimeBetween('now', '+7 days'),
|
|
'notify_user_id' => 1,
|
|
'notify_remarks' => '带上医保卡',
|
|
'is_notified' => 0,
|
|
'next_treat_at' => $faker->dateTimeBetween('now', '+7 days'),
|
|
'creator_id' => 1,
|
|
];
|
|
}
|
|
}
|