123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- namespace app\admin\model;
- use support\Db;
- use support\Model;
- /**
- * 医生模型
- * Class MedicalCareDoctor
- * @package app\admin\model
- */
- class MedicalCareDoctor extends Model
- {
- const UPDATED_AT = 'doctor_update_time';//模型自动更新时间字段
- const TYPE_HOSPITAL = 0;
- const TYPE_PHYSICIAN = 1;
- const TYPE_FAMILY = 2;
- const DOCTOR_TYPE = [
- self::TYPE_HOSPITAL => '医院医生',
- self::TYPE_PHYSICIAN => '健康管理师',
- self::TYPE_FAMILY => '家庭医生'
- ];
- const ON_LINE_NO = 0;
- const ON_LINE_YES = 1;
- const DOCTOR_ON_LINE = [
- self::ON_LINE_NO => '不支持',
- self::ON_LINE_YES => '支持线上'
- ];
- const STATUS_WORK = 1;
- const STATUS_REST = 0;
- const DOCTOR_STATUS = [
- self::STATUS_REST => '休班',
- self::STATUS_WORK => '上班'
- ];
- const DEL_NO = 0;
- const DEL_YES = 1;
- const DOCTOR_DEL = [
- self::DEL_NO => '未删除',
- self::DEL_YES => '已删除'
- ];
- /**
- * The table associated with the model.
- *
- * @var string
- */
- protected $table = 'medical_care_doctor';
- protected $dateFormat = 'U';//操作数据库时间格式 时间戳
- /**
- * Notes:模型关联 科目
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- * User: yym
- * Date: 2022/9/26
- */
- public function subject()
- {
- return $this->hasOne(MedicalCareSubject::class, 'subject_id', 'doctor_subject_id')->where(['subject_del' => MedicalCareSubject::DEL_NO]);
- }
- public function merchant_shop()
- {
- return $this->hasOne(MerchantShop::class, 'shop_id', 'doctor_shop_id')->where(['shop_del' => MerchantShop::DEL_NO]);
- }
- /**
- * Notes:获取医生列表
- * @param string $keywords
- * @param int $page
- * @param int $limit
- * @return array
- * User: QJF
- * Date: 2022/9/21
- */
- public static function getDoctorList(int $page, int $limit, $keywords)
- {
- $list = static::select('*')
- ->where(['doctor_del' => static::DEL_NO])
- ->when($keywords != '', function ($query) use ($keywords){
- $query->where('doctor_name', 'like', '%' . $keywords . '%')
- ->orWhere('doctor_mobile', 'like', '%' . $keywords . '%');
- })
- ->with(
- [
- 'subject' => function($query){
- $query->select('subject_id', 'subject_name');
- },
- 'merchant_shop' => function($query){
- $query->select('shop_id', 'shop_name', 'shop_logo');
- }
- ]
- )
- ->orderBy('doctor_create_time','DESC')
- ->forPage($page, $limit)
- ->get();
- $count = static::count();
- return [$list, $count];
- }
- /**
- * Notes:检测医生是否存在
- * @param $doctor_name
- * @param $doctor_mobile
- * @return bool
- * User: yym
- * Date: 2022/9/26
- * 验证条件:医生姓名+手机号同时存在的情况下
- */
- public static function checkDoctorName($doctor_name, $doctor_mobile)
- {
- return static::where(['doctor_name' => $doctor_name, 'doctor_mobile' => $doctor_mobile, 'doctor_del' => static::DEL_NO])->exists();
- }
- /**
- * Notes:检测不同账号姓名存在
- * @param $doctor_name
- * @param $doctor_mobile
- * @param $doctor_id
- * @return bool
- * User: yym
- * Date: 2022/9/26
- */
- public static function checkDoctorCount($doctor_name, $doctor_mobile, $doctor_id)
- {
- return static::where(['doctor_name' => $doctor_name, 'doctor_mobile' => $doctor_mobile, 'doctor_del' => static::DEL_NO])->where('doctor_id', '!=', $doctor_id)->exists();
- }
- /**
- * Notes:获取医生详情
- * @param int $doctor_id
- * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
- * User: yym
- * Date: 2022/9/26
- */
- public static function getDoctorInfo(int $doctor_id)
- {
- return static::where(['doctor_id' => $doctor_id])
- ->with(
- [
- 'subject' => function($query){
- $query->select('subject_id', 'subject_name');
- },
- 'merchant_shop' => function($query){
- $query->select('shop_id', 'shop_name', 'shop_logo');
- }
- ]
- )
- ->first();
- }
- /**
- * Notes:更新医生数据
- * @param int $doctor_id
- * @param array $update
- * @return false|int
- * User: yym
- * Date: 2022/9/26
- */
- public static function updateDoctor(int $doctor_id, array $update)
- {
- if(empty($doctor_id) || empty($update))
- {
- return false;
- }
- return static::where(['doctor_id' => $doctor_id])->update($update);
- }
- }
|