MedicalCareSubject.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace app\admin\model;
  3. use support\Db;
  4. use support\Model;
  5. /**
  6. * 医疗服务-预约服务业务员模型
  7. * Class Users
  8. * @package app\admin\model
  9. */
  10. class MedicalCareSubject extends Model
  11. {
  12. const STATUS_DEL_NO = '0';
  13. const STATUS_DEL_YES = '1';
  14. const STATUS_DEL = [
  15. self::STATUS_DEL_NO => '正常',
  16. self::STATUS_DEL_YES => '删除'
  17. ];
  18. const DEL_NO = 0;
  19. const DEL_YES = 1;
  20. const DOCTOR_DEL = [
  21. self::DEL_NO => '未删除',
  22. self::DEL_YES => '已删除'
  23. ];
  24. /**
  25. * The table associated with the model.
  26. *
  27. * @var string
  28. */
  29. protected $table = 'medical_care_subject';
  30. public $timestamps = false;
  31. /**
  32. * Notes:子集关联
  33. * @return \Illuminate\Database\Eloquent\Relations\HasMany
  34. * User: yym
  35. * Date: 2022/10/26
  36. */
  37. public function children()
  38. {
  39. return $this->hasMany(MedicalCareSubject::class, 'subject_pid', 'subject_id');
  40. }
  41. /**
  42. * Notes:获取菜单列表
  43. * @param string $keywords
  44. * @param int $page
  45. * @param int $limit
  46. * @return array
  47. * User: ZQ
  48. * Date: 2022/9/14
  49. */
  50. public static function getSubjectList(int $page, int $limit, string $keywords)
  51. {
  52. // if (!empty($keywords)){
  53. // $list = static::select('*')->where(['subject_del'=>static::STATUS_DEL_NO])
  54. // ->when($keywords != '', function ($query) use ($keywords){
  55. // $query->where('subject_name', 'like', '%' . $keywords . '%');
  56. // })
  57. // ->forPage($page,$limit)
  58. // ->orderBy('subject_sort','DESC')
  59. // ->orderBy('subject_create_time','DESC')
  60. // ->get()
  61. // ->toArray();
  62. // $count = static::where(['subject_del'=>static::STATUS_DEL_NO])
  63. // ->when($keywords != '', function ($query) use ($keywords){
  64. // $query->where('subject_name', 'like', '%' . $keywords . '%');
  65. // })
  66. // ->count();
  67. // }else{
  68. $list = static::select('*')->where(['subject_del'=>static::STATUS_DEL_NO,'subject_pid'=>0])
  69. ->when($keywords != '', function ($query) use ($keywords){
  70. $query->where('subject_name', 'like', '%' . $keywords . '%');
  71. })
  72. ->with(['children'=>
  73. function ($query) {
  74. $query->where(['subject_del'=>static::STATUS_DEL_NO]);
  75. }
  76. ])
  77. ->forPage($page,$limit)
  78. ->orderBy('subject_sort','DESC')
  79. ->orderBy('subject_create_time','DESC')
  80. ->get()
  81. ->toArray();
  82. $count = static::where(['subject_del'=>static::STATUS_DEL_NO,'subject_pid'=>0])
  83. ->when($keywords != '', function ($query) use ($keywords){
  84. $query->where('subject_name', 'like', '%' . $keywords . '%');
  85. })
  86. ->count();
  87. // }
  88. return [$list,$count];
  89. }
  90. /**
  91. * Notes:获取菜单列表
  92. * @param string $keywords
  93. * @param int $page
  94. * @param int $limit
  95. * @return array
  96. * User: ZQ
  97. * Date: 2022/9/14
  98. */
  99. public static function getChildrenList($pid)
  100. {
  101. $list = static::select('*')->where(['subject_del'=>static::STATUS_DEL_NO])
  102. ->whereIn('subject_pid',$pid)
  103. ->orderBy('subject_sort','DESC')
  104. ->orderBy('subject_create_time','DESC')
  105. ->get()
  106. ->toArray();
  107. return $list;
  108. }
  109. /**
  110. * Notes:查询指定条件下的某个字段内容
  111. * @param int $subject_id
  112. * @param string $field
  113. * User: ZQ
  114. * Date: 2022/9/27
  115. */
  116. public static function getValue(int $subject_id, string $field)
  117. {
  118. return static::where(['subject_id' => $subject_id])->value($field);
  119. }
  120. /**
  121. * Notes:获取列表
  122. * @return array
  123. * User: yym
  124. * Date: 2022/10/26
  125. */
  126. public static function getDoctorSubjectList()
  127. {
  128. return static::where(['subject_del' => static::DEL_NO, 'subject_pid' => 0])
  129. ->with(['children'=>
  130. function ($query) {
  131. $query->where(['subject_del'=>static::STATUS_DEL_NO]);
  132. }
  133. ])
  134. ->get()
  135. ->toArray();
  136. }
  137. }