Эх сурвалжийг харах

修改编辑优惠券可售状态不变的bug

zhangchen 4 сар өмнө
parent
commit
77ba214e54

+ 15 - 0
alien-store/src/main/java/shop/alien/store/service/impl/LifeDiscountCouponServiceImpl.java

@@ -141,6 +141,21 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
             LifeDiscountCoupon lifeDiscountCoupon = new LifeDiscountCoupon();
             lifeDiscountCoupon.setId(Integer.parseInt(lifeDiscountCouponDto.getCouponId()));
             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 (startResult < 0 || endResult > 0) {
+                lifeDiscountCoupon.setGetStatus(0);
+            } else {
+                lifeDiscountCoupon.setGetStatus(1);
+            }
+
             lifeDiscountCouponMapper.updateById(lifeDiscountCoupon);
             //发布优惠券规则信息
             //先删除之前所有规则