feat : mypage
This commit is contained in:
@@ -10,6 +10,7 @@ use App\Request\Api\UserRequest;
|
|||||||
use App\Service\Api\Login\LogOutService;
|
use App\Service\Api\Login\LogOutService;
|
||||||
use App\Service\Api\User\BindPhoneByWxService;
|
use App\Service\Api\User\BindPhoneByWxService;
|
||||||
use App\Service\Api\User\InviteListService;
|
use App\Service\Api\User\InviteListService;
|
||||||
|
use App\Service\Api\User\MyPageService;
|
||||||
use App\Service\Api\User\SiteService;
|
use App\Service\Api\User\SiteService;
|
||||||
use App\Service\Api\User\UnBindPhoneService;
|
use App\Service\Api\User\UnBindPhoneService;
|
||||||
use Hyperf\HttpServer\Annotation\Controller;
|
use Hyperf\HttpServer\Annotation\Controller;
|
||||||
@@ -103,4 +104,14 @@ class UserController extends AbstractController
|
|||||||
{
|
{
|
||||||
return (new LogOutService)->handle();
|
return (new LogOutService)->handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: 'myPage',methods: 'GET')]
|
||||||
|
#[Scene(scene: 'myPage')]
|
||||||
|
public function myPage()
|
||||||
|
{
|
||||||
|
return (new MyPageService)->handle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,4 +96,25 @@ class StringUtil
|
|||||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
69
app/Service/Api/User/MyPageService.php
Normal file
69
app/Service/Api/User/MyPageService.php
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This service file is part of item.
|
||||||
|
*
|
||||||
|
* @author ctexthuang
|
||||||
|
* @contact ctexthuang@qq.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service\Api\User;
|
||||||
|
|
||||||
|
use App\Constants\Common\CouponCode;
|
||||||
|
use App\Extend\StringUtil;
|
||||||
|
use App\Model\AdminUser;
|
||||||
|
use App\Model\UserCoupon;
|
||||||
|
use App\Service\Api\BaseService;
|
||||||
|
use App\Service\ServiceTrait\Api\GetUserInfoTrait;
|
||||||
|
use App\Service\ServiceTrait\Common\OssTrait;
|
||||||
|
use Hyperf\Di\Annotation\Inject;
|
||||||
|
|
||||||
|
class MyPageService extends BaseService
|
||||||
|
{
|
||||||
|
use GetUserInfoTrait;
|
||||||
|
use OssTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var AdminUser
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected AdminUser $adminUserModel;
|
||||||
|
|
||||||
|
|
||||||
|
public function handle(): array
|
||||||
|
{
|
||||||
|
$userInfo = $this->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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user