diff --git a/app/Controller/Api/UserController.php b/app/Controller/Api/UserController.php index 95e2718..c8f6537 100644 --- a/app/Controller/Api/UserController.php +++ b/app/Controller/Api/UserController.php @@ -10,6 +10,7 @@ use App\Request\Api\UserRequest; use App\Service\Api\Login\LogOutService; use App\Service\Api\User\BindPhoneByWxService; use App\Service\Api\User\InviteListService; +use App\Service\Api\User\MyPageService; use App\Service\Api\User\SiteService; use App\Service\Api\User\UnBindPhoneService; use Hyperf\HttpServer\Annotation\Controller; @@ -103,4 +104,14 @@ class UserController extends AbstractController { return (new LogOutService)->handle(); } + + /** + * @return array + */ + #[RequestMapping(path: 'myPage',methods: 'GET')] + #[Scene(scene: 'myPage')] + public function myPage() + { + return (new MyPageService)->handle(); + } } diff --git a/app/Extend/StringUtil.php b/app/Extend/StringUtil.php index b20a925..b768198 100644 --- a/app/Extend/StringUtil.php +++ b/app/Extend/StringUtil.php @@ -96,4 +96,25 @@ class StringUtil mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) ); } + + /** + * @param $str + * @param int $num + * @return string + */ + public static function maskMiddleStrByNum($str,int $num) { + $len = strlen($str); + + if ($len <= $num) { + return str_repeat('*', $num); + } + + $left_len = floor(($len - $num) / 2); + $right_len = ($len - $num) - $left_len; + + $left = substr($str, 0, $left_len); + $right = substr($str, -$right_len); + + return $left . '****' . $right; + } } \ No newline at end of file diff --git a/app/Service/Api/User/MyPageService.php b/app/Service/Api/User/MyPageService.php new file mode 100644 index 0000000..7157114 --- /dev/null +++ b/app/Service/Api/User/MyPageService.php @@ -0,0 +1,69 @@ +getUserInfo($this->userId); + + $adminInfo = $this->adminUserModel->getAdminInfoByBindUserId($this->userId); + + return [ + 'id' => $this->userId, + 'nickname' => $userInfo->nickname, + 'avatar' => $this->getOssObjectById($userInfo->avatar_id) ?? '', + 'mobile' => StringUtil::maskMiddleStrByNum($userInfo->mobile,4), + 'point' => 0, + 'coupon_num' => $this->getCouponNum(), + 'invite_num' => 0, + 'role_id' => (!empty($adminInfo) && $adminInfo->role_id > 0) ? $adminInfo->role_id : 0, + ]; + } + + /** + * @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 UserCoupon + */ + #[Inject] + private UserCoupon $userCouponModel; +} \ No newline at end of file