89 lines
2.1 KiB
PHP
89 lines
2.1 KiB
PHP
<?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\Model\UserInvite;
|
|
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);
|
|
|
|
$res = [
|
|
'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' => $this->getInviteNum(),
|
|
'role_id' => (!empty($adminInfo) && $adminInfo->role_id > 0) ? $adminInfo->role_id : 0,
|
|
];
|
|
|
|
return $this->return->success('success', $res);
|
|
}
|
|
|
|
/**
|
|
* @var UserCoupon
|
|
*/
|
|
#[Inject]
|
|
private UserCoupon $userCouponModel;
|
|
|
|
/**
|
|
* @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 UserInvite
|
|
*/
|
|
#[Inject]
|
|
private UserInvite $userInviteModel;
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
private function getInviteNum(): int
|
|
{
|
|
return $this->userInviteModel
|
|
->where('invitee_user_id',$this->userId)
|
|
->count()?? 0;
|
|
}
|
|
|
|
} |