ソースを参照

Merge remote-tracking branch 'origin/master'

wxd 4 ヶ月 前
コミット
f6bb43dae3

+ 4 - 0
alien-entity/src/main/java/shop/alien/entity/store/LifeDiscountCoupon.java

@@ -142,6 +142,10 @@ public class LifeDiscountCoupon extends Model<LifeDiscountCoupon> {
     @TableField("coupon_status")
     private Integer couponStatus;
 
+    @ApiModelProperty(value = "有效期")
+    @TableField("valid_date")
+    private LocalDate validDate;
+
     @Override
     protected Serializable pkVal() {
         return this.id;

+ 4 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/LifeDiscountCouponVo.java

@@ -147,4 +147,8 @@ public class LifeDiscountCouponVo {
 
     @ApiModelProperty(value = "优惠券状态:0:草稿,1:正式")
     private Integer couponStatus;
+
+    @ApiModelProperty(value = "有效期")
+    private LocalDate validDate;
+
 }

+ 8 - 6
alien-store/src/main/java/shop/alien/store/controller/LifeDiscountCouponController.java

@@ -213,11 +213,12 @@ public class LifeDiscountCouponController {
                                                                 @RequestParam(value = "storeId") String storeId,
                                                                 @RequestParam(value = "couponName", required = false) String couponName,
                                                                 @RequestParam(value = "tab") String tab,
-                                                                @RequestParam(value = "couponsFromType", defaultValue = "1") int couponsFromType
+                                                                @RequestParam(value = "couponsFromType", defaultValue = "1") int couponsFromType,
+                                                                @RequestParam(value = "couponStatus", defaultValue = "1",required = false) int couponStatus
     ) {
-        log.info("LifeDiscountCouponController.getStoreAllCouponList?storeId={}, couponName={}, tab={}, page={}, size={}", storeId, couponName, tab, page, size);
+        log.info("LifeDiscountCouponController.getStoreAllCouponList?storeId={}, couponName={}, tab={}, page={}, size={}, couponStatus={}", storeId, couponName, tab, page, size, couponStatus);
         try {
-            IPage<LifeDiscountCouponVo> storeCouponList = lifeDiscountCouponService.getStoreAllCouponList(storeId, userLoginInfo, page, size, couponName, tab, couponsFromType);
+            IPage<LifeDiscountCouponVo> storeCouponList = lifeDiscountCouponService.getStoreAllCouponList(storeId, userLoginInfo, page, size, couponName, tab, couponsFromType, couponStatus);
             return R.data(storeCouponList);
         } catch (Exception e) {
             log.error("LifeDiscountCouponController.getStoreCouponList ERROR Msg={}", e.getMessage());
@@ -233,11 +234,12 @@ public class LifeDiscountCouponController {
     })
     public R<List<LifeDiscountCouponVo>> getStoreAllCouponListPaginateNot(@ApiIgnore @TokenInfo UserLoginInfo userLoginInfo,
                                                                           @RequestParam(value = "storeId") String storeId,
-                                                                          @RequestParam(value = "status", required = false) String status
+                                                                          @RequestParam(value = "status", required = false) String status,
+                                                                          @RequestParam(value = "couponStatus", defaultValue = "1",required = false) int couponStatus
     ) {
-        log.info("LifeDiscountCouponController.getStoreAllCouponListPaginateNot?storeId={},status={}", storeId, status);
+        log.info("LifeDiscountCouponController.getStoreAllCouponListPaginateNot?storeId={},status={}, couponStatus={}", storeId, status, couponStatus);
         try {
-            List<LifeDiscountCouponVo> storeCouponList = lifeDiscountCouponService.getStoreAllCouponListPaginateNot(status, storeId, userLoginInfo);
+            List<LifeDiscountCouponVo> storeCouponList = lifeDiscountCouponService.getStoreAllCouponListPaginateNot(status, storeId, userLoginInfo, couponStatus);
             return R.data(storeCouponList);
         } catch (Exception e) {
             log.error("LifeDiscountCouponController.getStoreAllCouponListPaginateNot ERROR Msg={}", e.getMessage());

+ 2 - 2
alien-store/src/main/java/shop/alien/store/service/LifeDiscountCouponService.java

@@ -65,12 +65,12 @@ public interface LifeDiscountCouponService extends IService<LifeDiscountCoupon>
     /**
      * 获取所有优惠券列表(分页)
      */
-    public IPage<LifeDiscountCouponVo> getStoreAllCouponList(String storeId, UserLoginInfo userLoginInfo, int page, int size, String couponName, String tab, int couponsFromType);
+    public IPage<LifeDiscountCouponVo> getStoreAllCouponList(String storeId, UserLoginInfo userLoginInfo, int page, int size, String couponName, String tab, int couponsFromType, int couponStatus);
 
     /**
      * 获取所有优惠券列表(不分页)
      */
-    public List<LifeDiscountCouponVo> getStoreAllCouponListPaginateNot(String status, String storeId, UserLoginInfo userLoginInfo);
+    public List<LifeDiscountCouponVo> getStoreAllCouponListPaginateNot(String status, String storeId, UserLoginInfo userLoginInfo, int couponStatus);
 
     /**
      * 获取优惠券规则

+ 140 - 80
alien-store/src/main/java/shop/alien/store/service/impl/LifeDiscountCouponServiceImpl.java

@@ -75,34 +75,55 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
             BeanUtils.copyProperties(lifeDiscountCouponDto, lifeDiscountCoupon);
             // 根据开始领取时间判断可领取状态
             // 判断是否在领取时间内
+
             Date now = new Date();
             Instant instant = now.toInstant();
             ZoneId zoneId = ZoneId.systemDefault();
             LocalDate localNow = instant.atZone(zoneId).toLocalDate();
-            int startResult = localNow.compareTo(lifeDiscountCoupon.getBeginGetDate());
-            int endResult = localNow.compareTo(lifeDiscountCoupon.getEndGetDate());
-            if ((lifeDiscountCouponDto.getCouponStatus() != null && lifeDiscountCouponDto.getCouponStatus() == 0) || (startResult < 0 || endResult > 0)) {
-                lifeDiscountCoupon.setGetStatus(0);
-            } else {
-                lifeDiscountCoupon.setGetStatus(1);
+            if (lifeDiscountCouponDto.getCouponStatus() == 1 && !StringUtils.isEmpty(lifeDiscountCoupon.getBeginGetDate()) || !StringUtils.isEmpty(lifeDiscountCoupon.getEndGetDate())) {
+                int startResult = localNow.compareTo(lifeDiscountCoupon.getBeginGetDate());
+                int endResult = localNow.compareTo(lifeDiscountCoupon.getEndGetDate());
+                if ((lifeDiscountCouponDto.getCouponStatus() != null && lifeDiscountCouponDto.getCouponStatus() == 0) || (startResult < 0 || endResult > 0)) {
+                    lifeDiscountCoupon.setGetStatus(0);
+                } else {
+                    lifeDiscountCoupon.setGetStatus(1);
+                }
             }
 
+            // 设置有效期
+            String specifiedDay = lifeDiscountCoupon.getSpecifiedDay();
+            if(!StringUtils.isEmpty(specifiedDay)){
+                int sDay = Integer.parseInt(specifiedDay);
+                if(sDay > 0){
+                    Date validDate = addDaysToDateJava8(new Date(), sDay);
+                    LocalDate validDateLocalDate = validDate.toInstant()
+                            .atZone(ZoneId.systemDefault())
+                            .toLocalDate();
+                    lifeDiscountCoupon.setValidDate(validDateLocalDate);
+                }
+            }
             lifeDiscountCouponMapper.insert(lifeDiscountCoupon);
             //发布优惠券规则信息
             //周中规则保存
             LifeDiscountCouponUnavailableRules lifeDiscountCouponUnavailableRules = new LifeDiscountCouponUnavailableRules();
             lifeDiscountCouponUnavailableRules.setDiscountCouponId(lifeDiscountCoupon.getId());
             lifeDiscountCouponUnavailableRules.setUnavailableRuleType(DiscountCouponEnum.WEEKDAY_UNAVAILABLE.getValue());
-            lifeDiscountCouponDto.getWeeklyDisabledList().forEach(weeklyDisabled -> {
-                lifeDiscountCouponUnavailableRules.setUnavailableRuleValue(weeklyDisabled);
-                lifeDiscountCouponUnavailableRulesMapper.insert(lifeDiscountCouponUnavailableRules);
-            });
+            if(CollectionUtils.isNotEmpty(lifeDiscountCouponDto.getWeeklyDisabledList())) {
+                lifeDiscountCouponDto.getWeeklyDisabledList().forEach(weeklyDisabled -> {
+                    lifeDiscountCouponUnavailableRules.setUnavailableRuleValue(weeklyDisabled);
+                    lifeDiscountCouponUnavailableRulesMapper.insert(lifeDiscountCouponUnavailableRules);
+                });
+            }
+
             //节假日规则保存
             lifeDiscountCouponUnavailableRules.setUnavailableRuleType(DiscountCouponEnum.HOLIDAY_UNAVAILABLE.getValue());
-            lifeDiscountCouponDto.getHolidayDisabledList().forEach(holidayDisabled -> {
-                lifeDiscountCouponUnavailableRules.setUnavailableRuleValue(holidayDisabled);
-                lifeDiscountCouponUnavailableRulesMapper.insert(lifeDiscountCouponUnavailableRules);
-            });
+            if(CollectionUtils.isNotEmpty(lifeDiscountCouponDto.getHolidayDisabledList())){
+                lifeDiscountCouponDto.getHolidayDisabledList().forEach(holidayDisabled -> {
+                    lifeDiscountCouponUnavailableRules.setUnavailableRuleValue(holidayDisabled);
+                    lifeDiscountCouponUnavailableRulesMapper.insert(lifeDiscountCouponUnavailableRules);
+                });
+            }
+
             //领取规则
             lifeDiscountCouponUnavailableRules.setUnavailableRuleType(DiscountCouponEnum.CLAIM_RULE.getValue());
             String claimRule = lifeDiscountCouponDto.getClaimRule();
@@ -151,12 +172,29 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
             Instant instant = now.toInstant();
             ZoneId zoneId = ZoneId.systemDefault();
             LocalDate localNow = instant.atZone(zoneId).toLocalDate();
-            int startResult = localNow.compareTo(lifeDiscountCoupon.getBeginGetDate());
-            int endResult = localNow.compareTo(lifeDiscountCoupon.getEndGetDate());
-            if ((lifeDiscountCouponDto.getCouponStatus() != null && lifeDiscountCouponDto.getCouponStatus() == 0) || (startResult < 0 || endResult > 0)) {
+            if (lifeDiscountCouponDto.getCouponStatus() == 1 && !StringUtils.isEmpty(lifeDiscountCoupon.getBeginGetDate()) || !StringUtils.isEmpty(lifeDiscountCoupon.getEndGetDate())) {
+                int startResult = localNow.compareTo(lifeDiscountCoupon.getBeginGetDate());
+                int endResult = localNow.compareTo(lifeDiscountCoupon.getEndGetDate());
+                if ((lifeDiscountCouponDto.getCouponStatus() != null && lifeDiscountCouponDto.getCouponStatus() == 0) || (startResult < 0 || endResult > 0)) {
+                    lifeDiscountCoupon.setGetStatus(0);
+                } else {
+                    lifeDiscountCoupon.setGetStatus(1);
+                }
+            } else if (lifeDiscountCouponDto.getCouponStatus() == 0) {
                 lifeDiscountCoupon.setGetStatus(0);
-            } else {
-                lifeDiscountCoupon.setGetStatus(1);
+            }
+
+            // 设置有效期
+            String specifiedDay = lifeDiscountCouponDto.getSpecifiedDay();
+            if(!StringUtils.isEmpty(specifiedDay)){
+                int sDay = Integer.parseInt(specifiedDay);
+                if(sDay > 0){
+                    Date validDate = addDaysToDateJava8(new Date(), sDay);
+                    LocalDate validDateLocalDate = validDate.toInstant()
+                            .atZone(ZoneId.systemDefault())
+                            .toLocalDate();
+                    lifeDiscountCoupon.setValidDate(validDateLocalDate);
+                }
             }
 
             lifeDiscountCouponMapper.updateById(lifeDiscountCoupon);
@@ -170,16 +208,22 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
             LifeDiscountCouponUnavailableRules lifeDiscountCouponUnavailableRules = new LifeDiscountCouponUnavailableRules();
             lifeDiscountCouponUnavailableRules.setDiscountCouponId(lifeDiscountCoupon.getId());
             lifeDiscountCouponUnavailableRules.setUnavailableRuleType(DiscountCouponEnum.WEEKDAY_UNAVAILABLE.getValue());
-            lifeDiscountCouponDto.getWeeklyDisabledList().forEach(weeklyDisabled -> {
-                lifeDiscountCouponUnavailableRules.setUnavailableRuleValue(weeklyDisabled);
-                lifeDiscountCouponUnavailableRulesMapper.insert(lifeDiscountCouponUnavailableRules);
-            });
+            if(CollectionUtils.isNotEmpty(lifeDiscountCouponDto.getWeeklyDisabledList())) {
+                lifeDiscountCouponDto.getWeeklyDisabledList().forEach(weeklyDisabled -> {
+                    lifeDiscountCouponUnavailableRules.setUnavailableRuleValue(weeklyDisabled);
+                    lifeDiscountCouponUnavailableRulesMapper.insert(lifeDiscountCouponUnavailableRules);
+                });
+            }
+
             //节假日规则保存
             lifeDiscountCouponUnavailableRules.setUnavailableRuleType(DiscountCouponEnum.HOLIDAY_UNAVAILABLE.getValue());
-            lifeDiscountCouponDto.getHolidayDisabledList().forEach(holidayDisabled -> {
-                lifeDiscountCouponUnavailableRules.setUnavailableRuleValue(holidayDisabled);
-                lifeDiscountCouponUnavailableRulesMapper.insert(lifeDiscountCouponUnavailableRules);
-            });
+            if(CollectionUtils.isNotEmpty(lifeDiscountCouponDto.getHolidayDisabledList())){
+                lifeDiscountCouponDto.getHolidayDisabledList().forEach(holidayDisabled -> {
+                    lifeDiscountCouponUnavailableRules.setUnavailableRuleValue(holidayDisabled);
+                    lifeDiscountCouponUnavailableRulesMapper.insert(lifeDiscountCouponUnavailableRules);
+                });
+            }
+
             //领取规则
             lifeDiscountCouponUnavailableRules.setUnavailableRuleType(DiscountCouponEnum.CLAIM_RULE.getValue());
             lifeDiscountCouponUnavailableRules.setUnavailableRuleValue(lifeDiscountCouponDto.getClaimRule());
@@ -229,14 +273,14 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
         LifeDiscountCoupon lifeDiscountCoupon = lifeDiscountCouponMapper.selectById(counponId);
         lifeDiscountCoupon.setGetStatus(lifeDiscountCoupon.getGetStatus() == Integer.parseInt(DiscountCouponEnum.NO_GET.getValue())
                 ? Integer.parseInt(DiscountCouponEnum.CAN_GET.getValue()) : Integer.parseInt(DiscountCouponEnum.NO_GET.getValue()));
-        Date now = new Date();
-        Instant instant = now.toInstant();
-        ZoneId zoneId = ZoneId.systemDefault();
-        LocalDate localNow = instant.atZone(zoneId).toLocalDate();
-        if (localNow.compareTo(lifeDiscountCoupon.getStartDate()) < 0) {
-            lifeDiscountCoupon.setStartDate(localNow);
-            lifeDiscountCoupon.setGetStatus(Integer.parseInt(DiscountCouponEnum.CAN_GET.getValue()));
-        }
+//        Date now = new Date();
+//        Instant instant = now.toInstant();
+//        ZoneId zoneId = ZoneId.systemDefault();
+//        LocalDate localNow = instant.atZone(zoneId).toLocalDate();
+//        if (localNow.compareTo(lifeDiscountCoupon.getStartDate()) < 0) {
+//            lifeDiscountCoupon.setStartDate(localNow);
+//            lifeDiscountCoupon.setGetStatus(Integer.parseInt(DiscountCouponEnum.CAN_GET.getValue()));
+//        }
         lifeDiscountCouponMapper.updateById(lifeDiscountCoupon);
         return true;
     }
@@ -289,6 +333,18 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
         return lifeDiscountCouponVo;
     }
 
+    public static Date addDaysToDateJava8(Date date, int days) {
+        // 将Date转换为Instant
+        Instant instant = date.toInstant();
+
+        // 转换为LocalDate并加天数
+        LocalDate localDate = instant.atZone(ZoneId.systemDefault()).toLocalDate();
+        LocalDate newLocalDate = localDate.plusDays(days);
+
+        // 转换回Date
+        return Date.from(newLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
+    }
+
     @Override
     public List<LifeDiscountCouponVo> getStoreUserCouponList(String storeId, UserLoginInfo userLoginInfo) {
         List<LifeDiscountCouponVo> lifeDiscountCouponVos = new ArrayList<>();
@@ -298,7 +354,7 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
                         .eq(LifeDiscountCoupon::getStoreId, storeId)
                         .eq(LifeDiscountCoupon::getGetStatus, "1")
                         .gt(LifeDiscountCoupon::getSingleQty, 0) //还有库存
-                        .ge(LifeDiscountCoupon::getEndDate, new Date())
+                        .ge(LifeDiscountCoupon::getEndGetDate, new Date())
                         .orderByDesc(LifeDiscountCoupon::getCreatedTime));
         //根据优惠券列表查询该优惠券是否领取过
         for (LifeDiscountCoupon lifeDiscountCoupon : lifeDiscountCoupons) {
@@ -347,11 +403,7 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
                         confineTo = ChronoUnit.YEARS.between(localDateTime, now);
                     }
                     //如果在规则范围内,则不允许领取,范围外,则可以领取
-                    if (confineTo < 1) {
-                        lifeDiscountCouponVo.setCanReceived(false);
-                    } else {
-                        lifeDiscountCouponVo.setCanReceived(true);
-                    }
+                    lifeDiscountCouponVo.setCanReceived(confineTo >= 1);
                 }
             }
             lifeDiscountCouponVo.setQuantityClaimed(lifeDiscountCouponUsers.size());
@@ -641,12 +693,13 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
     }
 
     @Override
-    public IPage<LifeDiscountCouponVo> getStoreAllCouponList(String storeId, UserLoginInfo userLoginInfo, int page, int size, String couponName, String tab, int couponsFromType) {
+    public IPage<LifeDiscountCouponVo> getStoreAllCouponList(String storeId, UserLoginInfo userLoginInfo, int page, int size, String couponName, String tab, int couponsFromType, int couponStatus) {
 
         if (couponsFromType == 1) {
             IPage<LifeDiscountCoupon> iPage = new Page<>(page, size);
             List<LifeDiscountCouponVo> lifeDiscountCouponVos = new ArrayList<>();
             LambdaQueryWrapper<LifeDiscountCoupon> lifeDiscountCouponLambdaQueryWrapper = new LambdaQueryWrapper<LifeDiscountCoupon>();
+            lifeDiscountCouponLambdaQueryWrapper.eq(LifeDiscountCoupon::getCouponStatus, couponStatus);
             //如果couponName不为空,则模糊查询
             if (!StringUtils.isEmpty(couponName)) {
                 lifeDiscountCouponLambdaQueryWrapper.like(LifeDiscountCoupon::getName, couponName);
@@ -681,19 +734,21 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
                 Instant instant = now.toInstant();
                 ZoneId zoneId = ZoneId.systemDefault();
                 LocalDate localNow = instant.atZone(zoneId).toLocalDate();
-                int startResult = localNow.compareTo(lifeDiscountCoupon.getBeginGetDate());
-                int endResult = localNow.compareTo(lifeDiscountCoupon.getEndGetDate());
-                //如果当前时间小于开始时间
-                if (lifeDiscountCoupon.getSingleQty() == 0) {//无库存则已售罄
-                    lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_SOLD_OUT.getValue()));
-                } else if (lifeDiscountCoupon.getGetStatus().toString().equals(DiscountCouponEnum.NO_GET.getValue())) {
-                    lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.SUSPEND_GET.getValue()));
-                } else if (startResult < 0) {
-                    lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue()));
-                } else if (endResult > 0) {
-                    lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.FINISHED.getValue()));
-                } else if (startResult >= 0 && endResult <= 0) {
-                    lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.UNDER_WAY.getValue()));
+                if(!StringUtils.isEmpty(lifeDiscountCoupon.getBeginGetDate()) && !StringUtils.isEmpty(lifeDiscountCoupon.getEndGetDate())) {
+                    int startResult = localNow.compareTo(lifeDiscountCoupon.getBeginGetDate());
+                    int endResult = localNow.compareTo(lifeDiscountCoupon.getEndGetDate());
+                    //如果当前时间小于开始时间
+                    if (lifeDiscountCoupon.getSingleQty() == 0) {//无库存则已售罄
+                        lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_SOLD_OUT.getValue()));
+                    } else if (lifeDiscountCoupon.getGetStatus().toString().equals(DiscountCouponEnum.NO_GET.getValue())) {
+                        lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.SUSPEND_GET.getValue()));
+                    } else if (startResult < 0) {
+                        lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue()));
+                    } else if (endResult > 0) {
+                        lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.FINISHED.getValue()));
+                    } else if (startResult >= 0 && endResult <= 0) {
+                        lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.UNDER_WAY.getValue()));
+                    }
                 }
                 // 查询三个规则
                 List<LifeDiscountCouponUnavailableRules> discountCouponId = lifeDiscountCouponUnavailableRulesMapper.selectList(new QueryWrapper<LifeDiscountCouponUnavailableRules>().eq("discount_coupon_id", lifeDiscountCoupon.getId()));
@@ -751,19 +806,21 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
                 Instant instant = now.toInstant();
                 ZoneId zoneId = ZoneId.systemDefault();
                 LocalDate localNow = instant.atZone(zoneId).toLocalDate();
-                int startResult = localNow.compareTo(record.getStartDate());
-                int endResult = localNow.compareTo(record.getEndDate());
-                //如果当前时间小于开始时间
-                if (record.getSingleQty() == 0) {//无库存则已售罄
-                    record.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_SOLD_OUT.getValue()));
-                } else if (record.getGetStatus().toString().equals(DiscountCouponEnum.NO_GET.getValue())) {
-                    record.setStatus(Integer.parseInt(DiscountCouponEnum.SUSPEND_GET.getValue()));
-                } else if (startResult < 0) {
-                    record.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue()));
-                } else if (endResult > 0) {
-                    record.setStatus(Integer.parseInt(DiscountCouponEnum.FINISHED.getValue()));
-                } else if (startResult >= 0 && endResult <= 0) {
-                    record.setStatus(Integer.parseInt(DiscountCouponEnum.UNDER_WAY.getValue()));
+                if(!StringUtils.isEmpty(record.getBeginGetDate()) && !StringUtils.isEmpty(record.getEndGetDate())) {
+                    int startResult = localNow.compareTo(record.getBeginGetDate());
+                    int endResult = localNow.compareTo(record.getEndGetDate());
+                    //如果当前时间小于开始时间
+                    if (record.getSingleQty() == 0) {//无库存则已售罄
+                        record.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_SOLD_OUT.getValue()));
+                    } else if (record.getGetStatus().toString().equals(DiscountCouponEnum.NO_GET.getValue())) {
+                        record.setStatus(Integer.parseInt(DiscountCouponEnum.SUSPEND_GET.getValue()));
+                    } else if (startResult < 0) {
+                        record.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue()));
+                    } else if (endResult > 0) {
+                        record.setStatus(Integer.parseInt(DiscountCouponEnum.FINISHED.getValue()));
+                    } else if (startResult >= 0 && endResult <= 0) {
+                        record.setStatus(Integer.parseInt(DiscountCouponEnum.UNDER_WAY.getValue()));
+                    }
                 }
                 List<LifeDiscountCouponUnavailableRules> discountCouponId = lifeDiscountCouponUnavailableRulesMapper.selectList(new QueryWrapper<LifeDiscountCouponUnavailableRules>().eq("discount_coupon_id", record.getCouponId()));
                 Map<String, List<LifeDiscountCouponUnavailableRules>> collect = discountCouponId.stream().collect(Collectors.groupingBy(x -> x.getUnavailableRuleType()));
@@ -787,12 +844,13 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
     }
 
     @Override
-    public List<LifeDiscountCouponVo> getStoreAllCouponListPaginateNot(String status, String storeId, UserLoginInfo userLoginInfo) {
+    public List<LifeDiscountCouponVo> getStoreAllCouponListPaginateNot(String status, String storeId, UserLoginInfo userLoginInfo, int couponStatus) {
         List<LifeDiscountCouponVo> lifeDiscountCouponVos = new ArrayList<>();
         //根据店铺id查询该店铺的优惠券,状态是开启领取的券
         List<LifeDiscountCoupon> lifeDiscountCoupons = lifeDiscountCouponMapper.selectList(
                 new LambdaQueryWrapper<LifeDiscountCoupon>()
                         .eq(LifeDiscountCoupon::getStoreId, storeId)
+                        .eq(LifeDiscountCoupon::getCouponStatus, couponStatus)
                         .ne(LifeDiscountCoupon::getSingleQty, 0)
                         .orderByDesc(LifeDiscountCoupon::getCreatedTime)
         );
@@ -806,17 +864,19 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
             Instant instant = now.toInstant();
             ZoneId zoneId = ZoneId.systemDefault();
             LocalDate localNow = instant.atZone(zoneId).toLocalDate();
-            int startResult = localNow.compareTo(lifeDiscountCoupon.getBeginGetDate());
-            int endResult = localNow.compareTo(lifeDiscountCoupon.getEndGetDate());
-            //如果当前时间小于开始时间
-            if (lifeDiscountCoupon.getGetStatus().toString().equals(DiscountCouponEnum.NO_GET.getValue())) {
-                lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.SUSPEND_GET.getValue()));
-            } else if (startResult < 0) {
-                lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue()));
-            } else if (endResult > 0) {
-                lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.FINISHED.getValue()));
-            } else if (startResult >= 0 && endResult <= 0) {
-                lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.UNDER_WAY.getValue()));
+            if(!StringUtils.isEmpty(lifeDiscountCoupon.getBeginGetDate()) && !StringUtils.isEmpty(lifeDiscountCoupon.getEndGetDate())) {
+                int startResult = localNow.compareTo(lifeDiscountCoupon.getBeginGetDate());
+                int endResult = localNow.compareTo(lifeDiscountCoupon.getEndGetDate());
+                //如果当前时间小于开始时间
+                if (lifeDiscountCoupon.getGetStatus().toString().equals(DiscountCouponEnum.NO_GET.getValue())) {
+                    lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.SUSPEND_GET.getValue()));
+                } else if (startResult < 0) {
+                    lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.HAVE_NOT_STARTED.getValue()));
+                } else if (endResult > 0) {
+                    lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.FINISHED.getValue()));
+                } else if (startResult >= 0 && endResult <= 0) {
+                    lifeDiscountCouponVo.setStatus(Integer.parseInt(DiscountCouponEnum.UNDER_WAY.getValue()));
+                }
             }
             BeanUtils.copyProperties(lifeDiscountCoupon, lifeDiscountCouponVo);
             //如果按照状态查询了

+ 7 - 3
alien-store/src/main/java/shop/alien/store/service/impl/LifeDiscountCouponUserServiceImpl.java

@@ -45,17 +45,22 @@ public class LifeDiscountCouponUserServiceImpl extends ServiceImpl<LifeDiscountC
             Instant instant = now.toInstant();
             ZoneId zoneId = ZoneId.systemDefault();
             LocalDate localNow = instant.atZone(zoneId).toLocalDate();
-            int startResult = localNow.compareTo(lifeDiscountCoupon.getStartDate());
+            int startResult = localNow.compareTo(lifeDiscountCoupon.getBeginGetDate());
             if (startResult < 0) {
                 return R.fail("该优惠劵活动时间未开始");
             }
+            int getStatus = lifeDiscountCoupon.getGetStatus();
+            if (getStatus == 0) {
+                return R.fail("该优惠劵已经关闭领取");
+            }
+
             //判断领取数量
             for (int i = 0; i < receiveQuantity; i++) {
                 LifeDiscountCouponUser lifeDiscountCouponUser = new LifeDiscountCouponUser();
                 BeanUtils.copyProperties(lifeDiscountCouponUserDto, lifeDiscountCouponUser);
                 lifeDiscountCouponUser.setReceiveTime(new Date());
                 //存入过期时间
-                lifeDiscountCouponUser.setExpirationTime(lifeDiscountCoupon.getEndDate());
+                lifeDiscountCouponUser.setExpirationTime(lifeDiscountCoupon.getValidDate());
                 //存入状态  待使用:0
                 lifeDiscountCouponUser.setStatus(Integer.parseInt(DiscountCouponEnum.WAITING_USED.getValue()));
                 lifeDiscountCouponUserMapper.insert(lifeDiscountCouponUser);
@@ -64,7 +69,6 @@ public class LifeDiscountCouponUserServiceImpl extends ServiceImpl<LifeDiscountC
             lifeDiscountCoupon.setSingleQty(lifeDiscountCoupon.getSingleQty() - receiveQuantity);
             lifeDiscountCouponMapper.updateById(lifeDiscountCoupon);
         } catch (BeansException e) {
-            e.printStackTrace();
             log.error("LifeDiscountCouponController.receiveCoupon ERROR Msg=" + e.getMessage());
             return R.fail("领取失败");
         }