|
|
@@ -10,11 +10,14 @@ import shop.alien.config.redis.BaseRedisService;
|
|
|
import shop.alien.entity.store.*;
|
|
|
import shop.alien.job.feign.AlienStoreFeign;
|
|
|
import shop.alien.mapper.*;
|
|
|
+import shop.alien.util.common.constant.CouponStatusEnum;
|
|
|
+import shop.alien.util.common.constant.DiscountCouponEnum;
|
|
|
import shop.alien.util.type.LifeNoticeUtil;
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
@@ -69,6 +72,12 @@ public class StoreMembershipCardJob {
|
|
|
|
|
|
private final AlienStoreFeign alienStoreFeign;
|
|
|
|
|
|
+ private final LifeDiscountCouponMapper lifeDiscountCouponMapper;
|
|
|
+
|
|
|
+ private final LifeDiscountCouponUserMapper lifeDiscountCouponUserMapper;
|
|
|
+
|
|
|
+ private final LifeCouponMapper lifeCouponMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 会员卡状态及会员卡订单状态变更任务
|
|
|
*/
|
|
|
@@ -178,6 +187,8 @@ public class StoreMembershipCardJob {
|
|
|
if (date.compareTo(sevenDay) >= 0) {
|
|
|
log.info("开始删除已注销超过7天的店铺: storeId={}, storeName={}, logoutTime={}",
|
|
|
storeInfo.getId(), storeInfo.getStoreName(), logoutTime);
|
|
|
+
|
|
|
+ invalidateStoreCoupons(storeInfo.getId());
|
|
|
|
|
|
// 先清理关联的商户用户注销状态,确保可以重新入驻
|
|
|
List<StoreUser> relatedStoreUsers = storeUserMapper.selectList(
|
|
|
@@ -304,4 +315,48 @@ public class StoreMembershipCardJob {
|
|
|
calendar.add(Calendar.DAY_OF_YEAR, LOGOUT_COOLING_DAYS);
|
|
|
return new Date().compareTo(calendar.getTime()) >= 0;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 店铺注销冷静期结束:将该店铺赠出/发行的优惠券全部置为已失效
|
|
|
+ */
|
|
|
+ private void invalidateStoreCoupons(Integer storeId) {
|
|
|
+ if (storeId == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String storeIdStr = String.valueOf(storeId);
|
|
|
+ int voidedUserCouponStatus = Integer.parseInt(DiscountCouponEnum.HAVE_BEEN_VOIDED.getValue());
|
|
|
+
|
|
|
+ lifeDiscountCouponMapper.update(null, new LambdaUpdateWrapper<LifeDiscountCoupon>()
|
|
|
+ .eq(LifeDiscountCoupon::getStoreId, storeIdStr)
|
|
|
+ .set(LifeDiscountCoupon::getCouponStatus, LifeDiscountCoupon.COUPON_STATUS_INVALID)
|
|
|
+ .set(LifeDiscountCoupon::getGetStatus, 0));
|
|
|
+
|
|
|
+ List<LifeDiscountCoupon> storeCoupons = lifeDiscountCouponMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<LifeDiscountCoupon>().eq(LifeDiscountCoupon::getStoreId, storeIdStr));
|
|
|
+ if (!storeCoupons.isEmpty()) {
|
|
|
+ List<Integer> couponIds = storeCoupons.stream().map(LifeDiscountCoupon::getId).collect(Collectors.toList());
|
|
|
+ lifeDiscountCouponUserMapper.update(null, new LambdaUpdateWrapper<LifeDiscountCouponUser>()
|
|
|
+ .in(LifeDiscountCouponUser::getCouponId, couponIds)
|
|
|
+ .eq(LifeDiscountCouponUser::getStatus, Integer.parseInt(DiscountCouponEnum.WAITING_USED.getValue()))
|
|
|
+ .set(LifeDiscountCouponUser::getStatus, voidedUserCouponStatus));
|
|
|
+ }
|
|
|
+
|
|
|
+ lifeCouponMapper.update(null, new LambdaUpdateWrapper<LifeCoupon>()
|
|
|
+ .eq(LifeCoupon::getStoreId, storeIdStr)
|
|
|
+ .notIn(LifeCoupon::getStatus, CouponStatusEnum.ENDED.getCode(), CouponStatusEnum.INVALID.getCode())
|
|
|
+ .set(LifeCoupon::getStatus, CouponStatusEnum.INVALID.getCode()));
|
|
|
+
|
|
|
+ List<LifeCoupon> storeVouchers = lifeCouponMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<LifeCoupon>().eq(LifeCoupon::getStoreId, storeIdStr));
|
|
|
+ if (!storeVouchers.isEmpty()) {
|
|
|
+ List<String> voucherIds = storeVouchers.stream().map(LifeCoupon::getId).collect(Collectors.toList());
|
|
|
+ lifeDiscountCouponUserMapper.update(null, new LambdaUpdateWrapper<LifeDiscountCouponUser>()
|
|
|
+ .in(LifeDiscountCouponUser::getVoucherId, voucherIds)
|
|
|
+ .eq(LifeDiscountCouponUser::getStatus, Integer.parseInt(DiscountCouponEnum.WAITING_USED.getValue()))
|
|
|
+ .set(LifeDiscountCouponUser::getStatus, voidedUserCouponStatus));
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("店铺优惠券已失效处理完成: storeId={}, templateCount={}, voucherCount={}",
|
|
|
+ storeId, storeCoupons.size(), storeVouchers.size());
|
|
|
+ }
|
|
|
}
|