From 1b76794251981ada82dd0a06fcb644c32c36a319 Mon Sep 17 00:00:00 2001 From: Chang lue Tsen Date: Thu, 16 Oct 2025 09:31:33 -0400 Subject: [PATCH] fix(coupon): add expiration check and error handling for expired coupons --- internal/logic/public/portal/purchaseLogic.go | 6 ++++++ pkg/xerr/errCode.go | 1 + pkg/xerr/errMsg.go | 1 + 3 files changed, 8 insertions(+) diff --git a/internal/logic/public/portal/purchaseLogic.go b/internal/logic/public/portal/purchaseLogic.go index 2c0cd69..322f94c 100644 --- a/internal/logic/public/portal/purchaseLogic.go +++ b/internal/logic/public/portal/purchaseLogic.go @@ -83,6 +83,12 @@ func (l *PurchaseLogic) Purchase(req *types.PortalPurchaseRequest) (resp *types. if couponInfo.Count != 0 && couponInfo.Count <= couponInfo.UsedCount { return nil, errors.Wrapf(xerr.NewErrCode(xerr.CouponInsufficientUsage), "coupon used") } + // Check expiration time + expireTime := time.Unix(couponInfo.ExpireTime, 0) + if time.Now().After(expireTime) { + return nil, errors.Wrapf(xerr.NewErrCode(xerr.CouponExpired), "coupon expired") + } + couponSub := tool.StringToInt64Slice(couponInfo.Subscribe) if len(couponSub) > 0 && !tool.Contains(couponSub, req.SubscribeId) { return nil, errors.Wrapf(xerr.NewErrCode(xerr.CouponNotApplicable), "coupon not match") diff --git a/pkg/xerr/errCode.go b/pkg/xerr/errCode.go index b708ac4..c9377c4 100644 --- a/pkg/xerr/errCode.go +++ b/pkg/xerr/errCode.go @@ -57,6 +57,7 @@ const ( CouponAlreadyUsed uint32 = 50002 // Coupon has already been used CouponNotApplicable uint32 = 50003 // Coupon does not match the order or conditions CouponInsufficientUsage uint32 = 50004 // Coupon has insufficient remaining uses + CouponExpired uint32 = 50005 // Coupon is expired ) // Subscribe diff --git a/pkg/xerr/errMsg.go b/pkg/xerr/errMsg.go index f4f73a3..f688854 100644 --- a/pkg/xerr/errMsg.go +++ b/pkg/xerr/errMsg.go @@ -46,6 +46,7 @@ func init() { CouponAlreadyUsed: "Coupon has already been used", CouponNotApplicable: "Coupon does not match the order or conditions", CouponInsufficientUsage: "Coupon has insufficient remaining uses", + CouponExpired: "Coupon is expired", // Subscribe SubscribeExpired: "Subscribe is expired",