admin
2020-03-17 b85fb24ab565ab70f6648cc09d93ba9ff1fc6b57
fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/UserVIPPreInfoServiceImpl.java
@@ -7,24 +7,44 @@
import javax.annotation.Resource;
import com.yeshi.fanli.dao.mybatis.user.vip.UserVIPPreInfoMapper;
import com.yeshi.fanli.entity.bus.user.vip.UserVIPPreInfo;
import com.yeshi.fanli.exception.user.vip.UserVIPInfoException;
import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.dao.mybatis.user.vip.UserVIPPreInfoMapper;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
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.UserVIPPreInfoException;
import com.yeshi.fanli.service.inter.count.HongBaoV2CountService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.annotation.RequestSerializableByKeyService;
@Service
public class UserVIPPreInfoServiceImpl implements UserVIPPreInfoService {
   @Resource
   private UserVIPPreInfoMapper userVIPPreInfoMapper;
   @Resource
   private HongBaoV2CountService hongBaoV2CountService;
   @Resource
   private ThreeSaleSerivce threeSaleSerivce;
   @Resource
   private UserVIPInfoService userVIPInfoService;
   @Override
   public void addUserVIPPreInfo(UserVIPPreInfo info) throws UserVIPInfoException {
   public void addUserVIPPreInfo(UserVIPPreInfo info) throws UserVIPPreInfoException {
      if (info == null || info.getUid() == null || info.getProcess() == null)
         throw new UserVIPInfoException(1, "信息不完整");
         throw new UserVIPPreInfoException(1, "信息不完整");
      UserVIPPreInfo oldInfo = userVIPPreInfoMapper.selectByUidAndProcess(info.getUid(), info.getProcess());
      if (oldInfo != null)
         throw new UserVIPInfoException(2, "进度已存在");
         throw new UserVIPPreInfoException(2, "进度已存在");
      if (info.getCreateTime() == null)
         info.setCreateTime(new Date());
      userVIPPreInfoMapper.insertSelective(info);
@@ -48,4 +68,117 @@
      return infoList.get(0);
   }
   @RequestSerializableByKeyService(key = "#uid")
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void verifyVipCondition(Long uid) {
      if (uid == null || uid <= 0)
         return;
      // 验证是否VIP
      boolean vip = userVIPInfoService.isVIP(uid);
      if (vip) {
         return;
      }
      // 邀请订单
      long countZiGou = hongBaoV2CountService.counOrderByUidAndOrderType(uid, Constant.VIP_ORDER_PAY, HongBaoV2.TYPE_ZIGOU);
      // 邀请订单
      long countShare = hongBaoV2CountService.counOrderByUidAndOrderType(uid, Constant.VIP_ORDER_PAY, HongBaoV2.TYPE_SHARE_GOODS);
      // 队员
      long firstTeam = threeSaleSerivce.countFirstTeam(uid, 1);
      long secondTeam = threeSaleSerivce.countSecondTeam(uid, 1);
      // 一阶段
      boolean process1 = oneProcess(uid, countZiGou, countShare, firstTeam, secondTeam);
      if (!process1) {
         return;
      }
      // 一阶段
      boolean process2 = twoProcess(uid, countZiGou, countShare, firstTeam, secondTeam);
      if (!process2) {
         return;
      }
      vipProcess(uid, countZiGou, countShare, firstTeam, secondTeam);
   }
   /**
    * 一阶段
    * @param uid
    * @param countZiGou
    * @param countShare
    * @param firstTeam
    * @param secondTeam
    */
   private boolean oneProcess(Long uid, long countZiGou, long countShare, long firstTeam, long secondTeam) {
      UserVIPPreInfo oldInfo = userVIPPreInfoMapper.selectByUidAndProcess(uid, UserVIPPreInfo.PROCESS_1);
      if (oldInfo != null) {
         return true;
      }
      if (countZiGou >= Constant.VIP_PROCESS_1_ZIGOU || countShare >= Constant.VIP_PROCESS_1_SHARE
            || (firstTeam >= Constant.VIP_PROCESS_1_TEAM && secondTeam >= Constant.VIP_PROCESS_1_TEAM_SECOND)) {
         UserVIPPreInfo info = new UserVIPPreInfo();
         info.setUid(uid);
         info.setProcess(UserVIPPreInfo.PROCESS_1);
         info.setCreateTime(new Date());
         info.setUpdateTime(new Date());
         userVIPPreInfoMapper.insertSelective(info);
         return true;
      }
      return false;
   }
   /**
    * 一阶段
    * @param uid
    * @param countZiGou
    * @param countShare
    * @param firstTeam
    * @param secondTeam
    */
   private boolean twoProcess(Long uid, long countZiGou, long countShare, long firstTeam, long secondTeam) {
      UserVIPPreInfo oldInfo = userVIPPreInfoMapper.selectByUidAndProcess(uid, UserVIPPreInfo.PROCESS_2);
      if (oldInfo != null) {
         return true;
      }
      if (countZiGou >= Constant.VIP_PROCESS_2_ZIGOU || countShare >= Constant.VIP_PROCESS_2_SHARE
            || (firstTeam >= Constant.VIP_PROCESS_2_TEAM && secondTeam >= Constant.VIP_PROCESS_2_TEAM_SECOND)) {
         UserVIPPreInfo info = new UserVIPPreInfo();
         info.setUid(uid);
         info.setProcess(UserVIPPreInfo.PROCESS_2);
         info.setCreateTime(new Date());
         info.setUpdateTime(new Date());
         userVIPPreInfoMapper.insertSelective(info);
         return true;
      }
      return false;
   }
   /**
    * 一阶段
    * @param uid
    * @param countZiGou
    * @param countShare
    * @param firstTeam
    * @param secondTeam
    */
   private boolean vipProcess(Long uid, long countZiGou, long countShare, long firstTeam, long secondTeam) {
      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;
   }
}