|
@@ -202,9 +202,8 @@ public class LiveCouponServiceImpl implements ILiveCouponService
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public List<LiveCoupon> selectLiveCouponByLiveId(Long liveId) {
|
|
public List<LiveCoupon> selectLiveCouponByLiveId(Long liveId) {
|
|
|
- return liveCouponMapper.selectLiveCouponByLiveId(liveId).stream()
|
|
|
|
|
- .filter(c -> c.getCouponId() != null)
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
|
|
+ // 直接返回 PageHelper 的 Page,勿 stream().collect(),否则会丢失分页 total
|
|
|
|
|
+ return liveCouponMapper.selectLiveCouponByLiveId(liveId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -387,7 +386,12 @@ public class LiveCouponServiceImpl implements ILiveCouponService
|
|
|
userRecord.setCreateTime(now);
|
|
userRecord.setCreateTime(now);
|
|
|
userRecord.setUpdateTime(now);
|
|
userRecord.setUpdateTime(now);
|
|
|
userRecord.setStatus(0);
|
|
userRecord.setStatus(0);
|
|
|
- userRecord.setLimitTime(DateUtils.addDays(now, Math.toIntExact(liveCoupon.getCouponTime())));
|
|
|
|
|
|
|
+ // 与观看奖励发券一致:优先用发放配置结束时间,否则按模板有效天数(勿补 23:59:59.999,MySQL DATETIME 会进位到次日 00:00:00)
|
|
|
|
|
+ if (issue.getLimitTime() != null) {
|
|
|
|
|
+ userRecord.setLimitTime(issue.getLimitTime());
|
|
|
|
|
+ } else if (liveCoupon.getCouponTime() != null) {
|
|
|
|
|
+ userRecord.setLimitTime(DateUtils.addDays(now, Math.toIntExact(liveCoupon.getCouponTime())));
|
|
|
|
|
+ }
|
|
|
userRecord.setIsFail(1);
|
|
userRecord.setIsFail(1);
|
|
|
userRecord.setIsDel(0);
|
|
userRecord.setIsDel(0);
|
|
|
userRecord.setGoodsId(coupon.getGoodsId());
|
|
userRecord.setGoodsId(coupon.getGoodsId());
|
|
@@ -804,6 +808,39 @@ public class LiveCouponServiceImpl implements ILiveCouponService
|
|
|
liveCouponUserService.updateLiveCouponUser(update);
|
|
liveCouponUserService.updateLiveCouponUser(update);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 计算用户优惠券到期时间。
|
|
|
|
|
+ * <p>优先取发放配置结束时间(发布时的优惠券结束日期,日期型补齐到当天 23:59:59);
|
|
|
|
|
+ * 未配置时按模板有效天数从领取时刻起算。与完课/观看奖励发券逻辑保持一致。</p>
|
|
|
|
|
+ */
|
|
|
|
|
+ private Date resolveCouponUserLimitTime(LiveCouponIssue issue, LiveCoupon liveCoupon, Date now) {
|
|
|
|
|
+ if (issue != null && issue.getLimitTime() != null) {
|
|
|
|
|
+ return toEndOfDayIfMidnight(issue.getLimitTime());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (liveCoupon != null && liveCoupon.getCouponTime() != null) {
|
|
|
|
|
+ return DateUtils.addDays(now, Math.toIntExact(liveCoupon.getCouponTime()));
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发布结束日期多为 yyyy-MM-dd(落库为 00:00:00),补齐到当天末,保证结束日当天仍可用。
|
|
|
|
|
+ */
|
|
|
|
|
+ private Date toEndOfDayIfMidnight(Date date) {
|
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
|
+ cal.setTime(date);
|
|
|
|
|
+ if (cal.get(Calendar.HOUR_OF_DAY) == 0
|
|
|
|
|
+ && cal.get(Calendar.MINUTE) == 0
|
|
|
|
|
+ && cal.get(Calendar.SECOND) == 0
|
|
|
|
|
+ && cal.get(Calendar.MILLISECOND) == 0) {
|
|
|
|
|
+ cal.set(Calendar.HOUR_OF_DAY, 23);
|
|
|
|
|
+ cal.set(Calendar.MINUTE, 59);
|
|
|
|
|
+ cal.set(Calendar.SECOND, 59);
|
|
|
|
|
+ cal.set(Calendar.MILLISECOND, 999);
|
|
|
|
|
+ }
|
|
|
|
|
+ return cal.getTime();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 若优惠券未核销且已超过有效期,则同步更新为已过期状态。
|
|
* 若优惠券未核销且已超过有效期,则同步更新为已过期状态。
|
|
|
*
|
|
*
|
|
@@ -874,10 +911,11 @@ public class LiveCouponServiceImpl implements ILiveCouponService
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public List<LiveCoupon> listOn(Long liveId) {
|
|
public List<LiveCoupon> listOn(Long liveId) {
|
|
|
- return liveCouponMapper.listOn(liveId).stream()
|
|
|
|
|
- .filter(c -> c.getCouponId() != null)
|
|
|
|
|
- .filter(c -> c.getGoodsId() != null || isVerifyCouponType(c))
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
|
|
+ // 过滤规则与原先一致:couponId 非空,且已绑定商品或核销/代金券类型
|
|
|
|
|
+ // 使用 removeIf 保留 PageHelper 的 Page,避免 collect 后 total 丢失
|
|
|
|
|
+ List<LiveCoupon> list = liveCouponMapper.listOn(liveId);
|
|
|
|
|
+ list.removeIf(c -> c.getCouponId() == null || (c.getGoodsId() == null && !isVerifyCouponType(c)));
|
|
|
|
|
+ return list;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|