public function run() { if (false == $this->verifyUserAuth()) { return false; } $page = $this->getDataItem('page', 1); $limit = 10; $offset = ($page - 1) * $limit; $userId = $this->getUserAuth()->userId; if ($userId == '') { return $this->errorLog(ResultStatus::URL_PARAM_CANNOT_EMPTY, '参数异常'); } //$userId=1; $my_favorites = BpFavorites::query()->where("user_id = {$userId}")->limit($limit, $offset)->execute()->toArray(); foreach ($my_favorites as $fav) { $bp_list[] = BeautyParlor::findFirst(["bp_id = " . $fav['bp_id'], "columns" => ['bp_id as id', 'bp_name as name', 'bp_cover as cover', 'bp_address as address']])->toArray(); } foreach ($bp_list as $k => $v) { $bp_list[$k]['cover'] = "http://img.meelier.com/" . $bp_list[$k]['cover']; $tagarr = BeautyParlorTag::query()->columns('i.tag_title')->leftJoin('Apps\\Common\\Models\\BeautyParlorTagInfo', 'Apps\\Common\\Models\\BeautyParlorTag.tag_id = i.tag_id', 'i')->where("Apps\\Common\\Models\\BeautyParlorTag.bp_id = " . $bp_list[$k]['id'])->orderby("Apps\\Common\\Models\\BeautyParlorTag.sort asc")->limit(3, 0)->execute()->toArray(); $newarr = []; foreach ($tagarr as $key => $val) { $newarr[] = $tagarr[$key]['tag_title']; } $bp_list[$k]['tags'] = $newarr; } $this->setResult($bp_list); }
/** * 获取用户关注的美容院列表 * @param $user_id * @param int $offset * @param int $limit * @return mixed */ private function getFavorites($user_id, $offset = 0, $limit = 10) { $list = BpFavorites::query()->columns(['p.bp_id id', 'p.bp_name name', 'p.bp_cover cover', 'p.bp_address address', 'p.bp_tel tel', 'p.bp_medal medal_verify', 'a.low_price', 'a.facilities'])->leftJoin('Apps\\Common\\Models\\BeautyParlor', 'Apps\\Common\\Models\\BpFavorites.bp_id = p.bp_id', 'p')->leftJoin('Apps\\Common\\Models\\BeautyParlorAttr', 'Apps\\Common\\Models\\BpFavorites.bp_id = a.beauty_parlor_id', 'a')->where('p.bp_state = 1 and user_id = ' . $user_id)->limit($limit, $offset)->execute()->toArray(); $BeautyParlorTag = new BeautyParlorTag(); foreach ($list as $k => $val) { $tags = []; if ($tagList = $BeautyParlorTag->getTagList($val['id'])) { foreach ($tagList as $key => $value) { $tags[] = $value['tag_title']; } } else { $tags = []; } $list[$k]['cover'] = PicUrl::BeautyParlorCover($val['cover'], $this->getDi()); $list[$k]['medal_verify'] = BeautyParlor::getMedalVerify($val['medal']); $list[$k]['facilities'] = $val['facilities'] ? json_decode($val['facilities'], true) : []; $list[$k]['tag'] = $tags; } return $list; }