1], ]; } /** * 学员列表 */ public function search() { if ($this->user_type != User::TYPE_COACH) { return $this->apiReturnError('账号错误'); } $where = ['c.status' => 1, 'c.is_delete' => 0,'c.user_id'=>$this->user_id]; $coachData = Coach::find()->alias('c') ->innerJoin(['s' => Store::tableName()], 'c.store_id=s.id') ->innerJoin(['u' => User::tableName()], 'c.user_id=u.id') ->select('u.id,s.name as store_name,c.coach_photo,u.real_name') ->where($where) ->andWhere([ 'c.is_delete' => 0, 'c.status' => 1 ])->asArray()->one(); if(empty($coachData)){ return $this->apiReturnError('非教练'); } $coachData['coach_photo'] = SiteHelper::getFullUrl($coachData['coach_photo']); $uids = DeviceUniqueBindUser::find()->where(['c_id' => $this->user_id])->select('DISTINCT(uid)')->asArray()->all(); $uidArr = array_column($uids, 'uid'); if (empty($this->limit)) { $this->limit = 10; } if (empty($this->page)) { $this->page = 1; } $query = User::find() ->where(['in', 'id', $uidArr])->andFilterWhere(['OR', ['LIKE', 'real_name', $this->name]])->select('id as user_id,real_name,nickname,avatar_url'); $count_query = clone $query; $count = $count_query->count(); $pagination = new Pagination(['pageSize' => $this->limit, 'totalCount' => $count, 'page' => $this->page - 1]); $list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['id' => SORT_DESC])->asArray()->all(); foreach ($list as $key=>$val){ if(empty($val['real_name'])){ $list[$key]['real_name'] = $val["nickname"]; } $list[$key]['avatar_url'] = SiteHelper::getFullUrl($val['avatar_url']); } $this->pageCount = $pagination->pageCount; $end_flag = $this->page >= $pagination->pageCount ? true : false; $coachData['user_data'] = empty($list) ? [] : $list; return [ 'code' => 0, 'msg' => 'ok', 'data' => $coachData, 'count' => $count, 'page_size' => $this->limit, 'page_count' => $this->pageCount, 'page_no' => $this->page, 'end_flag' => $end_flag ]; } }