| | |
| | | // 查询当前活动的限制数量 |
| | | 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(); |