feat : coupon
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Controller\Api;
|
||||
|
||||
use App\Controller\AbstractController;
|
||||
use App\Service\Api\Coupon\CouponListService;
|
||||
use App\Service\Api\Coupon\HomePopupsService;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
@@ -13,10 +14,23 @@ use Hyperf\Validation\Annotation\Scene;
|
||||
#[Controller(prefix: 'api/coupon')]
|
||||
class CouponController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "home_popups", methods: "GET")]
|
||||
#[Scene(scene: "home_popups")]
|
||||
public function homePopups()
|
||||
{
|
||||
return (new HomePopupsService)->handle();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "my_coupon", methods: "GET")]
|
||||
#[Scene(scene: "my_coupon")]
|
||||
public function myCoupon()
|
||||
{
|
||||
return (new CouponListService)->handle();
|
||||
}
|
||||
}
|
||||
|
||||
66
app/Service/Api/Coupon/CouponListService.php
Normal file
66
app/Service/Api/Coupon/CouponListService.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\Coupon;
|
||||
|
||||
use App\Constants\Common\CouponCode;
|
||||
use App\Model\CouponTemplate;
|
||||
use App\Model\UserCoupon;
|
||||
use App\Service\Api\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class CouponListService extends BaseService
|
||||
{
|
||||
/**
|
||||
* @var UserCoupon
|
||||
*/
|
||||
#[Inject]
|
||||
protected UserCoupon $userCouponModel;
|
||||
|
||||
/**
|
||||
* @var CouponTemplate
|
||||
*/
|
||||
#[Inject]
|
||||
protected CouponTemplate $couponTemplateModel;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$limit = $this->request->input('limit',20);
|
||||
|
||||
$data = $this->couponTemplateModel
|
||||
->join('user_coupon', function ($join) {
|
||||
$join->on('user_coupon.coupon_template_id', '=', 'coupon_template.id')
|
||||
->where('user_coupon.user_id', '=', $this->userId)
|
||||
->where('user_coupon.status', '=', CouponCode::COUPON_STATUS_UNUSED)
|
||||
->where('validity_start_time', '<=', date('Y-m-d H:i:s'))
|
||||
->where('validity_end_time', '>=', date('Y-m-d H:i:s'))
|
||||
->select([
|
||||
'coupon_template.coupon_type',
|
||||
'coupon_template.amount',
|
||||
'coupon_template.ratio',
|
||||
'user_coupon.id',
|
||||
'user_coupon.coupon_template_id',
|
||||
'user_coupon.coupon_name',
|
||||
'user_coupon.status',
|
||||
'user_coupon.validity_start_time',
|
||||
'user_coupon.validity_end_time',
|
||||
]);
|
||||
})
|
||||
->paginate($limit)
|
||||
->toArray();
|
||||
|
||||
if (empty($data['list'])) return $this->return->success('success',$data);
|
||||
|
||||
return $this->return->success('success',$data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user