‘linchangsheng’ 1 month ago
parent
commit
ffb509f401
1 changed files with 12 additions and 6 deletions
  1. 12 6
      src/main/java/com/gree/mall/miniapp/logic/coupon/CouponLogic.java

+ 12 - 6
src/main/java/com/gree/mall/miniapp/logic/coupon/CouponLogic.java

@@ -640,6 +640,7 @@ public class CouponLogic {
 
     }
 
+    @Transactional(rollbackFor = Exception.class)
     public void getCoupon(HttpServletRequest request, String userId, List<String> couponIds) {
 
         CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request);
@@ -664,19 +665,20 @@ public class CouponLogic {
             Integer leftAmount = coupon.getLeftAmount();
             //已领取数量
             Integer receiveAmount = coupon.getReceiveAmount() == null ? 0 : coupon.getReceiveAmount();
-            if (leftAmount <= 0) {
-                continue;
-            }
-
-
 
             if (!CollectionUtils.isEmpty(couponIds)) {
 
                 Integer count = userCouponService.lambdaQuery()
                         .eq(UserCoupon::getUserId, userId)
                         .eq(UserCoupon::getCouponId, coupon.getCouponId()).count();
+
+                if (leftAmount <= 0) {
+                    throw new RemoteServiceException("该券已被领完");
+                }
+
+
                 if (receiveLimitCount != 0 && count >= receiveLimitCount) {
-                    continue;
+                    throw new RemoteServiceException("该券已被领完");
                 }
 
                 UserCoupon userCoupon = new UserCoupon();
@@ -726,6 +728,10 @@ public class CouponLogic {
 
             }else {
 
+                if (leftAmount <= 0) {
+                    continue;
+                }
+
 
                 //实际领取张数
                 int num = leftAmount - receiveLimitCount < 0 ? 0 : leftAmount - receiveLimitCount;