初始化提交
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
|
||||
|
||||
use Hyperf\Database\Model\Collection;
|
||||
use Hyperf\Database\Model\Relations\BelongsTo;
|
||||
use Hyperf\Database\Model\Relations\HasOne;
|
||||
use Hyperf\Database\Model\Relations\HasOneThrough;
|
||||
use Hyperf\Snowflake\Concern\Snowflake;
|
||||
|
||||
/**
|
||||
* @property int $history_inquiry_id 主键id
|
||||
* @property int $patient_id 患者id
|
||||
* @property int $doctor_id 医生id
|
||||
* @property int $pharmacist_id 药师id
|
||||
* @property int $order_inquiry_id 订单-问诊id
|
||||
* @property int $history_status 删除状态(0:否 1:是)
|
||||
* @property \Carbon\Carbon $created_at 创建时间
|
||||
* @property \Carbon\Carbon $updated_at 修改时间
|
||||
* @property-read UserDoctor $UserDoctor
|
||||
* @property-read Hospital $UserDoctorHospital
|
||||
*/
|
||||
class PatientHistoryInquiry extends Model
|
||||
{
|
||||
use Snowflake;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'patient_history_inquiry';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['history_inquiry_id', 'patient_id', 'doctor_id', 'pharmacist_id', 'order_inquiry_id', 'history_status', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['history_inquiry_id' => 'integer', 'patient_id' => 'integer', 'doctor_id' => 'integer', 'pharmacist_id' => 'integer', 'order_inquiry_id' => 'integer', 'history_status' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];
|
||||
|
||||
protected string $primaryKey = "history_inquiry_id";
|
||||
|
||||
/**
|
||||
* 关联医生表
|
||||
*/
|
||||
public function UserDoctor(): HasOne
|
||||
{
|
||||
return $this->hasOne(UserDoctor::class, 'doctor_id','doctor_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程关联医生表-医院表
|
||||
* @return HasOneThrough
|
||||
*/
|
||||
public function UserDoctorHospital(): HasOneThrough
|
||||
{
|
||||
return $this->hasOneThrough(
|
||||
Hospital::class,
|
||||
UserDoctor::class,
|
||||
"doctor_id",
|
||||
"hospital_id",
|
||||
"doctor_id",
|
||||
"hospital_id",
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息-单条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return object|null
|
||||
*/
|
||||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||||
{
|
||||
return self::where($params)->first($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息-多条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return object|null
|
||||
*/
|
||||
public static function getList(array $params, array $fields = ['*']): object|null
|
||||
{
|
||||
return self::where($params)->get($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息-多条-限制条数
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @param int $limit
|
||||
*/
|
||||
public static function getLimit(array $params, array $fields = ['*'],int $limit = 5): array
|
||||
{
|
||||
return self::where($params)->limit($limit)->get($fields)->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取首页用户历史问诊数据
|
||||
* 关联表:user_doctor
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @param int $limit
|
||||
* @return Collection|array|\Hyperf\Utils\Collection
|
||||
*/
|
||||
public static function getIndexHistoryDoctorLimit(array $params, array $fields = ["*"],int $limit = 5): Collection|array|\Hyperf\Utils\Collection
|
||||
{
|
||||
return self::with([
|
||||
"UserDoctor:doctor_id,user_name,avatar,hospital_id",
|
||||
"UserDoctor.Hospital:hospital_id,hospital_name"
|
||||
])
|
||||
->where($params)
|
||||
->limit($limit)
|
||||
->get($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param array $params
|
||||
* @param array $data
|
||||
* @return int
|
||||
*/
|
||||
public static function edit(array $params = [], array $data = []): int
|
||||
{
|
||||
return self::where($params)->update($data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user