yujian
2020-03-24 88c7df1d5089d8e39f356a68eaccc18f308e190c
fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/UserVIPInfoServiceImpl.java
@@ -92,14 +92,12 @@
   @Lazy
   @Resource
   private UserSystemCouponService userSystemCouponService;
   @Resource
   private UserVIPPreInfoService userVIPPreInfoService;
   @Resource
   private MsgAccountDetailService msgAccountDetailService;
   @Override
   @Transactional(rollbackFor = Exception.class)
@@ -271,8 +269,14 @@
   @Override
   public boolean isVIP(Long uid) {
      return isVIP(uid, System.currentTimeMillis());
   }
   @Override
   public boolean isVIP(Long uid, Long time) {
      UserVIPInfo userInfo = userVIPInfoMapper.selectByPrimaryKey(uid);
      if (userInfo != null && userInfo.getState() == UserVIPInfo.STATE_SUCCESS)
      if (userInfo != null && userInfo.getState() == UserVIPInfo.STATE_SUCCESS
            && userInfo.getSuccessTime().getTime() < time)
         return true;
      else
         return false;
@@ -315,29 +319,26 @@
      // 1、直接粉丝(从 2020 年 1 月 1 日起直接粉丝产生有效订单)
      BigDecimal payMoney = new BigDecimal(userVipConfigService.getValueByKey("require_order_pay"));
//      long teamNum = hongBaoV2CountService.countValidOrderTeamUserByUid(uid,
//            TimeUtil.convertDateToTemp(Constant.VIP_ONLINE_TIME), payMoney);
      // long teamNum =
      // hongBaoV2CountService.countValidOrderTeamUserByUid(uid,
      // TimeUtil.convertDateToTemp(Constant.VIP_ONLINE_TIME), payMoney);
      long teamNum = 0L;
      long vipBegin = TimeUtil.convertDateToTemp(Constant.VIP_ONLINE_TIME);
      List<ThreeSale> listThreeSale = threeSaleSerivce.getValidWorkerIdsByTime(uid, vipBegin);
      if (listThreeSale != null && listThreeSale.size() > 0) {
         for (ThreeSale three: listThreeSale) {
         for (ThreeSale three : listThreeSale) {
            UserInfo worker = three.getWorker();
            if (worker == null || worker.getId() == null) {
               continue;
            }
            // 1、邀请关系成功后;2、单(分享 + 自购)实付款大于1元
            long countValid = hongBaoV2CountService.countValidOrderByUidAndTime(worker.getId(), three.getSucceedTime(), payMoney);
            long countValid = hongBaoV2CountService.countValidOrderByUidAndTime(worker.getId(),
                  three.getSucceedTime(), payMoney);
            if (countValid > 0) {
               teamNum ++;
               teamNum++;
            }
         }
      }
      // 区分老用户和新用户
      String limtDate = userVipConfigService.getValueByKey("vip_execute_time");
@@ -450,18 +451,17 @@
      }
   }
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void applyVIPNew(Long uid) throws UserVIPInfoException {
      UserVIPPreInfo latestProcess = userVIPPreInfoService.getLatestProcessInfo(uid);
      if (latestProcess == null || latestProcess.getProcess() != UserVIPPreInfo.PROCESS_2) {
         throw new UserVIPInfoException(1, "该用户还不是高级会员");
      }
      }
      if (!verifyVipNew(uid))
         throw new UserVIPInfoException(1, "系统验证:不满足升级条件");
      UserVIPInfo userInfo = userVIPInfoMapper.selectByPrimaryKeyForUpdate(uid);
      if (userInfo == null) {
         userInfo = new UserVIPInfo();
@@ -479,8 +479,7 @@
      info.setState(UserVIPInfo.STATE_VERIFING);
      info.setUpdateTime(new Date());
      userVIPInfoMapper.updateByPrimaryKeySelective(info);
      MsgAccountDetail detail = new MsgAccountDetail();
      detail.setTitle("尊敬的高级会员,系统已收到你的超级会员升级申请,正在受理中");
      detail.setBeiZhu("如有疑问请联系我的-人工客服");
@@ -495,9 +494,7 @@
         e.printStackTrace();
      }
   }
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void passVIPApplyNew(Long uid) throws UserVIPInfoException {
@@ -508,15 +505,15 @@
      if (userVIPInfo.getState() != UserVIPInfo.STATE_VERIFING) {
         throw new UserVIPInfoException(2, "申请未处于审核状态");
      }
      UserVIPPreInfo latestProcess = userVIPPreInfoService.getLatestProcessInfo(uid);
      if (latestProcess == null || latestProcess.getProcess() != UserVIPPreInfo.PROCESS_2) {
         throw new UserVIPInfoException(1, "该用户还不是高级会员");
      }
      }
      if (!verifyVipNew(uid))
         throw new UserVIPInfoException(1, "系统验证:不满足升级条件");
      // 额外信息
      UserInfoExtra userInfoExtra = userInfoExtraService.getByUidForUpdate(uid);
      if (userInfoExtra == null)
@@ -540,7 +537,7 @@
      detail.setCreateTime(new Date());
      detail.setUniqueKey("VIP-" + uid);
      integralDetailService.insertSelective(detail);
      try {
         // 奖励券
         BigDecimal percent = new BigDecimal(configService.get(ConfigKeyEnum.exchangeRebatePercent.getKey()));
@@ -558,15 +555,13 @@
         throw new UserVIPInfoException(1, "券赠送失败");
      }
      // 消息
      MsgAccountVipDTO msgDto = new MsgAccountVipDTO();
      msgDto.setStatus("已将你的账户由高级会员升级为超级会员");
      msgDto.setEquity("从收到本消息起,你将获得全部超级会员权益");
      msgAccountDetailService.addMsgVIP(uid, "恭喜你!经人工审核你满足升级超级会员条件", "如有疑问请联系我的-人工客服", msgDto);
   }
   /**
    * 验证是否符合VIP
    * @param uid
@@ -582,15 +577,14 @@
      // 队员
      long firstTeam = threeSaleSerivce.countFirstTeam(uid, 1);
      long secondTeam = threeSaleSerivce.countSecondTeam(uid, 1);
      if (countZiGou >= Constant.VIP_PROCESS_3_ZIGOU || countShare >= Constant.VIP_PROCESS_3_SHARE
            || (firstTeam >= Constant.VIP_PROCESS_3_TEAM && secondTeam >= Constant.VIP_PROCESS_3_TEAM_SECOND)) {
         return true;
      }
      }
      return false;
   }
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void rejectVIPApplyNew(Long uid, String reason) throws UserVIPInfoException {
@@ -607,11 +601,12 @@
      info.setState(UserVIPInfo.STATE_INVALID);
      info.setUpdateTime(new Date());
      userVIPInfoMapper.updateByPrimaryKeySelective(info);
      // 消息
      MsgAccountVipDTO msgDto = new MsgAccountVipDTO();
      msgDto.setStatus("你的账号仍是高级会员");
      msgDto.setReason(reason);
      msgAccountDetailService.addMsgVIP(uid, "很抱歉!经人工审核你未满足或不符合升级超级会员的条件", "如有疑问请联系我的-人工客服", msgDto);
   }
}