[], ]; } public function queryWhere() { // 指定用户 $propertyHeadId = (int)PropertyHead::where('user_id',$this->userId)->value('id'); $where[] = ['property_head_id', '=', $propertyHeadId]; $where[] = ['status','=',1]; if (isset($this->params['start_time']) && !empty($this->params['start_time'])) { $monthStart = strtotime(date("Y-m-01",strtotime($this->params['start_time']))); $monthEnd = strtotime(date("Y-m-t 23:59:59",strtotime($this->params['start_time']))); $where[] = function($query) use ($monthStart, $monthEnd) { $query->where('start_time', 'between', [$monthStart, $monthEnd]) ->whereOr('end_time', 'between', [$monthStart, $monthEnd]); }; } return $where; } /** * @notes 获取列表 * @return array */ public function lists(): array { $lists = GroupActivityCategory::where($this->queryWhere()) ->field('id,title,start_time,end_time,participant_num') ->limit($this->limitOffset, $this->limitLength) ->order('start_time', 'desc') ->select() ->toArray(); foreach($lists as &$item) { $item['start_time'] = date('Y-m-d', strtotime($item['start_time'])); $item['end_time'] = date('m-d', $item['end_time']); } return $lists; } /** * @notes 获取数量 * @return int */ public function count(): int { return GroupActivityCategory::where($this->queryWhere())->count(); } }