From 5c03e2dd5afd65c483ef5da8346e78abc29dc7e3 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 01 四月 2020 14:39:54 +0800
Subject: [PATCH] 新增淘客接口,订单返利比例计算相关service修改

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/UserVIPInfoServiceImpl.java |  181 ++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 162 insertions(+), 19 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..7068387 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;
@@ -87,9 +92,12 @@
 	@Lazy
 	@Resource
 	private UserSystemCouponService userSystemCouponService;
-	
+
 	@Resource
 	private UserVIPPreInfoService userVIPPreInfoService;
+
+	@Resource
+	private MsgAccountDetailService msgAccountDetailService;
 
 	@Override
 	@Transactional(rollbackFor = Exception.class)
@@ -261,8 +269,14 @@
 
 	@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;
@@ -305,29 +319,26 @@
 
 		// 1銆佺洿鎺ョ矇涓濓紙浠� 2020 骞� 1 鏈� 1 鏃ヨ捣鐩存帴绮変笣浜х敓鏈夋晥璁㈠崟锛�
 		BigDecimal payMoney = new BigDecimal(userVipConfigService.getValueByKey("require_order_pay"));
-//		long teamNum = hongBaoV2CountService.countValidOrderTeamUserByUid(uid,
-//				TimeUtil.convertDateToTemp(Constant.VIP_ONLINE_TIME), payMoney);
+		// long teamNum =
+		// hongBaoV2CountService.countValidOrderTeamUserByUid(uid,
+		// TimeUtil.convertDateToTemp(Constant.VIP_ONLINE_TIME), payMoney);
 		long teamNum = 0L;
 		long vipBegin = TimeUtil.convertDateToTemp(Constant.VIP_ONLINE_TIME);
 		List<ThreeSale> listThreeSale = threeSaleSerivce.getValidWorkerIdsByTime(uid, vipBegin);
 		if (listThreeSale != null && listThreeSale.size() > 0) {
-			for (ThreeSale three: listThreeSale) {
+			for (ThreeSale three : listThreeSale) {
 				UserInfo worker = three.getWorker();
 				if (worker == null || worker.getId() == null) {
 					continue;
 				}
 				// 1銆侀個璇峰叧绯绘垚鍔熷悗锛�2銆佸崟锛堝垎浜� + 鑷喘锛夊疄浠樻澶т簬1鍏�
-				long countValid = hongBaoV2CountService.countValidOrderByUidAndTime(worker.getId(), three.getSucceedTime(), payMoney);
+				long countValid = hongBaoV2CountService.countValidOrderByUidAndTime(worker.getId(),
+						three.getSucceedTime(), payMoney);
 				if (countValid > 0) {
-					teamNum ++;
+					teamNum++;
 				}
 			}
 		}
-		
-		
-		
-		
-		
 
 		// 鍖哄垎鑰佺敤鎴峰拰鏂扮敤鎴�
 		String limtDate = userVipConfigService.getValueByKey("vip_execute_time");
@@ -440,12 +451,123 @@
 		}
 	}
 
+	@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);
@@ -455,15 +577,36 @@
 		// 闃熷憳
 		long firstTeam = threeSaleSerivce.countFirstTeam(uid, 1);
 		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);
+
+		// 娑堟伅
+		MsgAccountVipDTO msgDto = new MsgAccountVipDTO();
+		msgDto.setStatus("浣犵殑璐﹀彿浠嶆槸楂樼骇浼氬憳");
+		msgDto.setReason(reason);
+		msgAccountDetailService.addMsgVIP(uid, "寰堟姳姝夛紒缁忎汉宸ュ鏍镐綘鏈弧瓒虫垨涓嶇鍚堝崌绾ц秴绾т細鍛樼殑鏉′欢", "濡傛湁鐤戦棶璇疯仈绯绘垜鐨�-浜哄伐瀹㈡湇", msgDto);
+	}
+
 }

--
Gitblit v1.8.0