123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- namespace app\admin\model;
- use support\Db;
- use support\Model;
- /**
- * 医疗服务-预约服务业务员模型
- * Class Users
- * @package app\admin\model
- */
- class MedicalCareSubject extends Model
- {
- const STATUS_DEL_NO = '0';
- const STATUS_DEL_YES = '1';
- const STATUS_DEL = [
- self::STATUS_DEL_NO => '正常',
- self::STATUS_DEL_YES => '删除'
- ];
- 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_subject';
- public $timestamps = false;
- /**
- * Notes:子集关联
- * @return \Illuminate\Database\Eloquent\Relations\HasMany
- * User: yym
- * Date: 2022/10/26
- */
- public function children()
- {
- return $this->hasMany(MedicalCareSubject::class, 'subject_pid', 'subject_id');
- }
- /**
- * Notes:获取菜单列表
- * @param string $keywords
- * @param int $page
- * @param int $limit
- * @return array
- * User: ZQ
- * Date: 2022/9/14
- */
- public static function getSubjectList(int $page, int $limit, string $keywords)
- {
- // if (!empty($keywords)){
- // $list = static::select('*')->where(['subject_del'=>static::STATUS_DEL_NO])
- // ->when($keywords != '', function ($query) use ($keywords){
- // $query->where('subject_name', 'like', '%' . $keywords . '%');
- // })
- // ->forPage($page,$limit)
- // ->orderBy('subject_sort','DESC')
- // ->orderBy('subject_create_time','DESC')
- // ->get()
- // ->toArray();
- // $count = static::where(['subject_del'=>static::STATUS_DEL_NO])
- // ->when($keywords != '', function ($query) use ($keywords){
- // $query->where('subject_name', 'like', '%' . $keywords . '%');
- // })
- // ->count();
- // }else{
- $list = static::select('*')->where(['subject_del'=>static::STATUS_DEL_NO,'subject_pid'=>0])
- ->when($keywords != '', function ($query) use ($keywords){
- $query->where('subject_name', 'like', '%' . $keywords . '%');
- })
- ->with(['children'=>
- function ($query) {
- $query->where(['subject_del'=>static::STATUS_DEL_NO]);
- }
- ])
- ->forPage($page,$limit)
- ->orderBy('subject_sort','DESC')
- ->orderBy('subject_create_time','DESC')
- ->get()
- ->toArray();
- $count = static::where(['subject_del'=>static::STATUS_DEL_NO,'subject_pid'=>0])
- ->when($keywords != '', function ($query) use ($keywords){
- $query->where('subject_name', 'like', '%' . $keywords . '%');
- })
- ->count();
- // }
- return [$list,$count];
- }
- /**
- * Notes:获取菜单列表
- * @param string $keywords
- * @param int $page
- * @param int $limit
- * @return array
- * User: ZQ
- * Date: 2022/9/14
- */
- public static function getChildrenList($pid)
- {
- $list = static::select('*')->where(['subject_del'=>static::STATUS_DEL_NO])
- ->whereIn('subject_pid',$pid)
- ->orderBy('subject_sort','DESC')
- ->orderBy('subject_create_time','DESC')
- ->get()
- ->toArray();
- return $list;
- }
- /**
- * Notes:查询指定条件下的某个字段内容
- * @param int $subject_id
- * @param string $field
- * User: ZQ
- * Date: 2022/9/27
- */
- public static function getValue(int $subject_id, string $field)
- {
- return static::where(['subject_id' => $subject_id])->value($field);
- }
- /**
- * Notes:获取列表
- * @return array
- * User: yym
- * Date: 2022/10/26
- */
- public static function getDoctorSubjectList()
- {
- return static::where(['subject_del' => static::DEL_NO, 'subject_pid' => 0])
- ->with(['children'=>
- function ($query) {
- $query->where(['subject_del'=>static::STATUS_DEL_NO]);
- }
- ])
- ->get()
- ->toArray();
- }
- }
|