feat: invite num

This commit is contained in:
2025-04-01 10:02:10 +08:00
parent a73c547556
commit 93a33ffba3
4 changed files with 25 additions and 8 deletions

View File

@@ -0,0 +1,92 @@
<?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\BannerCode;
use App\Constants\Common\CouponCode;
use App\Model\Banner;
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 IndexService extends BaseService
{
use OssTrait;
use GetUserInfoTrait;
/**
* @return array
*/
public function handle(): array
{
$userInfo = $this->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;
}
}

View File

@@ -14,6 +14,7 @@ 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;
@@ -44,13 +45,19 @@ class MyPageService extends BaseService
'mobile' => StringUtil::maskMiddleStrByNum($userInfo->mobile,4),
'point' => 0,
'coupon_num' => $this->getCouponNum(),
'invite_num' => 0,
'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
*/
@@ -64,8 +71,19 @@ class MyPageService extends BaseService
}
/**
* @var UserCoupon
* @var UserInvite
*/
#[Inject]
private UserCoupon $userCouponModel;
private UserInvite $userInviteModel;
/**
* @return int
*/
private function getInviteNum(): int
{
return $this->userInviteModel
->where('invitee_user_id',$this->userId)
->count()?? 0;
}
}