package com.yeshi.fanli.service.impl.user.vip;
|
|
import java.util.Collections;
|
import java.util.Comparator;
|
import java.util.Date;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import com.yeshi.fanli.dao.mybatis.user.vip.UserVIPPreInfoMapper;
|
import com.yeshi.fanli.dto.msg.MsgAccountVipDTO;
|
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
|
import com.yeshi.fanli.entity.bus.user.UserInfo;
|
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.msg.MsgAccountDetailService;
|
import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService;
|
import com.yeshi.fanli.util.Constant;
|
import com.yeshi.fanli.util.TimeUtil;
|
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 MsgAccountDetailService msgAccountDetailService;
|
|
@Override
|
public void addUserVIPPreInfo(UserVIPPreInfo info) throws UserVIPPreInfoException {
|
if (info == null || info.getUid() == null || info.getProcess() == null)
|
throw new UserVIPPreInfoException(1, "信息不完整");
|
|
UserVIPPreInfo oldInfo = userVIPPreInfoMapper.selectByUidAndProcess(info.getUid(), info.getProcess());
|
if (oldInfo != null)
|
throw new UserVIPPreInfoException(2, "进度已存在");
|
if (info.getCreateTime() == null)
|
info.setCreateTime(new Date());
|
userVIPPreInfoMapper.insertSelective(info);
|
}
|
|
@Override
|
public UserVIPPreInfo getLatestProcessInfo(Long uid) {
|
List<UserVIPPreInfo> infoList = userVIPPreInfoMapper.listByUid(uid);
|
if (infoList == null || infoList.size() == 0)
|
return null;
|
|
Comparator<UserVIPPreInfo> cm = new Comparator<UserVIPPreInfo>() {
|
|
@Override
|
public int compare(UserVIPPreInfo o1, UserVIPPreInfo o2) {
|
return o2.getProcess() - o1.getProcess();
|
}
|
};
|
|
Collections.sort(infoList, cm);
|
return infoList.get(0);
|
}
|
|
@Override
|
public UserVIPPreInfo getProcessInfo(Long uid, Date time) {
|
List<UserVIPPreInfo> infoList = userVIPPreInfoMapper.listByUid(uid);
|
if (infoList == null || infoList.size() == 0)
|
return null;
|
Comparator<UserVIPPreInfo> cm = new Comparator<UserVIPPreInfo>() {
|
|
@Override
|
public int compare(UserVIPPreInfo o1, UserVIPPreInfo o2) {
|
return o2.getProcess() - o1.getProcess();
|
}
|
};
|
Collections.sort(infoList, cm);
|
|
for (UserVIPPreInfo info : infoList) {
|
if (time.getTime() >= info.getCreateTime().getTime())
|
return info;
|
}
|
return null;
|
}
|
|
@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) {
|
boolean process = false;
|
String msg = "";
|
if (countZiGou >= Constant.VIP_PROCESS_1_ZIGOU) {
|
process = true;
|
msg = "恭喜你!返利订单达到 " + Constant.VIP_PROCESS_1_ZIGOU + "笔";
|
} else if (countShare >= Constant.VIP_PROCESS_1_SHARE) {
|
process = true;
|
msg = "恭喜你!分享订单达到 " + Constant.VIP_PROCESS_1_SHARE + "笔";
|
} else if (firstTeam >= Constant.VIP_PROCESS_1_TEAM && secondTeam >= Constant.VIP_PROCESS_1_TEAM_SECOND) {
|
process = true;
|
msg = "直接粉丝达到" + Constant.VIP_PROCESS_1_TEAM + "人,间接粉丝达到 " + Constant.VIP_PROCESS_1_TEAM_SECOND + "人";
|
}
|
|
if (process) {
|
try {
|
UserVIPPreInfo info = new UserVIPPreInfo();
|
info.setUid(uid);
|
info.setProcess(UserVIPPreInfo.PROCESS_1);
|
info.setCreateTime(new Date());
|
info.setUpdateTime(new Date());
|
addUserVIPPreInfo(info);
|
|
// 消息
|
MsgAccountVipDTO msgDto = new MsgAccountVipDTO();
|
msgDto.setStatus("系统已将你的账户由快省达人升级为普通会员");
|
msgDto.setEquity("从收到本消息起,你将获得全部普通会员权益");
|
msgAccountDetailService.addMsgVIP(uid, msg, "如有疑问请联系我的-人工客服", msgDto);
|
} catch (UserVIPPreInfoException e) {
|
e.printStackTrace();
|
}
|
}
|
return process;
|
}
|
|
/**
|
* 二阶段
|
*
|
* @param uid
|
* @param countZiGou
|
* @param countShare
|
* @param firstTeam
|
* @param secondTeam
|
*/
|
private boolean twoProcess(Long uid, long countZiGou, long countShare, long firstTeam, long secondTeam) {
|
boolean process = false;
|
String msg = "";
|
if (countZiGou >= Constant.VIP_PROCESS_2_ZIGOU) {
|
process = true;
|
msg = "恭喜你!返利订单达到 " + Constant.VIP_PROCESS_2_ZIGOU + "笔";
|
} else if (countShare >= Constant.VIP_PROCESS_2_SHARE) {
|
process = true;
|
msg = "恭喜你!分享订单达到 " + Constant.VIP_PROCESS_2_SHARE + "笔";
|
} else if (firstTeam >= Constant.VIP_PROCESS_2_TEAM && secondTeam >= Constant.VIP_PROCESS_2_TEAM_SECOND) {
|
process = true;
|
msg = "直接粉丝达到" + Constant.VIP_PROCESS_2_TEAM + "人,间接粉丝达到 " + Constant.VIP_PROCESS_2_TEAM_SECOND + "人";
|
}
|
|
if (process) {
|
try {
|
UserVIPPreInfo info = new UserVIPPreInfo();
|
info.setUid(uid);
|
info.setProcess(UserVIPPreInfo.PROCESS_2);
|
info.setCreateTime(new Date());
|
info.setUpdateTime(new Date());
|
addUserVIPPreInfo(info);
|
|
// 消息
|
MsgAccountVipDTO msgDto = new MsgAccountVipDTO();
|
msgDto.setStatus("系统已将你的账户由普通会员升级为高级会员");
|
msgDto.setEquity("从收到本消息起,你将获得全部高级会员权益");
|
msgAccountDetailService.addMsgVIP(uid, msg, "如有疑问请联系我的-人工客服", msgDto);
|
} catch (UserVIPPreInfoException e) {
|
e.printStackTrace();
|
}
|
}
|
return process;
|
}
|
|
}
|