From d09284975427910441eeaf59d34a4d50d2fd5fdc Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期二, 24 十二月 2024 19:02:29 +0800
Subject: [PATCH] 修改bug

---
 UserAHTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/OrderController.java |   65 +++++++++++++++-----------------
 1 files changed, 31 insertions(+), 34 deletions(-)

diff --git a/UserAHTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/OrderController.java b/UserAHTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/OrderController.java
index 7e086e7..d7e56b3 100644
--- a/UserAHTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/OrderController.java
+++ b/UserAHTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/OrderController.java
@@ -1122,44 +1122,41 @@
             // 查询当前活动的限制数量
             UserCouponRecord userCouponRecords1 = userCouponRecordService.selectById(id);
 
-            List<UserCouponRecord> userCouponRecords = userCouponRecordService.selectList(new EntityWrapper<UserCouponRecord>().eq("couponId", userCouponRecords1.getCouponId()));
-
             // 获取活动限制数量
-            TActivityGeneralization tActivityGeneralization = activityGeneralizationService.selectById(userCouponRecords.get(0).getCouponActivityId());
-            if (tActivityGeneralization == null) {
-                throw new RuntimeException("未能找到对应的活动信息");
-            }
-            int limitQuantity = tActivityGeneralization.getMonthUseCount(); // 假设limitQuantity字段代表限制数量
-
-            // 判断当月的优惠券是否超过限制
-            Calendar currentCal = Calendar.getInstance();
-            int currentMonth = currentCal.get(Calendar.MONTH) + 1; // 当前月份
-
-            // 统计当月的优惠券使用数量
-            int usedThisMonth = 0;
-            for (UserCouponRecord record : userCouponRecords) {
-                if (record.getEndTime()==null){
-                    continue;
+            TActivityGeneralization tActivityGeneralization = activityGeneralizationService.selectById(userCouponRecords1.getCouponActivityId());
+            if (null != tActivityGeneralization && tActivityGeneralization.getStartTime().getTime() <= System.currentTimeMillis() && tActivityGeneralization.getEndTime().getTime() > System.currentTimeMillis()) {
+    
+                List<UserCouponRecord> userCouponRecords = userCouponRecordService.selectList(new EntityWrapper<UserCouponRecord>()
+                        .eq("userId", uid).eq("couponId", userCouponRecords1.getCouponId()));
+                int limitQuantity = tActivityGeneralization.getMonthUseCount(); // 假设limitQuantity字段代表限制数量
+    
+                // 判断当月的优惠券是否超过限制
+                Calendar currentCal = Calendar.getInstance();
+                int currentMonth = currentCal.get(Calendar.MONTH) + 1; // 当前月份
+    
+                // 统计当月的优惠券使用数量
+                int usedThisMonth = 0;
+                for (UserCouponRecord record : userCouponRecords) {
+                    if (record.getEndTime()==null){
+                        continue;
+                    }
+                    Calendar recordCal = Calendar.getInstance();
+                    recordCal.setTime(record.getEndTime());
+                    int recordMonth = recordCal.get(Calendar.MONTH) + 1;
+        
+                    // 判断endTime是否在当月
+                    if (recordMonth == currentMonth) {
+                        usedThisMonth++;
+                    }
                 }
-                Calendar recordCal = Calendar.getInstance();
-                recordCal.setTime(record.getEndTime());
-                int recordMonth = recordCal.get(Calendar.MONTH) + 1;
-
-                // 判断endTime是否在当月
-                if (recordMonth == currentMonth) {
-                    usedThisMonth++;
+    
+                // 判断是否超过限制
+                if (usedThisMonth >= limitQuantity) {
+                    return ResultUtil.error("本月使用数量已经超出限制");
+                    // 这里可以添加更多的逻辑处理,比如抛出异常、记录日志等
                 }
             }
-
-            // 判断是否超过限制
-            if (usedThisMonth >= limitQuantity) {
-                return ResultUtil.error("本月使用数量已经超出限制");
-                // 这里可以添加更多的逻辑处理,比如抛出异常、记录日志等
-            } else {
-                return ResultUtil.success();
-            }
-
-
+            return ResultUtil.success();
         }catch (Exception e){
             e.printStackTrace();
             return ResultUtil.runErr();

--
Gitblit v1.7.1