From b3983647274a28d0ec6dbf7167499e2ca5dd4de1 Mon Sep 17 00:00:00 2001 From: ctexthuang Date: Fri, 28 Mar 2025 13:54:16 +0800 Subject: [PATCH] feat : coupon --- app/Constants/Common/CouponCode.php | 3 ++- app/Service/Api/Coupon/CouponListService.php | 27 +++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/Constants/Common/CouponCode.php b/app/Constants/Common/CouponCode.php index 66857ef..6fbcd85 100644 --- a/app/Constants/Common/CouponCode.php +++ b/app/Constants/Common/CouponCode.php @@ -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 已领取 diff --git a/app/Service/Api/Coupon/CouponListService.php b/app/Service/Api/Coupon/CouponListService.php index 4bb2ed1..d4c2887 100644 --- a/app/Service/Api/Coupon/CouponListService.php +++ b/app/Service/Api/Coupon/CouponListService.php @@ -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',