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