yujian
2020-05-06 eb1adc13eda955e8ef0fc9fe41fb246fa89b722d
fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/UserVIPInfoServiceImpl.java
@@ -24,6 +24,7 @@
import com.yeshi.fanli.entity.bus.user.vip.UserVIPInfo;
import com.yeshi.fanli.entity.bus.user.vip.UserVIPPreInfo;
import com.yeshi.fanli.exception.user.vip.UserVIPInfoException;
import com.yeshi.fanli.exception.user.vip.UserVIPPreInfoException;
import com.yeshi.fanli.service.inter.count.HongBaoV2CountService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
@@ -56,30 +57,26 @@
   @Resource
   private HongBaoV2CountService hongBaoV2CountService;
   @Resource
   private ThreeSaleSerivce threeSaleSerivce;
   @Resource
   private UserVIPPreInfoService userVIPPreInfoService;
   @Resource
   private UserAccountMsgNotificationService userAccountMsgNotificationService;
   @Resource
   private UserInviteValidNumService userInviteValidNumService;
   @Resource
   private UserLevelUpgradedNotifyService userLevelUpgradedNotifyService;
   @Resource
   private UserInviteMsgNotificationService userInviteMsgNotificationService;
   @Resource(name = "producer")
   private Producer producer;
   @Override
   @Transactional(rollbackFor = Exception.class)
@@ -96,7 +93,6 @@
      info.setCreateTime(new Date());
      userVIPInfoMapper.insert(info);
   }
   @Override
   public boolean isVIP(Long uid) {
@@ -139,7 +135,6 @@
      return map;
   }
   @Override
   public List<UserVIPInfo> listQuery(int page, int count, String key, Integer state) {
      return userVIPInfoMapper.listQuery((page - 1) * count, count, key, state);
@@ -149,7 +144,6 @@
   public long countQuery(String key, Integer state) {
      return userVIPInfoMapper.countQuery(key, state);
   }
   @Transactional(rollbackFor = Exception.class)
   @Override
@@ -198,7 +192,7 @@
      if (!verifyVip(uid))
         throw new UserVIPInfoException(1, "系统验证:不满足升级条件");
      Date upgradeTime = new Date();
      // 通过超级会员
      UserVIPInfo info = new UserVIPInfo();
@@ -208,6 +202,17 @@
      info.setUpdateTime(upgradeTime);
      userVIPInfoMapper.updateByPrimaryKeySelective(info);
      UserVIPPreInfo preInfo = new UserVIPPreInfo();
      preInfo.setCreateTime(new Date());
      preInfo.setProcess(UserLevelEnum.superVIP.getLevel());
      preInfo.setUid(uid);
      try {
         userVIPPreInfoService.addUserVIPPreInfo(preInfo);
      } catch (UserVIPPreInfoException e1) {
         throw new UserVIPInfoException(100, "升级失败");
      }
      // 升级弹框提示
      UserLevelUpgradedNotify notify = new UserLevelUpgradedNotify();
      notify.setUid(uid);
@@ -216,31 +221,32 @@
      notify.setValid(true);
      notify.setCreateTime(new Date());
      userLevelUpgradedNotifyService.addUserLevelUpgradedNotify(notify);
      try {
         // 升级消息
         UserVIPPreInfo pre1 = userVIPPreInfoService.getVipByProcess(uid, UserVIPPreInfo.PROCESS_2);
         userAccountMsgNotificationService.vipUpgradeSuccess(uid, TimeUtil.getDayDifferenceCount(pre1.getCreateTime(), new Date()));
         userAccountMsgNotificationService.vipUpgradeSuccess(uid,
               TimeUtil.getDayDifferenceCount(pre1.getCreateTime(), new Date()));
         // 直接粉丝升级提醒
         ThreeSale threeSale = threeSaleSerivce.getMyBoss(uid);
         if (threeSale != null) {
            Long bossId = threeSale.getBoss().getId();
            UserInfo userInfo = userInfoService.selectByPKey(uid);
            userInviteMsgNotificationService.fansUpgrade(bossId,  "超级会员", userInfo.getNickName(), getPassItem(uid), upgradeTime);
            userInviteMsgNotificationService.fansUpgrade(bossId, "超级会员", userInfo.getNickName(), getPassItem(uid),
                  upgradeTime);
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
      if (!Constant.IS_TEST) {
         UserLevelChangedMQMsg msg = new UserLevelChangedMQMsg(uid, UserLevelEnum.highVIP,UserLevelEnum.superVIP, new Date());
         UserLevelChangedMQMsg msg = new UserLevelChangedMQMsg(uid, UserLevelEnum.highVIP, UserLevelEnum.superVIP,
               new Date());
         Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userLevelChanged, msg);
         producer.send(message);
      }
   }
   /**
    * 验证是否符合VIP
@@ -264,19 +270,19 @@
      if (!StringUtil.isNullOrEmpty(zigou)) {
         limitOrder = Long.parseLong(zigou);
      }
      long limitFirst = 0;
      String first = userVipConfigService.getValueByKey("vip_pre_10_first_level_team_count");
      if (!StringUtil.isNullOrEmpty(first)) {
         limitFirst = Long.parseLong(first);
      }
      long limitSecond = 0;
      String second = userVipConfigService.getValueByKey("vip_pre_10_second_level_team_count");
      if (!StringUtil.isNullOrEmpty(second)) {
         limitSecond = Long.parseLong(second);
      }
      String item = "";
      if (doneOrder >= limitOrder) {
         item = "返利+分享订单";
@@ -285,8 +291,7 @@
      }
      return item;
   }
   /**
    * 验证是否符合VIP
    * @param uid
@@ -308,20 +313,20 @@
      if (!StringUtil.isNullOrEmpty(zigou)) {
         limitOrder = Long.parseLong(zigou);
      }
      long limitFirst = 0;
      String first = userVipConfigService.getValueByKey("vip_pre_10_first_level_team_count");
      if (!StringUtil.isNullOrEmpty(first)) {
         limitFirst = Long.parseLong(first);
      }
      long limitSecond = 0;
      String second = userVipConfigService.getValueByKey("vip_pre_10_second_level_team_count");
      if (!StringUtil.isNullOrEmpty(second)) {
         limitSecond = Long.parseLong(second);
      }
      if (doneOrder >= limitOrder  || (doneFirst >= limitFirst && doneSecond >= limitSecond)) {
      if (doneOrder >= limitOrder || (doneFirst >= limitFirst && doneSecond >= limitSecond)) {
         return true;
      }
      return false;
@@ -342,9 +347,15 @@
      info.setId(userInfo.getId());
      info.setState(UserVIPInfo.STATE_INVALID);
      info.setUpdateTime(new Date());
      info.setBeiZhu(reason);
      userVIPInfoMapper.updateByPrimaryKeySelective(info);
      // 消息
      userAccountMsgNotificationService.vipUpgradeFail(uid, reason);
   }
   @Override
   public void deleteByPrimaryKey(Long id) {
      userVIPInfoMapper.deleteByPrimaryKey(id);
   }
}