params['keyword']) && $this->params['keyword']){ $where[] = ['name|sn','like','%'.$this->params['keyword'].'%']; } else{ $coachInfo = Coach::where(['id'=>$this->coachId])->field('city_id')->findOrEmpty(); $where[] = ['city_id','=',$coachInfo['city_id']]; } return $where; } public function lists(): array { $shopLists = Shop::where($this->setWhere()) ->field('id,logo,sn,name,synopsis,city_id') ->append(['category_ids']) ->limit($this->limitOffset, $this->limitLength) ->select()->toArray(); $coach = Coach::where(['id'=>$this->coachId])->field('shop_id,city_id')->findOrEmpty(); $categoryLists = GoodsCategory::column('name','id'); foreach ($shopLists as $key => $shop){ $shopLists[$key]['category_name'] = ''; $isJoin = false; if(0 == $coach['shop_id'] && $coach['city_id'] == $shop['city_id']){ $isJoin = true; } $shopLists[$key]['is_join'] = $isJoin; $categoryIds = array_column($shop['category_ids']->toArray(),'id'); $categoryNameLists = []; foreach ($categoryIds as $id){ $categoryNameLists[] = $categoryLists[$id] ??''; } $shopLists[$key]['category_name'] = implode(' ',$categoryNameLists); } return $shopLists; } public function count(): int { return Shop::where($this->setWhere()) ->count(); } }