feat : coupon

This commit is contained in:
2025-03-28 13:54:16 +08:00
parent 297b3363ad
commit b398364727
2 changed files with 25 additions and 5 deletions

View File

@@ -39,11 +39,12 @@ class CouponCode
CONST INT DISPENSE_CLAIM_RULE_SINGLE_PAGE = 3;
/**
* @var int 优惠券状态 1 未使用 2 已使用 3 过期
* @var int 优惠券状态 1 未使用 2 已使用 3 过期 99 可使用
*/
CONST INT COUPON_STATUS_UNUSED = 1;
CONST INT COUPON_STATUS_USED = 2;
CONST INT COUPON_STATUS_EXPIRE = 3;
const int COUPON_STATUS_CAN_USED = 99;
/**
* @var int 优惠券发放状态 1 未领取 2 已领取

View File

@@ -37,13 +37,32 @@ class CouponListService extends BaseService
{
$limit = (int)$this->request->input('limit',20);
$searchStatus = (int)$this->request->input('searchStatus',CouponCode::COUPON_STATUS_UNUSED);
$data = $this->couponTemplateModel
->join('user_coupon', function ($join) {
->join('user_coupon', function ($join) use ($searchStatus) {
$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'))
->when($searchStatus, function ($query, $searchStatus) {
$query->where('user_coupon.status','=',$searchStatus);
switch ($searchStatus) {
case CouponCode::COUPON_STATUS_UNUSED:
$query->where('user_coupon.validity_end_time', '>=', date('Y-m-d H:i:s'));
break;
case CouponCode::COUPON_STATUS_EXPIRE:
$query->where('user_coupon.validity_end_time', '<', date('Y-m-d H:i:s'));
break;
case CouponCode::COUPON_STATUS_CAN_USED:
$query->where('user_coupon.validity_start_time', '<=', date('Y-m-d H:i:s'));
break;
case CouponCode::COUPON_STATUS_USED:
default:
break;
}
})
// ->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',