getUserInfo($this->userId); $avatar = $this->getOssObjectById($userInfo->avatar_id); $res = [ 'banner' => $this->getBanner(), 'nickname' => $userInfo->nickname, 'avatar' => $avatar, 'point' => 0, 'coupon_num' => $this->getCouponNum() ]; return $this->return->success('success',$res); } /** * @return int */ private function getCouponNum(): int { return $this->userCouponModel ->where('user_id',$this->userId) ->where('status',CouponCode::COUPON_STATUS_UNUSED) ->where('validity_end_time','<',date('Y-m-d H:i:s')) ->count() ?? 0; } /** * @var Banner */ #[Inject] protected Banner $bannerModel; /** * @var UserCoupon */ #[Inject] private UserCoupon $userCouponModel; /** * @return array */ private function getBanner(): array { $res = $this->bannerModel ->where('city_id',$this->request->input('city_id')) ->where('status',BannerCode::DISPLAYED) ->orderBy('sort') ->get(); if ($res->isEmpty()) return []; $res = $res->toArray(); $imageList = $this->getOssObjects(array_column($res, 'image_id')); foreach ($res as &$v) { $v['url'] = $imageList[$v['image_id']]['url'] ?? ''; } return $res; } }