['id','category_type', 'work_status', 'service_status', 'master_worker_id', 'work_type','city'], ]; } public function queryWhere(){ $where = []; if (isset($this->params['master_worker_name']) && !empty($this->params['master_worker_name'])) { $master_worker_ids = MasterWorker::where([['worker_number|mobile|real_name', 'like','%' .$this->params['master_worker_name'] . '%']])->column('id')??[0]; $where[] = ['master_worker_id','in' ,$master_worker_ids]; } if(isset($this->params['workid']) && !empty($this->params['workid'])){ $where[] = ['master_worker_id', '=', $this->params['workid']]; } return $where; } public function queryAndWhere(){ $where = []; if (isset($this->params['work_sn']) && !empty($this->params['work_sn'])) { $where[] = ['work_sn','=' ,$this->params['work_sn']]; } if(isset($this->params['mobile']) && !empty($this->params['mobile'])){ $where[] = ['mobile', '=', $this->params['mobile']]; } if(isset($this->params['real_name']) && !empty($this->params['real_name'])){ $where[] = ['real_name', 'like', '%'.$this->params['real_name'].'%']; } return $where; } /** * @notes 获取列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author likeadmin * @date 2024/07/10 15:06 */ public function lists(): array { $params = $this->params; $list = MasterWorker::hasWhere('serviceWork', function($query) use ($params) { $query->where('work_type','in',[0,1]); if (isset($params['work_sn']) && !empty($params['work_sn'])) { $query->where(['work_sn','=',trim($params['work_sn'])]); } if (isset($params['mobile']) && !empty($params['mobile'])) { $query->where('mobile','=',trim($params['mobile'])); } if (isset($params['real_name']) && !empty($params['real_name'])) { $query->where('real_name','like','%'.trim($params['real_name']).'%'); } if (isset($params['appointment_time']) && !empty($params['appointment_time'])) { $query->where('appointment_time','between',[strtotime($params['appointment_time']), strtotime($params['appointment_time'].' 23:59:59')]); } if (!empty($params['dispatch_time']) && is_array($params['dispatch_time'])) { $query->where('dispatch_time','between',[strtotime($params['dispatch_time'][0]), strtotime($params['dispatch_time'][1])]); } if (empty($params['appointment_time']) && empty($params['dispatch_time'])) { $query->where('appointment_time','between',[strtotime(date('Y-m-d')), strtotime(date('Y-m-d 23:59:59'))]); } })->with(['serviceWork' => function($query) use($params) { $query->where('work_type','in',[0,1]); if (isset($params['work_sn']) && !empty($params['work_sn'])) { $query->where(['work_sn','=',trim($params['work_sn'])]); } if (isset($params['mobile']) && !empty($params['mobile'])) { $query->where('mobile','=',trim($params['mobile'])); } if (isset($params['real_name']) && !empty($params['real_name'])) { $query->where('real_name','like','%'.trim($params['real_name']).'%'); } if (isset($params['appointment_time']) && !empty($params['appointment_time'])) { $query->where('appointment_time','between',[strtotime($params['appointment_time']), strtotime($params['appointment_time'].' 23:59:59')]); } if (!empty($params['dispatch_time']) && is_array($params['dispatch_time'])) { $query->where('dispatch_time','between',[strtotime($params['dispatch_time'][0]), strtotime($params['dispatch_time'][1])]); } if (empty($params['appointment_time']) && empty($params['dispatch_time'])) { $query->where('appointment_time','between',[strtotime(date('Y-m-d')), strtotime(date('Y-m-d 23:59:59'))]); } }]) ->where($this->searchWhere) ->where($this->queryWhere()) ->limit($this->limitOffset, $this->limitLength) ->select() ->toArray(); foreach($list as &$item) { $item = [ 'id' => $item['id'], 'worker_number' => $item['worker_number'], 'real_name' => $item['real_name'], 'category_ids' => empty($item['category_ids']) ? [] : explode(",",$item['category_ids']), 'serviceWork' => $item['serviceWork'], ]; } return $list; } /** * @notes 获取数量 * @return int * @author likeadmin * @date 2024/07/10 15:06 */ public function count(): int { $params = $this->params; return MasterWorker::hasWhere('serviceWork', function($query) use ($params) { $query->where('work_type','in',[0,1]); if (isset($params['work_sn']) && !empty($params['work_sn'])) { $query->where('work_sn','=',trim($params['work_sn'])); } if (isset($params['mobile']) && !empty($params['mobile'])) { $query->where('mobile','=',trim($params['mobile'])); } if (isset($params['real_name']) && !empty($params['real_name'])) { $query->where('real_name','like','%'.trim($params['real_name']).'%'); } })->with('serviceWork') ->where($this->searchWhere) ->where($this->queryWhere()) ->count(); } }