From d0f12da013131cd291cec6e81a12d661c02c4bf4 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期二, 17 三月 2020 12:14:27 +0800
Subject: [PATCH] 2.1

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/UserVIPInfoServiceImpl.java |  153 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 148 insertions(+), 5 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/UserVIPInfoServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/UserVIPInfoServiceImpl.java
index 39ae98a..15c0c11 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/UserVIPInfoServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/UserVIPInfoServiceImpl.java
@@ -17,7 +17,10 @@
 import org.yeshi.utils.DateUtil;
 
 import com.yeshi.fanli.dao.mybatis.user.vip.UserVIPInfoMapper;
+import com.yeshi.fanli.dto.msg.MsgAccountVipDTO;
 import com.yeshi.fanli.dto.msg.MsgOtherVIPDTO;
+import com.yeshi.fanli.entity.bus.msg.MsgAccountDetail;
+import com.yeshi.fanli.entity.bus.msg.MsgAccountDetail.MsgTypeAccountTypeEnum;
 import com.yeshi.fanli.entity.bus.user.HongBaoV2;
 import com.yeshi.fanli.entity.bus.user.ThreeSale;
 import com.yeshi.fanli.entity.bus.user.UserInfo;
@@ -30,6 +33,7 @@
 import com.yeshi.fanli.entity.shop.BanLiShopOrder;
 import com.yeshi.fanli.entity.system.ConfigKeyEnum;
 import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum;
+import com.yeshi.fanli.exception.msg.MsgAccountDetailException;
 import com.yeshi.fanli.exception.user.vip.UserVIPInfoException;
 import com.yeshi.fanli.service.inter.config.ConfigService;
 import com.yeshi.fanli.service.inter.count.HongBaoV2CountService;
@@ -41,6 +45,7 @@
 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.msg.MsgAccountDetailService;
 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;
@@ -90,6 +95,11 @@
 	
 	@Resource
 	private UserVIPPreInfoService userVIPPreInfoService;
+	
+	@Resource
+	private MsgAccountDetailService msgAccountDetailService;
+	
+	
 
 	@Override
 	@Transactional(rollbackFor = Exception.class)
@@ -440,12 +450,129 @@
 		}
 	}
 
+	
+	@Transactional(rollbackFor = Exception.class)
+	@Override
+	public void applyVIPNew(Long uid) throws UserVIPInfoException {
+		UserVIPPreInfo latestProcess = userVIPPreInfoService.getLatestProcessInfo(uid);
+		if (latestProcess == null || latestProcess.getProcess() != UserVIPPreInfo.PROCESS_2) {
+			throw new UserVIPInfoException(1, "璇ョ敤鎴疯繕涓嶆槸楂樼骇浼氬憳");
+		} 
+		
+		if (!verifyVipNew(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);
+		
+		
+		MsgAccountDetail detail = new MsgAccountDetail();
+		detail.setTitle("灏婃暚鐨勯珮绾т細鍛橈紝绯荤粺宸叉敹鍒颁綘鐨勮秴绾т細鍛樺崌绾х敵璇凤紝姝e湪鍙楃悊涓�");
+		detail.setBeiZhu("濡傛湁鐤戦棶璇疯仈绯绘垜鐨�-浜哄伐瀹㈡湇");
+		detail.setRead(false);
+		detail.setCreateTime(new Date());
+		detail.setUser(new UserInfo(uid));
+		detail.setContent("鎴戜滑灏嗕細鍦�48灏忔椂鍐呭畬鎴愬鏍�");
+		detail.setType(MsgTypeAccountTypeEnum.vipApply);
+		try {
+			msgAccountDetailService.addMsgAccountDetail(detail);
+		} catch (MsgAccountDetailException e) {
+			e.printStackTrace();
+		}
+	}
+	
+	
+	
+	@Transactional(rollbackFor = Exception.class)
+	@Override
+	public void passVIPApplyNew(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 (!verifyVipNew(uid))
+			throw new UserVIPInfoException(1, "绯荤粺楠岃瘉锛氫笉婊¤冻鍗囩骇鏉′欢");
+		
+		// 棰濆淇℃伅
+		UserInfoExtra userInfoExtra = userInfoExtraService.getByUidForUpdate(uid);
+		if (userInfoExtra == null)
+			throw new UserVIPInfoException(1, "鐢ㄦ埛淇℃伅涓嶅瓨鍦�");
+
+		// 閫氳繃瓒呯骇浼氬憳
+		UserVIPInfo info = new UserVIPInfo();
+		info.setId(userVIPInfo.getId());
+		info.setSuccessTime(new Date());
+		info.setState(UserVIPInfo.STATE_SUCCESS);
+		info.setUpdateTime(new Date());
+		userVIPInfoMapper.updateByPrimaryKeySelective(info);
+
+		// 娣诲姞閲戝竵
+		userInfoExtraService.addGoldCoinByUid(uid, Constant.VIP_COLDCOIN_NUM);
+		// 娣诲姞閲戝竵鏄庣粏
+		IntegralDetail detail = new IntegralDetail();
+		detail.setTitle("鍗囩骇VIP绂忓埄");
+		detail.setUid(uid);
+		detail.setMoney(Constant.VIP_COLDCOIN_NUM);
+		detail.setCreateTime(new Date());
+		detail.setUniqueKey("VIP-" + uid);
+		integralDetailService.insertSelective(detail);
+				
+		try {
+			// 濂栧姳鍒�
+			BigDecimal percent = new BigDecimal(configService.get(ConfigKeyEnum.exchangeRebatePercent.getKey()));
+			for (int i = 0; i < Constant.VIP_COUPON_REWARD_NUM; i++) {
+				userSystemCouponService.insertUserCoupon(uid, CouponTypeEnum.rebatePercentCoupon.name(),
+						UserSystemCoupon.SOURCE_SYSTEM_PUSH, percent, false);
+			}
+
+			// 璧犻�佸厤鍗曞埜
+			for (int i = 0; i < Constant.VIP_COUPON_GIVEFREE_NUM; i++) {
+				userSystemCouponService.insertUserCoupon(uid, CouponTypeEnum.freeCouponGive.name(),
+						UserSystemCoupon.SOURCE_SYSTEM_PUSH, null, false);
+			}
+		} catch (Exception e) {
+			throw new UserVIPInfoException(1, "鍒歌禒閫佸け璐�");
+		}
+
+		
+		// 娑堟伅
+		MsgAccountVipDTO msgDto = new MsgAccountVipDTO();
+		msgDto.setStatus("宸插皢浣犵殑璐︽埛鐢遍珮绾т細鍛樺崌绾т负瓒呯骇浼氬憳");
+		msgDto.setEquity("浠庢敹鍒版湰娑堟伅璧凤紝浣犲皢鑾峰緱鍏ㄩ儴瓒呯骇浼氬憳鏉冪泭");
+		msgAccountDetailService.addMsgVIP(uid, "鎭枩浣狅紒缁忎汉宸ュ鏍镐綘婊¤冻鍗囩骇瓒呯骇浼氬憳鏉′欢", "濡傛湁鐤戦棶璇疯仈绯绘垜鐨�-浜哄伐瀹㈡湇", msgDto);
+	}
+	
+	
 	/**
 	 * 楠岃瘉鏄惁绗﹀悎VIP
 	 * @param uid
 	 * @return
 	 */
-	private boolean verifyVip(Long uid) {
+	private boolean verifyVipNew(Long uid) {
 		// 閭�璇疯鍗�
 		long countZiGou = hongBaoV2CountService.counOrderByUidAndOrderType(uid, Constant.VIP_ORDER_PAY,
 				HongBaoV2.TYPE_ZIGOU);
@@ -457,13 +584,29 @@
 		long secondTeam = threeSaleSerivce.countSecondTeam(uid, 1);
 		if (countZiGou >= Constant.VIP_PROCESS_3_ZIGOU || countShare >= Constant.VIP_PROCESS_3_SHARE
 				|| (firstTeam >= Constant.VIP_PROCESS_3_TEAM && secondTeam >= Constant.VIP_PROCESS_3_TEAM_SECOND)) {
-			UserVIPPreInfo latestProcess = userVIPPreInfoService.getLatestProcessInfo(uid);
-			if (latestProcess == null || latestProcess.getProcess() != UserVIPPreInfo.PROCESS_2) {
-				userVIPPreInfoService.verifyVipPreInfo(uid, false);
-			} 
 			return true;
 		} 
 		return false;
 	}
 	
+	
+	@Transactional(rollbackFor = Exception.class)
+	@Override
+	public void rejectVIPApplyNew(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);
+		
+		// TODO娑堟伅
+	}
 }

--
Gitblit v1.8.0