| | |
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.hibernate.annotations.LazyCollection;
|
| | | import org.springframework.context.annotation.Lazy;
|
| | | 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.ThreeSale;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | 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.log.LogHelper;
|
| | | 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;
|
| | |
|
| | | @Override
|
| | | public void addUserVIPPreInfo(UserVIPPreInfo info) throws UserVIPPreInfoException {
|
| | |
| | | return infoList.get(0);
|
| | | }
|
| | |
|
| | | @RequestSerializableByKeyService(key = "#uid")
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void verifyVipPreInfo(Long uid, boolean inviteSuccess) {
|
| | | if (uid == null || uid <= 0)
|
| | | return;
|
| | | |
| | | verifyCondition(uid);
|
| | | |
| | | // 验证上级
|
| | | if (inviteSuccess) {
|
| | | UserInfo boss = threeSaleSerivce.getBoss(uid);
|
| | | if (boss != null) {
|
| | | verifyVipPreInfoBoss(boss.getId());
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // 上级验证
|
| | | private void verifyVipPreInfoBoss(Long uid) {
|
| | | if (uid == null || uid <= 0)
|
| | | return;
|
| | |
|
| | | verifyCondition(uid);
|
| | | }
|
| | |
|
| | | private void verifyCondition(Long uid) {
|
| | | try {
|
| | | // 验证二阶段
|
| | | UserVIPPreInfo oldInfo = userVIPPreInfoMapper.selectByUidAndProcess(uid, UserVIPPreInfo.PROCESS_2);
|
| | | if (oldInfo != null) {
|
| | | 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;
|
| | | }
|
| | |
|
| | | // 二阶段
|
| | | twoProcess(uid, countZiGou, countShare, firstTeam, secondTeam);
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 一阶段
|
| | | * |
| | | * @param uid
|
| | | * @param countZiGou
|
| | | * @param countShare
|
| | | * @param firstTeam
|
| | | * @param secondTeam
|
| | | */
|
| | | private boolean oneProcess(Long uid, long countZiGou, long countShare, long firstTeam, long secondTeam) {
|
| | | 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) {
|
| | | 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;
|
| | | }
|
| | |
|
| | | }
|