feat : mypage
This commit is contained in:
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