|
|
@@ -24,9 +24,11 @@ import shop.alien.store.service.LifeDiscountCouponQuantumRulesService;
|
|
|
import shop.alien.store.service.LifeDiscountCouponService;
|
|
|
import shop.alien.store.service.LifeDiscountCouponUserService;
|
|
|
import shop.alien.util.common.constant.DiscountCouponEnum;
|
|
|
+import shop.alien.util.coupon.DiscountCouponExpirationUtil;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.Instant;
|
|
|
import java.time.LocalDate;
|
|
|
@@ -991,7 +993,16 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
vo.setVoucherId(lc.getId());
|
|
|
// quantityClaimed表示该券的总领取数量,在用户券列表中不设置或设置为0
|
|
|
vo.setQuantityClaimed(null);
|
|
|
- vo.setExpirationTime(userCoupon.getExpirationTime());
|
|
|
+ LocalDate exp = userCoupon.getExpirationTime();
|
|
|
+ if (exp == null) {
|
|
|
+ exp = DiscountCouponExpirationUtil.resolveLifeCouponVoucherExpiration(
|
|
|
+ userCoupon.getReceiveTime(),
|
|
|
+ lc.getExpirationDate(),
|
|
|
+ lc.getEndDate(),
|
|
|
+ zoneId);
|
|
|
+ }
|
|
|
+ vo.setExpirationTime(exp);
|
|
|
+ vo.setValidDate(exp);
|
|
|
vo.setReachUseTimeFlag(1);
|
|
|
|
|
|
// 判断是否到了使用开始时间
|
|
|
@@ -1002,14 +1013,10 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 设置有效期
|
|
|
- if (lc.getEndDate() != null) {
|
|
|
- vo.setValidDate(lc.getEndDate().toInstant().atZone(zoneId).toLocalDate());
|
|
|
- }
|
|
|
-
|
|
|
// 设置店铺信息
|
|
|
StoreInfo storeInfo = storeInfoMap.get(lc.getStoreId());
|
|
|
if (storeInfo != null) {
|
|
|
+ vo.setStoreName(storeInfo.getStoreName());
|
|
|
vo.setBusinessSection(storeInfo.getBusinessSection());
|
|
|
vo.setBusinessSectionName(storeInfo.getBusinessSectionName());
|
|
|
}
|
|
|
@@ -1030,22 +1037,19 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
|
|
|
// quantityClaimed表示该券的总领取数量,在用户券列表中不设置或设置为0
|
|
|
vo.setQuantityClaimed(null);
|
|
|
- vo.setExpirationTime(userCoupon.getExpirationTime());
|
|
|
-
|
|
|
- // 设置有效期(根据指定天数计算)
|
|
|
- String specifiedDay = coupon.getSpecifiedDay();
|
|
|
- if (!StringUtils.isEmpty(specifiedDay)) {
|
|
|
- try {
|
|
|
- int sDay = Integer.parseInt(specifiedDay);
|
|
|
- if (sDay > 0 && userCoupon.getReceiveTime() != null) {
|
|
|
- Date validDate = addDaysToDateJava8(userCoupon.getReceiveTime(), sDay);
|
|
|
- vo.setValidDate(validDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
|
|
|
- }
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- // 忽略解析错误
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ LocalDate exp = userCoupon.getExpirationTime();
|
|
|
+ if (exp == null) {
|
|
|
+ exp = DiscountCouponExpirationUtil.resolveLifeDiscountCouponExpiration(
|
|
|
+ userCoupon.getReceiveTime(),
|
|
|
+ coupon.getSpecifiedDay(),
|
|
|
+ coupon.getExpirationDate(),
|
|
|
+ coupon.getValidDate(),
|
|
|
+ coupon.getEndDate(),
|
|
|
+ zoneId);
|
|
|
+ }
|
|
|
+ vo.setExpirationTime(exp);
|
|
|
+ vo.setValidDate(exp);
|
|
|
+
|
|
|
// 判断是否到了优惠券的开始时间
|
|
|
vo.setReachUseTimeFlag(1);
|
|
|
if (coupon.getBeginGetDate() != null && localNow.isBefore(coupon.getBeginGetDate())) {
|
|
|
@@ -1056,6 +1060,7 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
if (!StringUtils.isEmpty(coupon.getStoreId())) {
|
|
|
StoreInfo storeInfo = storeInfoMap.get(coupon.getStoreId());
|
|
|
if (storeInfo != null) {
|
|
|
+ vo.setStoreName(storeInfo.getStoreName());
|
|
|
vo.setBusinessSection(storeInfo.getBusinessSection());
|
|
|
vo.setBusinessSectionName(storeInfo.getBusinessSectionName());
|
|
|
}
|
|
|
@@ -1651,7 +1656,8 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
if (couponType != null && couponType == 2) {
|
|
|
// 折扣券:显示折扣率和最低消费
|
|
|
if (lifeDiscountCoupon.getDiscountRate() != null) {
|
|
|
- forbiddenRule += "折扣率:" + lifeDiscountCoupon.getDiscountRate() + "折;";
|
|
|
+ BigDecimal zheShu = lifeDiscountCoupon.getDiscountRate().divide(BigDecimal.TEN, 2, RoundingMode.HALF_UP);
|
|
|
+ forbiddenRule += "折扣率:" + zheShu.stripTrailingZeros().toPlainString() + "折;";
|
|
|
}
|
|
|
} else {
|
|
|
// 满减券(默认):显示面值和最低消费
|
|
|
@@ -1874,7 +1880,13 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
lifeDiscountCouponUser.setUserId(userId);
|
|
|
lifeDiscountCouponUser.setCouponId(couponId);
|
|
|
lifeDiscountCouponUser.setReceiveTime(new Date());
|
|
|
- lifeDiscountCouponUser.setExpirationTime(LocalDate.now().plusDays(Long.parseLong(lifeDiscountCoupon.getSpecifiedDay())));
|
|
|
+ lifeDiscountCouponUser.setExpirationTime(DiscountCouponExpirationUtil.resolveLifeDiscountCouponExpiration(
|
|
|
+ lifeDiscountCouponUser.getReceiveTime(),
|
|
|
+ lifeDiscountCoupon.getSpecifiedDay(),
|
|
|
+ lifeDiscountCoupon.getExpirationDate(),
|
|
|
+ lifeDiscountCoupon.getValidDate(),
|
|
|
+ lifeDiscountCoupon.getEndDate(),
|
|
|
+ ZoneId.systemDefault()));
|
|
|
lifeDiscountCouponUser.setStatus(0);
|
|
|
lifeDiscountCouponUser.setDeleteFlag(0);
|
|
|
lifeDiscountCouponUser.setCreatedTime(new Date());
|
|
|
@@ -2051,13 +2063,13 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
|
|
|
lifeDiscountCouponUser.setCouponId(latestCoupon.getId());
|
|
|
lifeDiscountCouponUser.setUserId(userId);
|
|
|
lifeDiscountCouponUser.setReceiveTime(new Date());
|
|
|
-
|
|
|
- // 设置过期时间:优先使用validDate,如果为null则使用endDate
|
|
|
- LocalDate expirationTime = latestCoupon.getValidDate();
|
|
|
- if (expirationTime == null && latestCoupon.getEndDate() != null) {
|
|
|
- expirationTime = latestCoupon.getEndDate();
|
|
|
- }
|
|
|
- lifeDiscountCouponUser.setExpirationTime(expirationTime);
|
|
|
+ lifeDiscountCouponUser.setExpirationTime(DiscountCouponExpirationUtil.resolveLifeDiscountCouponExpiration(
|
|
|
+ lifeDiscountCouponUser.getReceiveTime(),
|
|
|
+ latestCoupon.getSpecifiedDay(),
|
|
|
+ latestCoupon.getExpirationDate(),
|
|
|
+ latestCoupon.getValidDate(),
|
|
|
+ latestCoupon.getEndDate(),
|
|
|
+ ZoneId.systemDefault()));
|
|
|
lifeDiscountCouponUser.setStatus(Integer.parseInt(DiscountCouponEnum.WAITING_USED.getValue()));
|
|
|
lifeDiscountCouponUser.setDeleteFlag(0);
|
|
|
lifeDiscountCouponUser.setIssueSource(2); // 2-收藏店铺
|