params['id'] ?? 0; switch ($id){ case 1: $coachOrderId = GoodsComment::alias('GC') ->where(['GC.coach_id'=>$this->coachId]) ->join('goods_comment_image GCI','GC.id = GCI.comment_id') ->column('GC.id') ?: []; $where[] = ['id','in',$coachOrderId]; break; case 2: $where[] = ['service_comment','>',3]; break; case 3: $where[] = ['service_comment','<=',3]; break; } return $where; } public function lists(): array { $lists = GoodsComment::where(['coach_id'=>$this->coachId]) ->where($this->setWhere()) ->with(['goods_comment_image']) ->field('id,user_id,service_comment,comment,reply,create_time') ->limit($this->limitOffset, $this->limitLength) ->order('id desc') ->select()->toArray(); $userIds = array_column($lists,'user_id'); $userLists = []; if($userIds){ $userLists = User::where(['id'=>$userIds])->field('id,nickname,avatar')->select()->toArray(); $userLists = array_column($userLists,null,'id'); } foreach ($lists as $key => $goodsComment){ $lists[$key]['nickname'] = $userLists[$goodsComment['user_id']]['nickname']; $lists[$key]['avatar'] = $userLists[$goodsComment['user_id']]['avatar']; } return $lists; } public function count(): int { return GoodsComment::where(['coach_id'=>$this->coachId]) ->where($this->setWhere()) ->count(); } }