MedicalCareDoctor.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. namespace app\admin\model;
  3. use support\Db;
  4. use support\Model;
  5. /**
  6. * 医生模型
  7. * Class MedicalCareDoctor
  8. * @package app\admin\model
  9. */
  10. class MedicalCareDoctor extends Model
  11. {
  12. const UPDATED_AT = 'doctor_update_time';//模型自动更新时间字段
  13. const TYPE_HOSPITAL = 0;
  14. const TYPE_PHYSICIAN = 1;
  15. const TYPE_FAMILY = 2;
  16. const DOCTOR_TYPE = [
  17. self::TYPE_HOSPITAL => '医院医生',
  18. self::TYPE_PHYSICIAN => '健康管理师',
  19. self::TYPE_FAMILY => '家庭医生'
  20. ];
  21. const ON_LINE_NO = 0;
  22. const ON_LINE_YES = 1;
  23. const DOCTOR_ON_LINE = [
  24. self::ON_LINE_NO => '不支持',
  25. self::ON_LINE_YES => '支持线上'
  26. ];
  27. const STATUS_WORK = 1;
  28. const STATUS_REST = 0;
  29. const DOCTOR_STATUS = [
  30. self::STATUS_REST => '休班',
  31. self::STATUS_WORK => '上班'
  32. ];
  33. const DEL_NO = 0;
  34. const DEL_YES = 1;
  35. const DOCTOR_DEL = [
  36. self::DEL_NO => '未删除',
  37. self::DEL_YES => '已删除'
  38. ];
  39. /**
  40. * The table associated with the model.
  41. *
  42. * @var string
  43. */
  44. protected $table = 'medical_care_doctor';
  45. protected $dateFormat = 'U';//操作数据库时间格式 时间戳
  46. /**
  47. * Notes:模型关联 科目
  48. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  49. * User: yym
  50. * Date: 2022/9/26
  51. */
  52. public function subject()
  53. {
  54. return $this->hasOne(MedicalCareSubject::class, 'subject_id', 'doctor_subject_id')->where(['subject_del' => MedicalCareSubject::DEL_NO]);
  55. }
  56. public function merchant_shop()
  57. {
  58. return $this->hasOne(MerchantShop::class, 'shop_id', 'doctor_shop_id')->where(['shop_del' => MerchantShop::DEL_NO]);
  59. }
  60. /**
  61. * Notes:获取医生列表
  62. * @param string $keywords
  63. * @param int $page
  64. * @param int $limit
  65. * @return array
  66. * User: QJF
  67. * Date: 2022/9/21
  68. */
  69. public static function getDoctorList(int $page, int $limit, $keywords)
  70. {
  71. $list = static::select('*')
  72. ->where(['doctor_del' => static::DEL_NO])
  73. ->when($keywords != '', function ($query) use ($keywords){
  74. $query->where('doctor_name', 'like', '%' . $keywords . '%')
  75. ->orWhere('doctor_mobile', 'like', '%' . $keywords . '%');
  76. })
  77. ->with(
  78. [
  79. 'subject' => function($query){
  80. $query->select('subject_id', 'subject_name');
  81. },
  82. 'merchant_shop' => function($query){
  83. $query->select('shop_id', 'shop_name', 'shop_logo');
  84. }
  85. ]
  86. )
  87. ->orderBy('doctor_create_time','DESC')
  88. ->forPage($page, $limit)
  89. ->get();
  90. $count = static::count();
  91. return [$list, $count];
  92. }
  93. /**
  94. * Notes:检测医生是否存在
  95. * @param $doctor_name
  96. * @param $doctor_mobile
  97. * @return bool
  98. * User: yym
  99. * Date: 2022/9/26
  100. * 验证条件:医生姓名+手机号同时存在的情况下
  101. */
  102. public static function checkDoctorName($doctor_name, $doctor_mobile)
  103. {
  104. return static::where(['doctor_name' => $doctor_name, 'doctor_mobile' => $doctor_mobile, 'doctor_del' => static::DEL_NO])->exists();
  105. }
  106. /**
  107. * Notes:检测不同账号姓名存在
  108. * @param $doctor_name
  109. * @param $doctor_mobile
  110. * @param $doctor_id
  111. * @return bool
  112. * User: yym
  113. * Date: 2022/9/26
  114. */
  115. public static function checkDoctorCount($doctor_name, $doctor_mobile, $doctor_id)
  116. {
  117. return static::where(['doctor_name' => $doctor_name, 'doctor_mobile' => $doctor_mobile, 'doctor_del' => static::DEL_NO])->where('doctor_id', '!=', $doctor_id)->exists();
  118. }
  119. /**
  120. * Notes:获取医生详情
  121. * @param int $doctor_id
  122. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  123. * User: yym
  124. * Date: 2022/9/26
  125. */
  126. public static function getDoctorInfo(int $doctor_id)
  127. {
  128. return static::where(['doctor_id' => $doctor_id])
  129. ->with(
  130. [
  131. 'subject' => function($query){
  132. $query->select('subject_id', 'subject_name');
  133. },
  134. 'merchant_shop' => function($query){
  135. $query->select('shop_id', 'shop_name', 'shop_logo');
  136. }
  137. ]
  138. )
  139. ->first();
  140. }
  141. /**
  142. * Notes:更新医生数据
  143. * @param int $doctor_id
  144. * @param array $update
  145. * @return false|int
  146. * User: yym
  147. * Date: 2022/9/26
  148. */
  149. public static function updateDoctor(int $doctor_id, array $update)
  150. {
  151. if(empty($doctor_id) || empty($update))
  152. {
  153. return false;
  154. }
  155. return static::where(['doctor_id' => $doctor_id])->update($update);
  156. }
  157. }