userId]; $type = $this->params['type'] ?? 1; // if(isset($type) && $type){ // } $relationIds = Collect::where(['user_id'=>$this->userId,'type'=>$type]) ->column('relation_id'); $this->where[] = ['id','in',$relationIds]; } public function lists(): array { $this->setWhere(); $lists = []; switch ($this->params['type']){ case 1: $lists = Coach::where($this->where) ->append(['distance_desc']) ->order('distance asc') ->limit($this->limitOffset, $this->limitLength) ->field('id,work_status,shop_id,work_photo,name,round(st_distance_sphere(point('.$this->params['longitude'].','.$this->params['latitude'].'), point(longitude, latitude))/1000,2) as distance,order_num,good_comment') ->select() ->toArray(); $collect = Collect::where(['user_id'=>$this->userId,'type'=>1])->value('relation_id'); $coachIds = array_column($lists,'id'); $collectLists = Collect::where(['type'=>1,'relation_id'=>$coachIds]) ->group('relation_id') ->column('count(id) as num','relation_id'); foreach ($lists as $key => $coach) { $lists[$key]['first_appoint'] = CoachLogic::getLatelyLeisureTime($coach['id']);; $lists[$key]['is_collect'] = $collect ? 1 : 0; $lists[$key]['comment_num'] = GoodsComment::where(['coach_id'=>$coach['id']])->count('id'); $lists[$key]['good_comment'] = $coach['good_comment'].'%'; $lists[$key]['collect_num'] = $collectLists[$coach['id']] ?? 0; } break; case 2: $lists = Goods::field('id,name,image,tags,price,order_num+virtual_order_num as order_num,duration,scribing_price') ->where($this->where) ->limit($this->limitOffset, $this->limitLength) ->select() ->toArray(); break; case 3: $lists = Shop::where($this->where) ->append(['distance_desc','categoryIds']) ->order('distance asc') ->field('id,name,good_comment,logo,round(st_distance_sphere(point('.$this->params['longitude'].','.$this->params['latitude'].'), point(longitude, latitude))/1000,2) as distance,work_status') ->limit($this->limitOffset, $this->limitLength) ->select() ->toArray(); $categoryLists = GoodsCategory::where(['is_show'=>1])->column('name','id'); foreach ($lists as $key => $coach) { $categoryNameLists = []; foreach ($coach['categoryIds'] as $category){ $categoryNameLists[] = $categoryLists[$category['category_id']] ?? ''; } $lists[$key]['consumption'] = '¥56'; $lists[$key]['category_name'] = $categoryNameLists; } break; } return $lists; } public function count(): int { return Coach::where($this->where)->count(); } }