Pu Zhibing
2025-01-24 c9c63baa6aca084be7a9302f240c080c9ab1454b
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/AppUserServiceImpl.java
@@ -25,6 +25,7 @@
import com.ruoyi.common.redis.annotation.DistributedLock;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.order.feignClient.OrderClient;
import com.ruoyi.other.api.domain.*;
import com.ruoyi.other.api.feignClient.*;
import com.ruoyi.system.api.domain.SysUser;
@@ -111,6 +112,9 @@
   private RedisTemplate redisTemplate;
   @Resource
   private BalancePaymentService balancePaymentService;
   @Resource
   private OrderClient orderClient;
   /**
@@ -673,7 +677,7 @@
            return;
         }
      }
      if(appUser.getVipId() > 2){
      if(appUser.getVipId() >= 2){
         appUser.setVipId(1);
         this.updateById(appUser);
         //添加等级变化记录
@@ -865,7 +869,6 @@
   @Override
   public void unbindThePromoter() {
      //注册X天后没有升级成黄金会员则自动解绑推广人
      //解绑推广人
      Set<Long> unbind_promoter = redisTemplate.opsForZSet().rangeByScore("unbind_promoter", 0, LocalDateTime.now().toEpochSecond(ZoneOffset.UTC));
      if(unbind_promoter.size() > 0){
@@ -876,16 +879,21 @@
            updateWrapper.set("invite_user_id", null).set("shop_id", null).eq("id", appUser.getId());
            this.update(updateWrapper);
         }
         redisTemplate.opsForZSet().remove("unbind_promoter", unbind_promoter.toArray());
      }
      //可更换推广人
      Set<Long> replaceable = redisTemplate.opsForZSet().rangeByScore("replaceable", 0, LocalDateTime.now().toEpochSecond(ZoneOffset.UTC));
      if(replaceable.size() > 0){
         List<AppUser> list = this.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0).eq(AppUser::getChangePromoter, 0)
               .eq(AppUser::getStatus, 1).in(AppUser::getId, unbind_promoter));
               .eq(AppUser::getStatus, 1).in(AppUser::getId, replaceable));
         for (AppUser appUser : list) {
            appUser.setChangePromoter(1);
            this.updateById(appUser);
            Long data = orderClient.getOrderCountByAppUserId(appUser.getId()).getData();
            if(data == 0){
               appUser.setChangePromoter(1);
               this.updateById(appUser);
            }
         }
         redisTemplate.opsForZSet().remove("replaceable", replaceable.toArray());
      }
   }
   
@@ -982,7 +990,7 @@
         List<AppUser> list = this.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getVipId, i).eq(AppUser::getStatus, 1).eq(AppUser::getDelFlag, 0).eq(AppUser::getIsDanger, 0));
         for (AppUser appUser : list) {
            //消费积分
            List<UserPoint> list1 = userPointService.list(new LambdaQueryWrapper<UserPoint>().eq(UserPoint::getAppUserId, appUser.getId()).eq(UserPoint::getType, 1).last(" and SUBDATE(now(), INTERVAL " + vipSetting.getKeepBuyDay() + " DAY) >= create_time"));
            List<UserPoint> list1 = userPointService.list(new LambdaQueryWrapper<UserPoint>().eq(UserPoint::getAppUserId, appUser.getId()).eq(UserPoint::getType, 1).last(" and SUBDATE(now(), INTERVAL " + vipSetting.getKeepBuyDay() + " DAY) <= create_time"));
            int sum = list1.stream().mapToInt(UserPoint::getVariablePoint).sum();
            if(sum < vipSetting.getKeepBuyPoint()){
               appUser.setIsDanger(1);
@@ -990,7 +998,7 @@
               continue;
            }
            //返佣积分
            list1 = userPointService.list(new LambdaQueryWrapper<UserPoint>().eq(UserPoint::getAppUserId, appUser.getId()).eq(UserPoint::getType, 2).last(" and SUBDATE(now(), INTERVAL " + vipSetting.getKeepShareDay() + " DAY) >= create_time"));
            list1 = userPointService.list(new LambdaQueryWrapper<UserPoint>().eq(UserPoint::getAppUserId, appUser.getId()).eq(UserPoint::getType, 2).last(" and SUBDATE(now(), INTERVAL " + vipSetting.getKeepShareDay() + " DAY) <= create_time"));
            sum = list1.stream().mapToInt(UserPoint::getVariablePoint).sum();
            if(sum < vipSetting.getKeepSharePoint()){
               appUser.setIsDanger(1);
@@ -998,7 +1006,7 @@
               continue;
            }
            //门店业绩
            list1 = userPointService.list(new LambdaQueryWrapper<UserPoint>().eq(UserPoint::getAppUserId, appUser.getId()).eq(UserPoint::getType, 8).last(" and SUBDATE(now(), INTERVAL " + vipSetting.getKeepShopDay() + " DAY) >= create_time"));
            list1 = userPointService.list(new LambdaQueryWrapper<UserPoint>().eq(UserPoint::getAppUserId, appUser.getId()).eq(UserPoint::getType, 8).last(" and SUBDATE(now(), INTERVAL " + vipSetting.getKeepShopDay() + " DAY) <= create_time"));
            sum = list1.stream().mapToInt(UserPoint::getVariablePoint).sum();
            if(sum < vipSetting.getKeepShopPoint()){
               appUser.setIsDanger(1);