96 lines
2.3 KiB
PHP
96 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\OrderStatus;
|
|
use EloquentFilter\Filterable;
|
|
use App\Traits\HasDateTimeFormatter;
|
|
use Slowlyo\OwlAdmin\Models\AdminUser;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
|
|
/**
|
|
* 病历记录
|
|
*/
|
|
class PatientRecord extends Model
|
|
{
|
|
use HasDateTimeFormatter, Filterable;
|
|
|
|
const ILLNESS_TYPE_KEY = 'illness_type';
|
|
|
|
protected $fillable = [
|
|
'patient_id', 'type_id', 'illness_type_id',
|
|
'treat_at', 'content', 'images',
|
|
'doctor_id', 'doctor_ratio', 'doctor_money',
|
|
'saler_id', 'saler_ratio', 'saler_money',
|
|
'inviter_id', 'inviter_ratio', 'inviter_money',
|
|
'origin_price', 'sell_price', 'order_status',
|
|
'notify_at', 'notify_user_id', 'notify_remarks', 'is_notified', 'next_treat_at',
|
|
'creator_id',
|
|
];
|
|
|
|
protected $appends = ['order_status_text'];
|
|
|
|
protected $casts = [
|
|
'order_status' => OrderStatus::class,
|
|
'notify_at' => 'date',
|
|
'treat_at' => 'datetime',
|
|
'next_treat_at' => 'datetime',
|
|
'origin_price' => 'float',
|
|
'sell_price' => 'float',
|
|
'images' => 'json',
|
|
];
|
|
|
|
public function patient()
|
|
{
|
|
return $this->belongsTo(Patient::class, 'patient_id');
|
|
}
|
|
|
|
public function type()
|
|
{
|
|
return $this->belongsTo(Keyword::class, 'type_id');
|
|
}
|
|
|
|
public function doctor()
|
|
{
|
|
return $this->belongsTo(AdminUser::class, 'doctor_id');
|
|
}
|
|
|
|
public function inviter()
|
|
{
|
|
return $this->belongsTo(AdminUser::class, 'inviter_id');
|
|
}
|
|
|
|
public function saler()
|
|
{
|
|
return $this->belongsTo(AdminUser::class, 'saler_id');
|
|
}
|
|
|
|
public function notifyUser()
|
|
{
|
|
return $this->belongsTo(AdminUser::class, 'notify_user_id');
|
|
}
|
|
|
|
public function creator()
|
|
{
|
|
return $this->belongsTo(AdminUser::class, 'creator_id');
|
|
}
|
|
|
|
public function illnessType()
|
|
{
|
|
return $this->belongsTo(Keyword::class, 'illness_type_id');
|
|
}
|
|
|
|
public function scopeSort($q)
|
|
{
|
|
return $q->orderBy('treat_at', 'desc');
|
|
}
|
|
|
|
protected function orderStatusText(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->order_status ? $this->order_status->text() : '',
|
|
);
|
|
}
|
|
}
|