| | |
| | | package com.yeshi.fanli.service.impl.user.vip;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | | import java.util.Date;
|
| | |
| | | import org.springframework.context.annotation.Lazy;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.yeshi.utils.DateUtil;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.user.vip.UserVIPPreInfoMapper;
|
| | | import com.yeshi.fanli.dto.msg.MsgAccountVipDTO;
|
| | | import com.yeshi.fanli.entity.bus.msg.MsgOtherDetail.MsgTypeOtherTypeEnum;
|
| | | 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.UserInfoExtra;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfoRegister;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInviteValidNum;
|
| | | import com.yeshi.fanli.entity.bus.user.UserSystemCoupon;
|
| | | import com.yeshi.fanli.entity.bus.user.vip.UserVIPPreInfo;
|
| | | import com.yeshi.fanli.entity.integral.IntegralDetail;
|
| | | import com.yeshi.fanli.entity.system.ConfigKeyEnum;
|
| | | import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum;
|
| | | 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.msg.UserOtherMsgNotificationService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoRegisterService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInviteSeparateService;
|
| | | import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
|
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralDetailService;
|
| | | 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.MsgAccountDetailService;
|
| | | import com.yeshi.fanli.service.inter.user.msg.UserAccountMsgNotificationService;
|
| | | import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.vip.UserVipConfigService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.annotation.RequestSerializableByKeyService;
|
| | | import com.yeshi.fanli.vo.msg.ClientTextStyleVO;
|
| | | import com.yeshi.fanli.vo.msg.CommonMsgItemVO;
|
| | | import com.yeshi.fanli.vo.msg.CommonMsgItemVOFactory;
|
| | |
|
| | | @Service
|
| | | public class UserVIPPreInfoServiceImpl implements UserVIPPreInfoService {
|
| | |
| | | @Resource
|
| | | private ThreeSaleSerivce threeSaleSerivce;
|
| | |
|
| | | @Resource
|
| | | private MsgAccountDetailService msgAccountDetailService;
|
| | | |
| | | @Resource
|
| | | private UserVipConfigService userVipConfigService;
|
| | |
|
| | |
| | | @Resource
|
| | | private UserOtherMsgNotificationService userOtherMsgNotificationService;
|
| | |
|
| | | @Resource
|
| | | private UserAccountMsgNotificationService userAccountMsgNotificationService;
|
| | | |
| | | @Resource
|
| | | private UserInfoRegisterService userInfoRegisterService;
|
| | | |
| | | @Resource
|
| | | private UserInviteMsgNotificationService userInviteMsgNotificationService;
|
| | |
|
| | | @Override
|
| | | public void addUserVIPPreInfo(UserVIPPreInfo info) throws UserVIPPreInfoException {
|
| | |
| | | * @param secondTeam
|
| | | */
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | private boolean oneProcess(Long uid, long countZiGou, long countShare, long firstTeam, long secondTeam) {
|
| | | private boolean oneProcess(Long uid, long countZiGou, long countShare, long firstTeam, long secondTeam) throws Exception{
|
| | | UserVIPPreInfo oldInfo = userVIPPreInfoMapper.selectByUidAndProcess(uid, UserVIPPreInfo.PROCESS_1);
|
| | | if (oldInfo != null) {
|
| | | return true;
|
| | | }
|
| | |
|
| | | boolean process = false;
|
| | | String msg = "";
|
| | | |
| | | long limitZiGou = 0;
|
| | | String zigou = userVipConfigService.getValueByKey("vip_pre_3_zigou_order_count");
|
| | | if (!StringUtil.isNullOrEmpty(zigou)) {
|
| | |
| | | limitSecond = Long.parseLong(second);
|
| | | }
|
| | |
|
| | | String item = "";
|
| | | Integer type = null;
|
| | | long targetNum1 = 0L;
|
| | | Long targetNum2 = 0L;
|
| | | boolean process = false;
|
| | | if (countZiGou >= limitZiGou) {
|
| | | process = true;
|
| | | msg = "恭喜你!返利订单达到 " + limitZiGou + "笔";
|
| | | type = Constant.TYPE_REBATE;
|
| | | targetNum1 = limitZiGou;
|
| | | item = "返利订单";
|
| | | } else if (countShare >= limitShare) {
|
| | | process = true;
|
| | | msg = "恭喜你!分享订单达到 " + limitShare + "笔";
|
| | | type = Constant.TYPE_SHAER;
|
| | | targetNum1 = limitShare;
|
| | | item = "分享订单";
|
| | | } else if (firstTeam >= limitFirst && secondTeam >= limitSecond) {
|
| | | process = true;
|
| | | msg = "直接粉丝达到" + limitFirst + "人,间接粉丝达到 " + limitSecond + "人";
|
| | | targetNum1 = limitFirst;
|
| | | targetNum2 = limitSecond;
|
| | | item = "邀请粉丝";
|
| | | }
|
| | |
|
| | | if (process) {
|
| | | try {
|
| | | Date upgradeTime = new Date();
|
| | | UserVIPPreInfo info = new UserVIPPreInfo();
|
| | | info.setUid(uid);
|
| | | info.setProcess(UserVIPPreInfo.PROCESS_1);
|
| | | info.setCreateTime(new Date());
|
| | | info.setUpdateTime(new Date());
|
| | | info.setCreateTime(upgradeTime);
|
| | | info.setUpdateTime(upgradeTime);
|
| | | addUserVIPPreInfo(info);
|
| | |
|
| | | // 消息
|
| | | MsgAccountVipDTO msgDto = new MsgAccountVipDTO();
|
| | | msgDto.setStatus("系统已将你的账户由快省达人升级为普通会员");
|
| | | msgDto.setEquity("从收到本消息起,你将获得全部普通会员权益");
|
| | | msgAccountDetailService.addMsgVIP(uid, msg, "如有疑问请联系我的-人工客服", msgDto);
|
| | | |
| | | // 升级消息
|
| | | Date registerTime = new Date(1577836800000L);
|
| | | UserInfoRegister userInfoRegister = userInfoRegisterService.selectByPrimaryKey(uid);
|
| | | if (userInfoRegister != null && userInfoRegister.getCreateTime() != null) {
|
| | | registerTime = userInfoRegister.getCreateTime();
|
| | | }
|
| | | int daysBetween = DateUtil.daysBetween(registerTime, new Date());
|
| | | userAccountMsgNotificationService.vipPreUpgrade(uid, "快省达人", "普通会员", daysBetween, targetNum1, targetNum2, type);
|
| | |
|
| | | // 赠送金币
|
| | | String goldcoin = userVipConfigService.getValueByKey("vip_pre_3_gift_goldcoin");
|
| | |
| | | detail.setTitle("升级VIP福利");
|
| | | detail.setUid(uid);
|
| | | detail.setMoney(Integer.parseInt(goldcoin));
|
| | | detail.setCreateTime(new Date());
|
| | | detail.setCreateTime(upgradeTime);
|
| | | detail.setUniqueKey("VIP-3-" + uid);
|
| | | integralDetailService.insertSelective(detail);
|
| | |
|
| | |
| | | userInfoExtraService.addGoldCoinByUid(uid, Integer.parseInt(goldcoin));
|
| | |
|
| | | // 消息
|
| | | List<CommonMsgItemVO> listMsg = new ArrayList<>();
|
| | | listMsg.add(CommonMsgItemVOFactory.createMsgItemVO(new ClientTextStyleVO("状 态", ClientTextStyleVO.COLOR_TITLE),
|
| | | new ClientTextStyleVO("恭喜你!成功升级为普通会员", ClientTextStyleVO.COLOR_CONTENT)));
|
| | | listMsg.add(CommonMsgItemVOFactory.createMsgItemVO(new ClientTextStyleVO("奖 励", ClientTextStyleVO.COLOR_TITLE),
|
| | | new ClientTextStyleVO("获得金币" + goldcoinNum+"枚", ClientTextStyleVO.COLOR_CONTENT)));
|
| | | listMsg.add(CommonMsgItemVOFactory.createMsgItemVO(new ClientTextStyleVO("备 注", ClientTextStyleVO.COLOR_TITLE),
|
| | | new ClientTextStyleVO("详情查看,对应会员权益", ClientTextStyleVO.COLOR_CONTENT)));
|
| | | userOtherMsgNotificationService.createMsgOtherDetail(uid, listMsg, MsgTypeOtherTypeEnum.vipUpgradeReward);
|
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
|
| | | userOtherMsgNotificationService.goldCoinSystemGiveMsg(uid, goldcoinNum, userInfoExtra.getGoldCoin());
|
| | | }
|
| | | |
| | | // 是否存在下级脱离期限 -更新不脱离
|
| | | userInviteSeparateService.updateInvalidByBossId(uid);
|
| | |
|
| | | // 上级脱离关系
|
| | | remindBoss(uid);
|
| | | // 提醒上级
|
| | | remindBoss(uid, "普通会员", item, upgradeTime, true);
|
| | |
|
| | | } catch (UserVIPPreInfoException e) {
|
| | | e.printStackTrace();
|
| | |
| | | }
|
| | | return process;
|
| | | }
|
| | |
|
| | | |
| | | private void remindBoss(Long uid) {
|
| | | // 是否存在上级
|
| | | ThreeSale threeSale = threeSaleSerivce.getMyBoss(uid);
|
| | | if (threeSale == null)
|
| | | return;
|
| | | |
| | | // 验证上级是否正常
|
| | | Long bossId = threeSale.getBoss().getId();
|
| | | UserInfo userInfo = userInfoService.getUserById(bossId);
|
| | | if (userInfo == null || userInfo.getState() != UserInfo.STATE_NORMAL) {
|
| | | return;
|
| | | }
|
| | | |
| | | // 验证上级是否已是会员
|
| | | UserVIPPreInfo oldInfo = userVIPPreInfoMapper.selectByUidAndProcess(bossId, UserVIPPreInfo.PROCESS_1);
|
| | | if (oldInfo != null) {
|
| | | return;
|
| | | }
|
| | | |
| | | // 添加脱离关系倒计时
|
| | | userInviteSeparateService.addPreSeparateRecord(uid, bossId);
|
| | | }
|
| | | |
| | |
|
| | |
|
| | | /**
|
| | |
| | | */
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | private boolean twoProcess(Long uid, long countZiGou, long countShare, long firstTeam, long secondTeam) {
|
| | | boolean process = false;
|
| | | String msg = "";
|
| | | |
| | | long limitZiGou = 10;
|
| | | // String zigou = userVipConfigService.getValueByKey("vip_pre_7_zigou_order_count");
|
| | | // if (!StringUtil.isNullOrEmpty(zigou)) {
|
| | | // limitZiGou = Long.parseLong(zigou);
|
| | | // }
|
| | | long limitZiGou = 0;
|
| | | String zigou = userVipConfigService.getValueByKey("vip_pre_7_zigou_order_count");
|
| | | if (!StringUtil.isNullOrEmpty(zigou)) {
|
| | | limitZiGou = Long.parseLong(zigou);
|
| | | }
|
| | |
|
| | | long limitShare = 0;
|
| | | String share = userVipConfigService.getValueByKey("vip_pre_7_share_order_count");
|
| | |
| | | limitSecond = Long.parseLong(second);
|
| | | }
|
| | |
|
| | | Integer type = null;
|
| | | long targetNum1 = 0L;
|
| | | Long targetNum2 = 0L;
|
| | | String item = "";
|
| | | boolean process = false;
|
| | | if (countZiGou >= limitZiGou) {
|
| | | process = true;
|
| | | msg = "恭喜你!返利订单达到 " + limitZiGou + "笔";
|
| | | targetNum1 = limitZiGou;
|
| | | type = Constant.TYPE_REBATE;
|
| | | item = "返利订单";
|
| | | } else if (countShare >= limitShare) {
|
| | | process = true;
|
| | | msg = "恭喜你!分享订单达到 " + limitShare + "笔";
|
| | | targetNum1 = limitShare;
|
| | | type = Constant.TYPE_SHAER;
|
| | | item = "分享订单";
|
| | | } else if (firstTeam >= limitFirst && secondTeam >= limitSecond) {
|
| | | process = true;
|
| | | msg = "直接粉丝达到" + limitFirst + "人,间接粉丝达到 " + limitSecond + "人";
|
| | | targetNum1 = limitFirst;
|
| | | targetNum2 = limitSecond;
|
| | | item = "邀请粉丝";
|
| | | }
|
| | |
|
| | | if (process) {
|
| | | try {
|
| | | Date upgradeTime = new Date();
|
| | | UserVIPPreInfo info = new UserVIPPreInfo();
|
| | | info.setUid(uid);
|
| | | info.setProcess(UserVIPPreInfo.PROCESS_2);
|
| | | info.setCreateTime(new Date());
|
| | | info.setUpdateTime(new Date());
|
| | | info.setCreateTime(upgradeTime);
|
| | | info.setUpdateTime(upgradeTime);
|
| | | addUserVIPPreInfo(info);
|
| | |
|
| | | // 消息
|
| | | MsgAccountVipDTO msgDto = new MsgAccountVipDTO();
|
| | | msgDto.setStatus("系统已将你的账户由普通会员升级为高级会员");
|
| | | msgDto.setEquity("从收到本消息起,你将获得全部高级会员权益");
|
| | | msgAccountDetailService.addMsgVIP(uid, msg, "如有疑问请联系我的-人工客服", msgDto);
|
| | | |
| | | // 升级消息
|
| | | UserVIPPreInfo pre1 = userVIPPreInfoMapper.selectByUidAndProcess(uid, UserVIPPreInfo.PROCESS_1);
|
| | | int daysBetween = DateUtil.daysBetween(pre1.getCreateTime(), upgradeTime);
|
| | | userAccountMsgNotificationService.vipPreUpgrade(uid, "普通会员", "高级会员", daysBetween, targetNum1, targetNum2, type);
|
| | |
|
| | | // 赠送奖励券
|
| | | String rewardCoupon = userVipConfigService.getValueByKey("vip_pre_7_gift_reward_coupon");
|
| | | if (!StringUtil.isNullOrEmpty(rewardCoupon)) {
|
| | | int num = Integer.parseInt(rewardCoupon);
|
| | | BigDecimal percent = new BigDecimal(configService.get(ConfigKeyEnum.exchangeRebatePercent.getKey()));
|
| | | for (int i = 0; i < num; i++) {
|
| | | userSystemCouponService.insertUserCoupon(uid, CouponTypeEnum.rebatePercentCoupon.name(),
|
| | | UserSystemCoupon.SOURCE_SYSTEM_PUSH, percent, false);
|
| | | }
|
| | | |
| | | List<CommonMsgItemVO> listMsg = new ArrayList<>();
|
| | | listMsg.add(CommonMsgItemVOFactory.createMsgItemVO(new ClientTextStyleVO("状 态", ClientTextStyleVO.COLOR_TITLE),
|
| | | new ClientTextStyleVO("恭喜你!成功升级为高级会员", ClientTextStyleVO.COLOR_CONTENT)));
|
| | | listMsg.add(CommonMsgItemVOFactory.createMsgItemVO(new ClientTextStyleVO("奖 励", ClientTextStyleVO.COLOR_TITLE),
|
| | | new ClientTextStyleVO("获得返利奖励券" + num +"张", ClientTextStyleVO.COLOR_CONTENT)));
|
| | | listMsg.add(CommonMsgItemVOFactory.createMsgItemVO(new ClientTextStyleVO("备 注", ClientTextStyleVO.COLOR_TITLE),
|
| | | new ClientTextStyleVO("详情查看,对应会员权益", ClientTextStyleVO.COLOR_CONTENT)));
|
| | | userOtherMsgNotificationService.createMsgOtherDetail(uid, listMsg, MsgTypeOtherTypeEnum.vipUpgradeReward);
|
| | | userSystemCouponService.rewardCouponWin(uid, UserSystemCoupon.SOURCE_SYSTEM_PUSH, num, true, percent);
|
| | | }
|
| | | |
| | | // 提醒上级
|
| | | remindBoss(uid, "高级会员", item, upgradeTime, false);
|
| | | |
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | LogHelper.error(e);
|
| | |
| | | }
|
| | | return process;
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public void remindBoss(Long uid, String rankName, String item, Date time, boolean divorced) {
|
| | | // 是否存在上级
|
| | | ThreeSale threeSale = threeSaleSerivce.getMyBoss(uid);
|
| | | if (threeSale == null)
|
| | | return;
|
| | | Long bossId = threeSale.getBoss().getId();
|
| | | UserInfo userInfo = userInfoService.selectByPKey(uid);
|
| | | |
| | | // 粉丝升级提醒
|
| | | userInviteMsgNotificationService.fansUpgrade(bossId, "直接粉丝", rankName, userInfo.getNickName(), item, time);
|
| | | |
| | | // 是否存在上上级
|
| | | ThreeSale threeSaleSuper = threeSaleSerivce.getMyBoss(bossId);
|
| | | if (threeSaleSuper != null) { // 粉丝升级提醒
|
| | | Long bossIdSuper = threeSaleSuper.getBoss().getId();
|
| | | userInviteMsgNotificationService.fansUpgrade(bossIdSuper, "间接粉丝", rankName, userInfo.getNickName(), item, time);
|
| | | }
|
| | | |
| | | // 是否升级脱离
|
| | | if (!divorced) {
|
| | | return;
|
| | | }
|
| | | |
| | | // 验证上级是否已是会员
|
| | | UserVIPPreInfo oldInfo = userVIPPreInfoMapper.selectByUidAndProcess(bossId, UserVIPPreInfo.PROCESS_1);
|
| | | if (oldInfo == null) {
|
| | | // 添加脱离关系倒计时
|
| | | userInviteSeparateService.addPreSeparateRecord(uid, bossId);
|
| | | |
| | | // 直接粉丝脱离-开始脱离提醒
|
| | | userInviteMsgNotificationService.fansPreDivorced(bossId, rankName, userInfo.getNickName(), item, time);
|
| | | |
| | | //间接粉丝脱离-开始脱离提醒
|
| | | if (threeSaleSuper != null) { |
| | | UserInfo boss = userInfoService.selectByPKey(bossId);
|
| | | Long bossIdSuper = threeSaleSuper.getBoss().getId();
|
| | | userInviteMsgNotificationService.fansPredivorcedIndirect(bossIdSuper, rankName, userInfo.getNickName(),
|
| | | boss.getNickName(), item, time);
|
| | | } |
| | | }
|
| | | }
|
| | | |
| | | @Override
|
| | | public UserVIPPreInfo selectByUidAndProcess(Long uid, int process) {
|
| | | UserVIPPreInfo info = userVIPPreInfoMapper.selectByUidAndProcess(uid, process);
|
| | | return info;
|