| | |
| | | package com.yeshi.fanli.service.impl.user.vip;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import com.yeshi.fanli.entity.SystemEnum;
|
| | | import org.springframework.context.annotation.Lazy;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.aliyun.openservices.ons.api.Message;
|
| | | import com.aliyun.openservices.ons.api.Producer;
|
| | | import com.yeshi.fanli.dao.mybatis.user.vip.UserVIPInfoMapper;
|
| | | import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum;
|
| | | import com.yeshi.fanli.dto.mq.user.body.UserLevelChangedMQMsg;
|
| | | import com.yeshi.fanli.entity.bus.user.ThreeSale;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInviteValidNum;
|
| | | import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
|
| | | import com.yeshi.fanli.entity.bus.user.vip.UserLevelUpgradedNotify;
|
| | | import com.yeshi.fanli.entity.bus.user.vip.UserVIPInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.vip.UserVIPPreInfo;
|
| | | import com.yeshi.fanli.entity.common.Config;
|
| | | import com.yeshi.fanli.entity.system.ConfigKeyEnum;
|
| | | import com.yeshi.fanli.exception.user.vip.UserVIPInfoException;
|
| | | import com.yeshi.fanli.exception.user.vip.UserVIPPreInfoException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | 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;
|
| | | import com.yeshi.fanli.service.inter.user.invite.UserInviteMsgNotificationService;
|
| | | import com.yeshi.fanli.service.inter.user.invite.UserInviteValidNumService;
|
| | | import com.yeshi.fanli.service.inter.user.msg.UserAccountMsgNotificationService;
|
| | | import com.yeshi.fanli.service.inter.user.vip.UserLevelUpgradedNotifyService;
|
| | | import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.vip.UserVipConfigService;
|
| | | import com.yeshi.fanli.service.manger.msg.RocketMQManager;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.util.email.MailSenderUtil;
|
| | | import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory;
|
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName;
|
| | |
|
| | | @Service
|
| | | public class UserVIPInfoServiceImpl implements UserVIPInfoService {
|
| | |
|
| | | @Resource
|
| | | private UserVIPInfoMapper userVIPInfoMapper;
|
| | |
|
| | | @Resource
|
| | | private UserInfoService userInfoService;
|
| | |
|
| | | @Resource
|
| | | private UserVipConfigService userVipConfigService;
|
| | |
|
| | | @Lazy
|
| | | @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
|
| | | private RocketMQManager rocketMQManager;
|
| | |
|
| | | @Resource
|
| | | private ConfigService configService;
|
| | |
|
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void addUserVIPInfo(UserVIPInfo info) throws UserVIPInfoException {
|
| | | if (info.getId() == null) {
|
| | | throw new UserVIPInfoException(1, "信息不完整");
|
| | | }
|
| | | UserVIPInfo userInfo = userVIPInfoMapper.selectByPrimaryKey(info.getId());
|
| | | if (userInfo != null) {
|
| | | throw new UserVIPInfoException(1, "信息已存在");
|
| | | }
|
| | | // 初始化状态
|
| | | info.setState(UserVIPInfo.STATE_INVALID);
|
| | | info.setCreateTime(new Date());
|
| | | userVIPInfoMapper.insert(info);
|
| | | }
|
| | |
|
| | | @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
|
| | | && userInfo.getSuccessTime().getTime() < time)
|
| | | return true;
|
| | | else
|
| | | return false;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public UserVIPInfo selectByUid(Long uid) {
|
| | | UserVIPInfo userInfo = userVIPInfoMapper.selectByPrimaryKey(uid);
|
| | | return userInfo;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Map<Long, Boolean> listByUids(List<Long> uids) {
|
| | | if (uids == null || uids.size() == 0)
|
| | | return new HashMap<>();
|
| | | List<UserVIPInfo> infoList = userVIPInfoMapper.listByUids(uids);
|
| | | // 整理数据
|
| | | Map<Long, Boolean> map = new HashMap<>();
|
| | | if (infoList != null)
|
| | | for (UserVIPInfo info : infoList)
|
| | | if (info != null && info.getState() == UserVIPInfo.STATE_SUCCESS)
|
| | | map.put(info.getId(), true);
|
| | | else
|
| | | map.put(info.getId(), false);
|
| | | for (Long uid : uids) {
|
| | | if (map.get(uid) == null)
|
| | | map.put(uid, false);
|
| | | }
|
| | | return map;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<UserVIPInfo> listQuery(int page, int count, String key, Integer state) {
|
| | | return userVIPInfoMapper.listQuery((page - 1) * count, count, key, state);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long countQuery(String key, Integer state) {
|
| | | return userVIPInfoMapper.countQuery(key, state);
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void applyVIP(Long uid) throws UserVIPInfoException {
|
| | | UserVIPPreInfo latestProcess = userVIPPreInfoService.getLatestProcessInfo(uid);
|
| | | if (latestProcess == null || latestProcess.getProcess() != UserVIPPreInfo.PROCESS_2) {
|
| | | throw new UserVIPInfoException(1, "请先升级为高级会员");
|
| | | }
|
| | |
|
| | | int verifyResult = verifyVip(uid);
|
| | | if (verifyResult <= 0)
|
| | | throw new UserVIPInfoException(1, "不满足升级条件");
|
| | |
|
| | | UserVIPInfo userInfo = userVIPInfoMapper.selectByPrimaryKeyForUpdate(uid);
|
| | | if (userInfo == null) {
|
| | | userInfo = new UserVIPInfo();
|
| | | userInfo.setId(uid);
|
| | | addUserVIPInfo(userInfo);
|
| | | }
|
| | |
|
| | | if (userInfo.getState() != UserVIPInfo.STATE_INVALID)
|
| | | throw new UserVIPInfoException(2, "系统已收到你的超级会员升级申请,将会尽快完成审核");
|
| | |
|
| | | SystemEnum system = userInfoService.getUserSystem(uid);
|
| | |
|
| | | UserVIPInfo info = new UserVIPInfo();
|
| | | info.setId(userInfo.getId());
|
| | | info.setApplyTime(new Date());
|
| | | info.setState(UserVIPInfo.STATE_VERIFING);
|
| | | info.setUpdateTime(new Date());
|
| | | userVIPInfoMapper.updateByPrimaryKeySelective(info);
|
| | | // 发送邮件通知
|
| | | try {
|
| | | Config config = configService.getConfig(ConfigKeyEnum.extractCodeEmailFrom.getKey(), system);
|
| | | String[] sts = config.getValue().split(",");
|
| | | String account = sts[0];
|
| | | String pwd = sts[1];
|
| | |
|
| | | String msg = String.format("用户ID:%s 申请超级会员", uid + "");
|
| | | String email = userVipConfigService.getValueByKey("apply_vip_email");
|
| | | String[] emails = email.split(",");
|
| | | for (String e : emails) {
|
| | | MailSenderUtil.sendEmail(e, account, pwd, msg, msg);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void passVIPApply(Long uid) throws UserVIPInfoException {
|
| | | UserVIPInfo userVIPInfo = userVIPInfoMapper.selectByPrimaryKeyForUpdate(uid);
|
| | | if (userVIPInfo == null) {
|
| | | throw new UserVIPInfoException(1, "用户信息不存在");
|
| | | }
|
| | | 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, "该用户还不是高级会员");
|
| | | }
|
| | |
|
| | | int verifyVipResult = verifyVip(uid);
|
| | |
|
| | | if (verifyVipResult <= 0)
|
| | | throw new UserVIPInfoException(1, "系统验证:不满足升级条件");
|
| | |
|
| | | Date upgradeTime = new Date();
|
| | | // 通过超级会员
|
| | | UserVIPInfo info = new UserVIPInfo();
|
| | | info.setId(userVIPInfo.getId());
|
| | | info.setSuccessTime(upgradeTime);
|
| | | info.setState(UserVIPInfo.STATE_SUCCESS);
|
| | | info.setUpdateTime(upgradeTime);
|
| | | userVIPInfoMapper.updateByPrimaryKeySelective(info);
|
| | |
|
| | | UserVIPPreInfo preInfo = new UserVIPPreInfo();
|
| | | preInfo.setCreateTime(new Date());
|
| | | preInfo.setProcess(UserLevelEnum.superVIP.getLevel());
|
| | | preInfo.setSourceType(verifyVipResult);
|
| | | preInfo.setUid(uid);
|
| | |
|
| | | try {
|
| | | userVIPPreInfoService.addUserVIPPreInfo(preInfo);
|
| | | } catch (UserVIPPreInfoException e1) {
|
| | | throw new UserVIPInfoException(100, "升级失败");
|
| | | }
|
| | |
|
| | | // 升级弹框提示
|
| | | UserLevelUpgradedNotify notify = new UserLevelUpgradedNotify();
|
| | | notify.setUid(uid);
|
| | | notify.setFromLevel(UserLevelEnum.highVIP);
|
| | | notify.setToLevel(UserLevelEnum.superVIP);
|
| | | 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()));
|
| | |
|
| | | // 直接粉丝升级提醒
|
| | | 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);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 验证是否符合VIP
|
| | | *
|
| | | * @param uid
|
| | | * @return
|
| | | */
|
| | | private String getPassItem(Long uid) {
|
| | | // 自购 + 分享订单
|
| | | long doneOrder = hongBaoV2CountService.countMyDirectOrderByCashArrival(uid, Constant.VIP_ORDER_PAY);
|
| | | // 有效粉丝
|
| | | int doneFirst = 0;
|
| | | int doneSecond = 0;
|
| | | UserInviteValidNum userInviteValidNum = userInviteValidNumService.selectByPrimaryKey(uid);
|
| | | if (userInviteValidNum != null) {
|
| | | doneFirst = userInviteValidNum.getNumFirst() == null ? 0 : userInviteValidNum.getNumFirst();
|
| | | doneSecond = userInviteValidNum.getNumSecond() == null ? 0 : userInviteValidNum.getNumSecond();
|
| | | }
|
| | |
|
| | | long limitOrder = 0;
|
| | | String zigou = userVipConfigService.getValueByKey("vip_pre_10_order_count");
|
| | | 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 = "返利+分享订单";
|
| | | } else if (doneFirst >= limitFirst && doneSecond >= limitSecond) {
|
| | | item = "直接+间接粉丝";
|
| | | }
|
| | | return item;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 验证是否符合VIP
|
| | | *
|
| | | * @param uid
|
| | | * @return 0-不符合 1-订单 2-团队
|
| | | * int 返回类型
|
| | | * @throws
|
| | | * @Title: verifyVip
|
| | | * @Description:
|
| | | */
|
| | | private int verifyVip(Long uid) {
|
| | | // 自购 + 分享订单
|
| | | long doneOrder = hongBaoV2CountService.countMyDirectOrderByCashArrival(uid, Constant.VIP_ORDER_PAY);
|
| | | // 有效粉丝
|
| | | int doneFirst = 0;
|
| | | int doneSecond = 0;
|
| | | UserInviteValidNum userInviteValidNum = userInviteValidNumService.selectByPrimaryKey(uid);
|
| | | if (userInviteValidNum != null) {
|
| | | doneFirst = userInviteValidNum.getNumFirst() == null ? 0 : userInviteValidNum.getNumFirst();
|
| | | doneSecond = userInviteValidNum.getNumSecond() == null ? 0 : userInviteValidNum.getNumSecond();
|
| | | }
|
| | | long limitOrder = 0;
|
| | | String zigou = userVipConfigService.getValueByKey("vip_pre_10_order_count");
|
| | | 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) {
|
| | | return UserVIPPreInfo.SOURCE_TYPE_ORDER;
|
| | | }
|
| | |
|
| | | if ((doneFirst >= limitFirst && doneSecond >= limitSecond))
|
| | |
|
| | | return UserVIPPreInfo.SOURCE_TYPE_TEAM;
|
| | | return 0;
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void rejectVIPApply(Long uid, String reason) throws UserVIPInfoException {
|
| | | UserVIPInfo userInfo = userVIPInfoMapper.selectByPrimaryKeyForUpdate(uid);
|
| | | if (userInfo == null) {
|
| | | throw new UserVIPInfoException(1, "用户信息不存在");
|
| | | }
|
| | | if (userInfo.getState() != UserVIPInfo.STATE_VERIFING) {
|
| | | throw new UserVIPInfoException(2, "申请未处于审核状态");
|
| | | }
|
| | |
|
| | | UserVIPInfo info = new UserVIPInfo();
|
| | | 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);
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.user.vip; |
| | | |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | 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.UserVIPInfoMapper; |
| | | import com.yeshi.fanli.entity.bus.user.ThreeSale; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfo; |
| | | import com.yeshi.fanli.entity.bus.user.UserInviteValidNum; |
| | | import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum; |
| | | import com.yeshi.fanli.entity.bus.user.vip.UserLevelUpgradedNotify; |
| | | import com.yeshi.fanli.entity.bus.user.vip.UserVIPInfo; |
| | | import com.yeshi.fanli.entity.bus.user.vip.UserVIPPreInfo; |
| | | import com.yeshi.fanli.entity.common.Config; |
| | | import com.yeshi.fanli.entity.system.ConfigKeyEnum; |
| | | import com.yeshi.fanli.exception.user.vip.UserVIPInfoException; |
| | | import com.yeshi.fanli.exception.user.vip.UserVIPPreInfoException; |
| | | import com.yeshi.fanli.log.LogHelper; |
| | | import com.yeshi.fanli.service.inter.config.ConfigService; |
| | | 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; |
| | | import com.yeshi.fanli.service.inter.user.invite.UserInviteMsgNotificationService; |
| | | import com.yeshi.fanli.service.inter.user.invite.UserInviteValidNumService; |
| | | import com.yeshi.fanli.service.inter.user.msg.UserAccountMsgNotificationService; |
| | | import com.yeshi.fanli.service.inter.user.vip.UserLevelUpgradedNotifyService; |
| | | import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService; |
| | | import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService; |
| | | import com.yeshi.fanli.service.inter.user.vip.UserVipConfigService; |
| | | import com.yeshi.fanli.service.manger.msg.RocketMQManager; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import org.yeshi.utils.TimeUtil; |
| | | import com.yeshi.fanli.util.email.MailSenderUtil; |
| | | |
| | | @Service |
| | | public class UserVIPInfoServiceImpl implements UserVIPInfoService { |
| | | |
| | | @Resource |
| | | private UserVIPInfoMapper userVIPInfoMapper; |
| | | |
| | | @Resource |
| | | private UserInfoService userInfoService; |
| | | |
| | | @Resource |
| | | private UserVipConfigService userVipConfigService; |
| | | |
| | | @Lazy |
| | | @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 |
| | | private RocketMQManager rocketMQManager; |
| | | |
| | | @Resource |
| | | private ConfigService configService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void addUserVIPInfo(UserVIPInfo info) throws UserVIPInfoException { |
| | | if (info.getId() == null) { |
| | | throw new UserVIPInfoException(1, "信息不完整"); |
| | | } |
| | | UserVIPInfo userInfo = userVIPInfoMapper.selectByPrimaryKey(info.getId()); |
| | | if (userInfo != null) { |
| | | throw new UserVIPInfoException(1, "信息已存在"); |
| | | } |
| | | // 初始化状态 |
| | | info.setState(UserVIPInfo.STATE_INVALID); |
| | | info.setCreateTime(new Date()); |
| | | userVIPInfoMapper.insert(info); |
| | | } |
| | | |
| | | @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 |
| | | && userInfo.getSuccessTime().getTime() < time) |
| | | return true; |
| | | else |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public UserVIPInfo selectByUid(Long uid) { |
| | | UserVIPInfo userInfo = userVIPInfoMapper.selectByPrimaryKey(uid); |
| | | return userInfo; |
| | | } |
| | | |
| | | @Override |
| | | public Map<Long, Boolean> listByUids(List<Long> uids) { |
| | | if (uids == null || uids.size() == 0) |
| | | return new HashMap<>(); |
| | | List<UserVIPInfo> infoList = userVIPInfoMapper.listByUids(uids); |
| | | // 整理数据 |
| | | Map<Long, Boolean> map = new HashMap<>(); |
| | | if (infoList != null) |
| | | for (UserVIPInfo info : infoList) |
| | | if (info != null && info.getState() == UserVIPInfo.STATE_SUCCESS) |
| | | map.put(info.getId(), true); |
| | | else |
| | | map.put(info.getId(), false); |
| | | for (Long uid : uids) { |
| | | if (map.get(uid) == null) |
| | | map.put(uid, false); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | @Override |
| | | public List<UserVIPInfo> listQuery(int page, int count, String key, Integer state) { |
| | | return userVIPInfoMapper.listQuery((page - 1) * count, count, key, state); |
| | | } |
| | | |
| | | @Override |
| | | public long countQuery(String key, Integer state) { |
| | | return userVIPInfoMapper.countQuery(key, state); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void applyVIP(Long uid) throws UserVIPInfoException { |
| | | UserVIPPreInfo latestProcess = userVIPPreInfoService.getLatestProcessInfo(uid); |
| | | if (latestProcess == null || latestProcess.getProcess() != UserVIPPreInfo.PROCESS_2) { |
| | | throw new UserVIPInfoException(1, "请先升级为高级会员"); |
| | | } |
| | | |
| | | int verifyResult = verifyVip(uid); |
| | | if (verifyResult <= 0) |
| | | throw new UserVIPInfoException(1, "不满足升级条件"); |
| | | |
| | | UserVIPInfo userInfo = userVIPInfoMapper.selectByPrimaryKeyForUpdate(uid); |
| | | if (userInfo == null) { |
| | | userInfo = new UserVIPInfo(); |
| | | userInfo.setId(uid); |
| | | addUserVIPInfo(userInfo); |
| | | } |
| | | |
| | | if (userInfo.getState() != UserVIPInfo.STATE_INVALID) |
| | | throw new UserVIPInfoException(2, "系统已收到你的超级会员升级申请,将会尽快完成审核"); |
| | | |
| | | SystemEnum system = userInfoService.getUserSystem(uid); |
| | | |
| | | UserVIPInfo info = new UserVIPInfo(); |
| | | info.setId(userInfo.getId()); |
| | | info.setApplyTime(new Date()); |
| | | info.setState(UserVIPInfo.STATE_VERIFING); |
| | | info.setUpdateTime(new Date()); |
| | | userVIPInfoMapper.updateByPrimaryKeySelective(info); |
| | | // 发送邮件通知 |
| | | try { |
| | | Config config = configService.getConfig(ConfigKeyEnum.extractCodeEmailFrom.getKey(), system); |
| | | String[] sts = config.getValue().split(","); |
| | | String account = sts[0]; |
| | | String pwd = sts[1]; |
| | | |
| | | String msg = String.format("用户ID:%s 申请超级会员", uid + ""); |
| | | String email = userVipConfigService.getValueByKey("apply_vip_email"); |
| | | String[] emails = email.split(","); |
| | | for (String e : emails) { |
| | | MailSenderUtil.sendEmail(e, account, pwd, msg, msg); |
| | | } |
| | | } catch (Exception e) { |
| | | LogHelper.errorDetailInfo(e); |
| | | } |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void passVIPApply(Long uid) throws UserVIPInfoException { |
| | | UserVIPInfo userVIPInfo = userVIPInfoMapper.selectByPrimaryKeyForUpdate(uid); |
| | | if (userVIPInfo == null) { |
| | | throw new UserVIPInfoException(1, "用户信息不存在"); |
| | | } |
| | | 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, "该用户还不是高级会员"); |
| | | } |
| | | |
| | | int verifyVipResult = verifyVip(uid); |
| | | |
| | | if (verifyVipResult <= 0) |
| | | throw new UserVIPInfoException(1, "系统验证:不满足升级条件"); |
| | | |
| | | Date upgradeTime = new Date(); |
| | | // 通过超级会员 |
| | | UserVIPInfo info = new UserVIPInfo(); |
| | | info.setId(userVIPInfo.getId()); |
| | | info.setSuccessTime(upgradeTime); |
| | | info.setState(UserVIPInfo.STATE_SUCCESS); |
| | | info.setUpdateTime(upgradeTime); |
| | | userVIPInfoMapper.updateByPrimaryKeySelective(info); |
| | | |
| | | UserVIPPreInfo preInfo = new UserVIPPreInfo(); |
| | | preInfo.setCreateTime(new Date()); |
| | | preInfo.setProcess(UserLevelEnum.superVIP.getLevel()); |
| | | preInfo.setSourceType(verifyVipResult); |
| | | preInfo.setUid(uid); |
| | | |
| | | try { |
| | | userVIPPreInfoService.addUserVIPPreInfo(preInfo); |
| | | } catch (UserVIPPreInfoException e1) { |
| | | throw new UserVIPInfoException(100, "升级失败"); |
| | | } |
| | | |
| | | // 升级弹框提示 |
| | | UserLevelUpgradedNotify notify = new UserLevelUpgradedNotify(); |
| | | notify.setUid(uid); |
| | | notify.setFromLevel(UserLevelEnum.highVIP); |
| | | notify.setToLevel(UserLevelEnum.superVIP); |
| | | 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())); |
| | | |
| | | // 直接粉丝升级提醒 |
| | | 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); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 验证是否符合VIP |
| | | * |
| | | * @param uid |
| | | * @return |
| | | */ |
| | | private String getPassItem(Long uid) { |
| | | // 自购 + 分享订单 |
| | | long doneOrder = hongBaoV2CountService.countMyDirectOrderByCashArrival(uid, Constant.VIP_ORDER_PAY); |
| | | // 有效粉丝 |
| | | int doneFirst = 0; |
| | | int doneSecond = 0; |
| | | UserInviteValidNum userInviteValidNum = userInviteValidNumService.selectByPrimaryKey(uid); |
| | | if (userInviteValidNum != null) { |
| | | doneFirst = userInviteValidNum.getNumFirst() == null ? 0 : userInviteValidNum.getNumFirst(); |
| | | doneSecond = userInviteValidNum.getNumSecond() == null ? 0 : userInviteValidNum.getNumSecond(); |
| | | } |
| | | |
| | | long limitOrder = 0; |
| | | String zigou = userVipConfigService.getValueByKey("vip_pre_10_order_count"); |
| | | 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 = "返利+分享订单"; |
| | | } else if (doneFirst >= limitFirst && doneSecond >= limitSecond) { |
| | | item = "直接+间接粉丝"; |
| | | } |
| | | return item; |
| | | } |
| | | |
| | | /** |
| | | * 验证是否符合VIP |
| | | * |
| | | * @param uid |
| | | * @return 0-不符合 1-订单 2-团队 |
| | | * int 返回类型 |
| | | * @throws |
| | | * @Title: verifyVip |
| | | * @Description: |
| | | */ |
| | | private int verifyVip(Long uid) { |
| | | // 自购 + 分享订单 |
| | | long doneOrder = hongBaoV2CountService.countMyDirectOrderByCashArrival(uid, Constant.VIP_ORDER_PAY); |
| | | // 有效粉丝 |
| | | int doneFirst = 0; |
| | | int doneSecond = 0; |
| | | UserInviteValidNum userInviteValidNum = userInviteValidNumService.selectByPrimaryKey(uid); |
| | | if (userInviteValidNum != null) { |
| | | doneFirst = userInviteValidNum.getNumFirst() == null ? 0 : userInviteValidNum.getNumFirst(); |
| | | doneSecond = userInviteValidNum.getNumSecond() == null ? 0 : userInviteValidNum.getNumSecond(); |
| | | } |
| | | long limitOrder = 0; |
| | | String zigou = userVipConfigService.getValueByKey("vip_pre_10_order_count"); |
| | | 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) { |
| | | return UserVIPPreInfo.SOURCE_TYPE_ORDER; |
| | | } |
| | | |
| | | if ((doneFirst >= limitFirst && doneSecond >= limitSecond)) |
| | | |
| | | return UserVIPPreInfo.SOURCE_TYPE_TEAM; |
| | | return 0; |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void rejectVIPApply(Long uid, String reason) throws UserVIPInfoException { |
| | | UserVIPInfo userInfo = userVIPInfoMapper.selectByPrimaryKeyForUpdate(uid); |
| | | if (userInfo == null) { |
| | | throw new UserVIPInfoException(1, "用户信息不存在"); |
| | | } |
| | | if (userInfo.getState() != UserVIPInfo.STATE_VERIFING) { |
| | | throw new UserVIPInfoException(2, "申请未处于审核状态"); |
| | | } |
| | | |
| | | UserVIPInfo info = new UserVIPInfo(); |
| | | 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); |
| | | } |
| | | |
| | | } |