| | |
| | | package com.yeshi.fanli.service.impl.user.vip;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | |
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | 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.UserVIPInfoMapper;
|
| | | import com.yeshi.fanli.entity.bus.user.HongBaoV2;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInviteValidNum;
|
| | | import com.yeshi.fanli.entity.bus.user.UserSystemCoupon;
|
| | | import com.yeshi.fanli.entity.bus.user.vip.UserVIPInfo;
|
| | | import com.yeshi.fanli.entity.shop.BanLiShopOrder;
|
| | | import com.yeshi.fanli.entity.bus.user.vip.UserVIPPreInfo;
|
| | | import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum;
|
| | | import com.yeshi.fanli.exception.user.vip.UserVIPInfoException;
|
| | | 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.shop.BanLiShopOrderService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
| | | 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.UserInviteValidNumService;
|
| | | import com.yeshi.fanli.service.inter.user.msg.UserAccountMsgNotificationService;
|
| | | 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.util.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | | @Service
|
| | | public class UserVIPInfoServiceImpl implements UserVIPInfoService {
|
| | |
|
| | | @Resource
|
| | | private UserVIPInfoMapper userVIPInfoMapper;
|
| | | |
| | |
|
| | | @Resource
|
| | | private UserInfoService userInfoService;
|
| | |
|
| | | @Resource
|
| | | private UserInfoExtraService userInfoExtraService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private UserVipConfigService userVipConfigService;
|
| | | |
| | |
|
| | | @Lazy
|
| | | @Resource
|
| | | private HongBaoV2CountService hongBaoV2CountService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private IntegralDetailService integralDetailService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private BanLiShopOrderService banLiShopOrderService;
|
| | |
|
| | | @Resource
|
| | | private UserOtherMsgNotificationService userOtherMsgNotificationService;
|
| | |
|
| | | @Resource
|
| | | private ThreeSaleSerivce threeSaleSerivce;
|
| | |
|
| | | @Resource
|
| | | private UserInviteSeparateService userInviteSeparateService;
|
| | |
|
| | | @Resource
|
| | | private ConfigService configService;
|
| | |
|
| | | @Lazy
|
| | | @Resource
|
| | | private UserSystemCouponService userSystemCouponService;
|
| | |
|
| | | @Resource
|
| | | private UserVIPPreInfoService userVIPPreInfoService;
|
| | |
|
| | | @Resource
|
| | | private UserAccountMsgNotificationService userAccountMsgNotificationService;
|
| | |
|
| | | @Resource
|
| | | private UserInviteValidNumService userInviteValidNumService;
|
| | |
|
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void addUserVIPInfo(UserVIPInfo info) throws UserVIPInfoException {
|
| | | if (info.getId() == null) {
|
| | | throw new UserVIPInfoException(1, "信息不完整");
|
| | |
| | | userVIPInfoMapper.insert(info);
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void passVIPApply(Long uid) 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.setSuccessTime(new Date());
|
| | | info.setState(UserVIPInfo.STATE_SUCCESS);
|
| | | info.setUpdateTime(new Date());
|
| | | userVIPInfoMapper.updateByPrimaryKeySelective(info);
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @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());
|
| | | userVIPInfoMapper.updateByPrimaryKeySelective(info);
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void applyVIP(Long uid) throws UserVIPInfoException {
|
| | | UserVIPInfo userInfo = userVIPInfoMapper.selectByPrimaryKeyForUpdate(uid);
|
| | | if (userInfo == null) {
|
| | | throw new UserVIPInfoException(1, "用户信息不存在");
|
| | | }
|
| | |
|
| | | if (userInfo.getState() != UserVIPInfo.STATE_INVALID) {
|
| | | throw new UserVIPInfoException(2, "已经申请过");
|
| | | }
|
| | |
|
| | | UserVIPInfo info = new UserVIPInfo();
|
| | | info.setId(userInfo.getId());
|
| | | info.setApplyTime(new Date());
|
| | | info.setState(UserVIPInfo.STATE_VERIFING);
|
| | | info.setUpdateTime(new Date());
|
| | | userVIPInfoMapper.updateByPrimaryKeySelective(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)
|
| | | if (userInfo != null && userInfo.getState() == UserVIPInfo.STATE_SUCCESS
|
| | | && userInfo.getSuccessTime().getTime() < time)
|
| | | return true;
|
| | | else
|
| | | return false;
|
| | |
| | | return map;
|
| | | }
|
| | |
|
| | | |
| | |
|
| | | @Override
|
| | | public boolean verifyConform(Long uid) {
|
| | | if (uid == null || uid <= 0)
|
| | | return false;
|
| | | |
| | | UserInfoExtra extra = userInfoExtraService.getUserInfoExtra(uid);
|
| | | if (extra == null) |
| | | return false;
|
| | | |
| | | String limtDate = userVipConfigService.getValueByKey("vip_execute_time");
|
| | | Date executeDate = null;
|
| | | 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, "请先升级为高级会员");
|
| | | }
|
| | |
|
| | | if (!verifyVip(uid))
|
| | | 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, "系统已收到你的超级会员升级申请,将会尽快完成审核");
|
| | |
|
| | | UserVIPInfo info = new UserVIPInfo();
|
| | | info.setId(userInfo.getId());
|
| | | info.setApplyTime(new Date());
|
| | | info.setState(UserVIPInfo.STATE_VERIFING);
|
| | | info.setUpdateTime(new Date());
|
| | | userVIPInfoMapper.updateByPrimaryKeySelective(info);
|
| | | }
|
| | |
|
| | | @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, "该用户还不是高级会员");
|
| | | }
|
| | |
|
| | | if (!verifyVip(uid))
|
| | | throw new UserVIPInfoException(1, "系统验证:不满足升级条件");
|
| | |
|
| | | // 额外信息
|
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getByUidForUpdate(uid);
|
| | | if (userInfoExtra == null)
|
| | | 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);
|
| | |
|
| | | try {
|
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");
|
| | | executeDate = format.parse(limtDate);
|
| | | } catch (ParseException e) {
|
| | | // 赠送免单券
|
| | | String giveCoupon = userVipConfigService.getValueByKey("vip_pre_10_gift_givefree_coupon");
|
| | | if (!StringUtil.isNullOrEmpty(giveCoupon)) {
|
| | | int num = Integer.parseInt(giveCoupon);
|
| | | userSystemCouponService.freeCouponWin(uid, CouponTypeEnum.freeCouponGive,
|
| | | UserSystemCoupon.SOURCE_SYSTEM_PUSH, num, true);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | throw new UserVIPInfoException(1, "券赠送失败");
|
| | | }
|
| | | |
| | | try {
|
| | | // 升级消息
|
| | | UserVIPPreInfo pre1 = userVIPPreInfoService.getVipByProcess(uid, UserVIPPreInfo.PROCESS_2);
|
| | | int days = DateUtil.daysBetween(pre1.getCreateTime(), new Date());
|
| | | userAccountMsgNotificationService.vipUpgradeSuccess(uid, days);
|
| | | |
| | | // 升级提醒上级
|
| | | userVIPPreInfoService.remindBoss(uid, "超级会员", getPassItem(uid), upgradeTime, false);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | if (executeDate == null)
|
| | | return false;
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * 验证是否符合VIP
|
| | | * @param uid
|
| | | * @return
|
| | | */
|
| | | private String getPassItem(Long uid) {
|
| | | // 自购订单
|
| | | long doneZiGou = hongBaoV2CountService.counOrderByUidAndOrderType(uid, Constant.VIP_ORDER_PAY,
|
| | | HongBaoV2.TYPE_ZIGOU);
|
| | | // 分享订单
|
| | | long doneShare = hongBaoV2CountService.counOrderByUidAndOrderType(uid, Constant.VIP_ORDER_PAY,
|
| | | HongBaoV2.TYPE_SHARE_GOODS);
|
| | |
|
| | | // 1、直接粉丝(从 2020 年 1 月 1 日起直接粉丝产生有效订单)
|
| | | BigDecimal payMoney = new BigDecimal(userVipConfigService.getValueByKey("require_order_pay"));
|
| | | long teamNum = hongBaoV2CountService.countValidOrderTeamUserByUid(uid, executeDate.getTime(), payMoney);
|
| | | if (extra.getFirstLoginTime() == null || extra.getFirstLoginTime().getTime() < executeDate.getTime()) {
|
| | | long limitNum = Long.parseLong(userVipConfigService.getValueByKey("require_invite_num_old_user"));
|
| | | if (teamNum < limitNum)
|
| | | return false;
|
| | | } else {
|
| | | long limitNum = Long.parseLong(userVipConfigService.getValueByKey("require_invite_num_new_user"));
|
| | | if (teamNum < limitNum)
|
| | | return false;
|
| | | // 有效粉丝
|
| | | 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 limitZiGou = 0;
|
| | | String zigou = userVipConfigService.getValueByKey("vip_pre_10_zigou_order_count");
|
| | | if (!StringUtil.isNullOrEmpty(zigou)) {
|
| | | limitZiGou = Long.parseLong(zigou);
|
| | | }
|
| | |
|
| | | // 2、累计自购返利≥100 元(从注册板栗快省起);
|
| | | BigDecimal fanMoney = new BigDecimal(userVipConfigService.getValueByKey("require_fan_money"));
|
| | | BigDecimal purchase = hongBaoV2CountService.getRewardMoneyBySelf(uid);
|
| | | if (purchase.compareTo(fanMoney) < 0)
|
| | | return false;
|
| | | |
| | | // 3、累计金币≥10000 枚(从注册板栗快省起);
|
| | | BigDecimal goldCoin = integralDetailService.getCumulativeMoney(uid);
|
| | | BigDecimal limitGoldCoin = new BigDecimal(userVipConfigService.getValueByKey("require_gold_coin"));
|
| | | if (goldCoin.compareTo(limitGoldCoin) < 0)
|
| | | return false;
|
| | | |
| | | // 4、使用红包≥1 次
|
| | | List<Integer> list = new ArrayList<Integer>();
|
| | | list.add(BanLiShopOrder.STATE_SUCCESS);
|
| | | long useHongBao = banLiShopOrderService.countByUidAndState(uid, list);
|
| | | long limitHongBao = Long.parseLong(userVipConfigService.getValueByKey("require_shop_buy"));
|
| | | if (useHongBao < limitHongBao)
|
| | | return false;
|
| | | |
| | | // 符合条件
|
| | | return true;
|
| | | long limitShare = 0;
|
| | | String share = userVipConfigService.getValueByKey("vip_pre_10_share_order_count");
|
| | | if (!StringUtil.isNullOrEmpty(share)) {
|
| | | limitShare = Long.parseLong(share);
|
| | | }
|
| | | |
| | | 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 (doneZiGou >= limitZiGou) {
|
| | | item = "返利订单";
|
| | | } else if (doneShare >= limitShare) {
|
| | | item = "分享订单";
|
| | | } else if (doneFirst >= limitFirst && doneSecond >= limitSecond) {
|
| | | item = "邀请粉丝";
|
| | | }
|
| | | return item;
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 验证是否符合VIP
|
| | | * @param uid
|
| | | * @return
|
| | | */
|
| | | private boolean verifyVip(Long uid) {
|
| | | // 自购订单
|
| | | long doneZiGou = hongBaoV2CountService.counOrderByUidAndOrderType(uid, Constant.VIP_ORDER_PAY,
|
| | | HongBaoV2.TYPE_ZIGOU);
|
| | | // 分享订单
|
| | | long doneShare = hongBaoV2CountService.counOrderByUidAndOrderType(uid, Constant.VIP_ORDER_PAY,
|
| | | HongBaoV2.TYPE_SHARE_GOODS);
|
| | | |
| | | // 有效粉丝
|
| | | 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 limitZiGou = 0;
|
| | | String zigou = userVipConfigService.getValueByKey("vip_pre_10_zigou_order_count");
|
| | | if (!StringUtil.isNullOrEmpty(zigou)) {
|
| | | limitZiGou = Long.parseLong(zigou);
|
| | | }
|
| | | |
| | | long limitShare = 0;
|
| | | String share = userVipConfigService.getValueByKey("vip_pre_10_share_order_count");
|
| | | if (!StringUtil.isNullOrEmpty(share)) {
|
| | | limitShare = Long.parseLong(share);
|
| | | }
|
| | | |
| | | 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 (doneZiGou >= limitZiGou || doneShare >= limitShare || (doneFirst >= limitFirst && doneSecond >= limitSecond)) {
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | @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());
|
| | | userVIPInfoMapper.updateByPrimaryKeySelective(info);
|
| | |
|
| | | // 消息
|
| | | userAccountMsgNotificationService.vipUpgradeFail(uid, reason);
|
| | | }
|
| | |
|
| | | }
|