feat : banner
This commit is contained in:
12
app/Constants/Common/BannerCode.php
Normal file
12
app/Constants/Common/BannerCode.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Constants\Common;
|
||||
|
||||
class BannerCode
|
||||
{
|
||||
/**
|
||||
* @var int 1=显示 2=隐藏
|
||||
*/
|
||||
CONST INT DISPLAYED = 1;
|
||||
CONST INT HIDDEN = 2;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class SystemController extends AbstractController
|
||||
#[RequestMapping(path: 'index',methods: 'GET')]
|
||||
#[Scene(scene: 'index')]
|
||||
#[Middleware(JwtAuthMiddleware::class)]
|
||||
public function index()
|
||||
public function index(): array
|
||||
{
|
||||
return (new IndexService)->handle();
|
||||
}
|
||||
|
||||
@@ -111,6 +111,6 @@ class OptionalListService extends BaseService
|
||||
$res[$item['category_id']]['spu_list'][] = $item;
|
||||
}
|
||||
|
||||
return $res;
|
||||
return array_values($res);
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,82 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api;
|
||||
|
||||
use App\Constants\Common\BannerCode;
|
||||
use App\Constants\Common\CouponCode;
|
||||
use App\Model\Banner;
|
||||
use App\Model\UserCoupon;
|
||||
use App\Service\ServiceTrait\Api\GetUserInfoTrait;
|
||||
use App\Service\ServiceTrait\Common\OssTrait;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class IndexService extends BaseService
|
||||
{
|
||||
public function handle()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user