fix(coupon): add expiration check and error handling for expired coupons
This commit is contained in:
parent
8b48286365
commit
1b76794251
@ -83,6 +83,12 @@ func (l *PurchaseLogic) Purchase(req *types.PortalPurchaseRequest) (resp *types.
|
|||||||
if couponInfo.Count != 0 && couponInfo.Count <= couponInfo.UsedCount {
|
if couponInfo.Count != 0 && couponInfo.Count <= couponInfo.UsedCount {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.CouponInsufficientUsage), "coupon used")
|
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)
|
couponSub := tool.StringToInt64Slice(couponInfo.Subscribe)
|
||||||
if len(couponSub) > 0 && !tool.Contains(couponSub, req.SubscribeId) {
|
if len(couponSub) > 0 && !tool.Contains(couponSub, req.SubscribeId) {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.CouponNotApplicable), "coupon not match")
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.CouponNotApplicable), "coupon not match")
|
||||||
|
|||||||
@ -57,6 +57,7 @@ const (
|
|||||||
CouponAlreadyUsed uint32 = 50002 // Coupon has already been used
|
CouponAlreadyUsed uint32 = 50002 // Coupon has already been used
|
||||||
CouponNotApplicable uint32 = 50003 // Coupon does not match the order or conditions
|
CouponNotApplicable uint32 = 50003 // Coupon does not match the order or conditions
|
||||||
CouponInsufficientUsage uint32 = 50004 // Coupon has insufficient remaining uses
|
CouponInsufficientUsage uint32 = 50004 // Coupon has insufficient remaining uses
|
||||||
|
CouponExpired uint32 = 50005 // Coupon is expired
|
||||||
)
|
)
|
||||||
|
|
||||||
// Subscribe
|
// Subscribe
|
||||||
|
|||||||
@ -46,6 +46,7 @@ func init() {
|
|||||||
CouponAlreadyUsed: "Coupon has already been used",
|
CouponAlreadyUsed: "Coupon has already been used",
|
||||||
CouponNotApplicable: "Coupon does not match the order or conditions",
|
CouponNotApplicable: "Coupon does not match the order or conditions",
|
||||||
CouponInsufficientUsage: "Coupon has insufficient remaining uses",
|
CouponInsufficientUsage: "Coupon has insufficient remaining uses",
|
||||||
|
CouponExpired: "Coupon is expired",
|
||||||
|
|
||||||
// Subscribe
|
// Subscribe
|
||||||
SubscribeExpired: "Subscribe is expired",
|
SubscribeExpired: "Subscribe is expired",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user