['name','mobile'], '=' => ['type'] ]; } /** * @notes 自定查询条件 * @return array * @author 段誉 * @date 2022/10/25 16:53 */ public function queryWhere() { $where[] = ['status', '=', 1]; $where[] = ['expiration_time', '>=', time()]; if (!empty($this->params['cate_id'])) { $where[] = ['cate_id', 'like', '%' . ',' .$this->params['cate_id'].',' . '%']; } if (!empty($this->params['area_id'])) { $where[] = ['area_id', 'like', '%' . ',' .$this->params['area_id'].',' . '%']; } return $where; } /** * @notes 获取服务商列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author 段誉 * @date 2022/9/16 18:55 */ public function lists(): array { $orderRaw = 'expiration_time desc'; $field = 'id,user_id,name,mobile,type,agricultural_machinery_model,images,cate_id,area_id,money,content,status,expiration_time,create_time'; $result = UserService::field($field) ->where($this->queryWhere()) ->where($this->searchWhere) ->orderRaw($orderRaw) ->append(['type_desc','cate_desc','area_desc','images','user']) ->limit($this->limitOffset, $this->limitLength) ->select()->toArray(); // $articleIds = array_column($result, 'id'); // // $collectIds = ArticleCollect::where(['user_id' => $this->userId, 'status' => YesNoEnum::YES]) // ->whereIn('article_id', $articleIds) // ->column('article_id'); // foreach ($result as &$item) { // $item['collect'] = in_array($item['id'], $collectIds); // } return $result; } /** * @notes 获取服务商数量 * @return int * @author 段誉 * @date 2022/9/16 18:55 */ public function count(): int { return UserService::where($this->searchWhere) ->where($this->queryWhere()) ->count(); } }