|
@@ -49,6 +49,7 @@ public class CouponService {
|
|
|
return couponMapper.selectList(
|
|
return couponMapper.selectList(
|
|
|
new LambdaQueryWrapper<Coupon>()
|
|
new LambdaQueryWrapper<Coupon>()
|
|
|
.in(Coupon::getId, couponIds)
|
|
.in(Coupon::getId, couponIds)
|
|
|
|
|
+ .and(w -> w.isNull(Coupon::getStatus).or().eq(Coupon::getStatus, "ACTIVE"))
|
|
|
.le(Coupon::getValidFrom, now)
|
|
.le(Coupon::getValidFrom, now)
|
|
|
.ge(Coupon::getValidUntil, now)
|
|
.ge(Coupon::getValidUntil, now)
|
|
|
.orderByAsc(Coupon::getValue));
|
|
.orderByAsc(Coupon::getValue));
|
|
@@ -60,6 +61,9 @@ public class CouponService {
|
|
|
if (coupon == null) {
|
|
if (coupon == null) {
|
|
|
return "优惠券不存在";
|
|
return "优惠券不存在";
|
|
|
}
|
|
}
|
|
|
|
|
+ if (!"ACTIVE".equals(coupon.getStatus())) {
|
|
|
|
|
+ return "优惠券已停用";
|
|
|
|
|
+ }
|
|
|
if (coupon.getTotalCount() != null && coupon.getUsedCount() != null
|
|
if (coupon.getTotalCount() != null && coupon.getUsedCount() != null
|
|
|
&& coupon.getUsedCount() >= coupon.getTotalCount()) {
|
|
&& coupon.getUsedCount() >= coupon.getTotalCount()) {
|
|
|
return "优惠券已领完";
|
|
return "优惠券已领完";
|
|
@@ -98,6 +102,9 @@ public class CouponService {
|
|
|
if (coupon == null) {
|
|
if (coupon == null) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (!"ACTIVE".equals(coupon.getStatus())) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
Date now = new Date();
|
|
Date now = new Date();
|
|
|
if (coupon.getValidFrom() != null && now.before(coupon.getValidFrom())) {
|
|
if (coupon.getValidFrom() != null && now.before(coupon.getValidFrom())) {
|
|
|
return null;
|
|
return null;
|
|
@@ -167,6 +174,9 @@ public class CouponService {
|
|
|
if (coupon == null) {
|
|
if (coupon == null) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (!"ACTIVE".equals(coupon.getStatus())) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
if (period != null) {
|
|
if (period != null) {
|
|
|
Long exists = couponGrantLogMapper.selectCount(
|
|
Long exists = couponGrantLogMapper.selectCount(
|
|
|
new LambdaQueryWrapper<CouponGrantLog>()
|
|
new LambdaQueryWrapper<CouponGrantLog>()
|
|
@@ -200,7 +210,8 @@ public class CouponService {
|
|
|
List<Coupon> coupons = couponMapper.selectList(
|
|
List<Coupon> coupons = couponMapper.selectList(
|
|
|
new LambdaQueryWrapper<Coupon>()
|
|
new LambdaQueryWrapper<Coupon>()
|
|
|
.eq(Coupon::getGrantType, "JOIN")
|
|
.eq(Coupon::getGrantType, "JOIN")
|
|
|
- .eq(Coupon::getGrantLevelCode, levelCode));
|
|
|
|
|
|
|
+ .eq(Coupon::getGrantLevelCode, levelCode)
|
|
|
|
|
+ .and(w -> w.isNull(Coupon::getStatus).or().eq(Coupon::getStatus, "ACTIVE")));
|
|
|
if (coupons.isEmpty()) {
|
|
if (coupons.isEmpty()) {
|
|
|
logger.warn("未找到 JOIN 赠券模板: userId={}, levelCode={}", userId, levelCode);
|
|
logger.warn("未找到 JOIN 赠券模板: userId={}, levelCode={}", userId, levelCode);
|
|
|
return;
|
|
return;
|
|
@@ -216,7 +227,8 @@ public class CouponService {
|
|
|
public void grantPopulationCoupons(Long userId, Long memberId) {
|
|
public void grantPopulationCoupons(Long userId, Long memberId) {
|
|
|
List<Coupon> coupons = couponMapper.selectList(
|
|
List<Coupon> coupons = couponMapper.selectList(
|
|
|
new LambdaQueryWrapper<Coupon>()
|
|
new LambdaQueryWrapper<Coupon>()
|
|
|
- .eq(Coupon::getGrantType, "POPULATION"));
|
|
|
|
|
|
|
+ .eq(Coupon::getGrantType, "POPULATION")
|
|
|
|
|
+ .and(w -> w.isNull(Coupon::getStatus).or().eq(Coupon::getStatus, "ACTIVE")));
|
|
|
for (Coupon c : coupons) {
|
|
for (Coupon c : coupons) {
|
|
|
grant(userId, c.getId(), "POPULATION", null, "member:" + memberId);
|
|
grant(userId, c.getId(), "POPULATION", null, "member:" + memberId);
|
|
|
}
|
|
}
|
|
@@ -225,7 +237,9 @@ public class CouponService {
|
|
|
/** PERIODIC: 返回所有周期性补发券模板 */
|
|
/** PERIODIC: 返回所有周期性补发券模板 */
|
|
|
public List<Coupon> listPeriodicTemplates() {
|
|
public List<Coupon> listPeriodicTemplates() {
|
|
|
return couponMapper.selectList(
|
|
return couponMapper.selectList(
|
|
|
- new LambdaQueryWrapper<Coupon>().eq(Coupon::getGrantType, "PERIODIC"));
|
|
|
|
|
|
|
+ new LambdaQueryWrapper<Coupon>()
|
|
|
|
|
+ .eq(Coupon::getGrantType, "PERIODIC")
|
|
|
|
|
+ .and(w -> w.isNull(Coupon::getStatus).or().eq(Coupon::getStatus, "ACTIVE")));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** 积分兑换中心:所有可兑换券(points_price>0 且在有效期内) */
|
|
/** 积分兑换中心:所有可兑换券(points_price>0 且在有效期内) */
|
|
@@ -234,6 +248,7 @@ public class CouponService {
|
|
|
return couponMapper.selectList(
|
|
return couponMapper.selectList(
|
|
|
new LambdaQueryWrapper<Coupon>()
|
|
new LambdaQueryWrapper<Coupon>()
|
|
|
.gt(Coupon::getPointsPrice, 0)
|
|
.gt(Coupon::getPointsPrice, 0)
|
|
|
|
|
+ .and(w -> w.isNull(Coupon::getStatus).or().eq(Coupon::getStatus, "ACTIVE"))
|
|
|
.le(Coupon::getValidFrom, now)
|
|
.le(Coupon::getValidFrom, now)
|
|
|
.ge(Coupon::getValidUntil, now)
|
|
.ge(Coupon::getValidUntil, now)
|
|
|
.orderByAsc(Coupon::getPointsPrice));
|
|
.orderByAsc(Coupon::getPointsPrice));
|
|
@@ -246,6 +261,7 @@ public class CouponService {
|
|
|
new LambdaQueryWrapper<Coupon>()
|
|
new LambdaQueryWrapper<Coupon>()
|
|
|
.eq(Coupon::getProductId, productId)
|
|
.eq(Coupon::getProductId, productId)
|
|
|
.gt(Coupon::getPointsPrice, 0)
|
|
.gt(Coupon::getPointsPrice, 0)
|
|
|
|
|
+ .and(w -> w.isNull(Coupon::getStatus).or().eq(Coupon::getStatus, "ACTIVE"))
|
|
|
.le(Coupon::getValidFrom, now)
|
|
.le(Coupon::getValidFrom, now)
|
|
|
.ge(Coupon::getValidUntil, now)
|
|
.ge(Coupon::getValidUntil, now)
|
|
|
.orderByAsc(Coupon::getPointsPrice));
|
|
.orderByAsc(Coupon::getPointsPrice));
|
|
@@ -264,6 +280,7 @@ public class CouponService {
|
|
|
.stream().map(UserCoupon::getCouponId).collect(java.util.stream.Collectors.toList());
|
|
.stream().map(UserCoupon::getCouponId).collect(java.util.stream.Collectors.toList());
|
|
|
LambdaQueryWrapper<Coupon> wrapper = new LambdaQueryWrapper<Coupon>()
|
|
LambdaQueryWrapper<Coupon> wrapper = new LambdaQueryWrapper<Coupon>()
|
|
|
.gt(Coupon::getPointsPrice, 0)
|
|
.gt(Coupon::getPointsPrice, 0)
|
|
|
|
|
+ .and(w -> w.isNull(Coupon::getStatus).or().eq(Coupon::getStatus, "ACTIVE"))
|
|
|
.le(Coupon::getValidFrom, now)
|
|
.le(Coupon::getValidFrom, now)
|
|
|
.ge(Coupon::getValidUntil, now)
|
|
.ge(Coupon::getValidUntil, now)
|
|
|
.notIn(!ownedIds.isEmpty(), Coupon::getId, ownedIds)
|
|
.notIn(!ownedIds.isEmpty(), Coupon::getId, ownedIds)
|
|
@@ -277,7 +294,9 @@ public class CouponService {
|
|
|
/** JOIN 权益展示:所有加入赠券模板 */
|
|
/** JOIN 权益展示:所有加入赠券模板 */
|
|
|
public List<Coupon> listJoinRules() {
|
|
public List<Coupon> listJoinRules() {
|
|
|
return couponMapper.selectList(
|
|
return couponMapper.selectList(
|
|
|
- new LambdaQueryWrapper<Coupon>().eq(Coupon::getGrantType, "JOIN"));
|
|
|
|
|
|
|
+ new LambdaQueryWrapper<Coupon>()
|
|
|
|
|
+ .eq(Coupon::getGrantType, "JOIN")
|
|
|
|
|
+ .and(w -> w.isNull(Coupon::getStatus).or().eq(Coupon::getStatus, "ACTIVE")));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** 我的优惠券:返回 user_coupon + coupon 联合数据,含 status/receivedAt/usedAt */
|
|
/** 我的优惠券:返回 user_coupon + coupon 联合数据,含 status/receivedAt/usedAt */
|
|
@@ -296,7 +315,9 @@ public class CouponService {
|
|
|
if (coupon == null) continue;
|
|
if (coupon == null) continue;
|
|
|
// 过期判断
|
|
// 过期判断
|
|
|
String status = uc.getStatus();
|
|
String status = uc.getStatus();
|
|
|
- if ("AVAILABLE".equals(status) && coupon.getValidUntil() != null && now.after(coupon.getValidUntil())) {
|
|
|
|
|
|
|
+ if ("AVAILABLE".equals(status) && !"ACTIVE".equals(coupon.getStatus())) {
|
|
|
|
|
+ status = "DISABLED";
|
|
|
|
|
+ } else if ("AVAILABLE".equals(status) && coupon.getValidUntil() != null && now.after(coupon.getValidUntil())) {
|
|
|
status = "EXPIRED";
|
|
status = "EXPIRED";
|
|
|
}
|
|
}
|
|
|
Map<String, Object> item = new HashMap<>();
|
|
Map<String, Object> item = new HashMap<>();
|