From 98b1a0affd69bbe63223c21fdd2c404e8bedfccb Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 20 五月 2020 17:25:08 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/div' into 2.1.2

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/UserVIPPreInfoServiceImpl.java |  116 +++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 87 insertions(+), 29 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/UserVIPPreInfoServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/UserVIPPreInfoServiceImpl.java
index e81b3a7..f647afa 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/UserVIPPreInfoServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/vip/UserVIPPreInfoServiceImpl.java
@@ -34,6 +34,7 @@
 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.TeamUserLevelStatisticService;
 import com.yeshi.fanli.service.inter.user.vip.UserLevelUpgradedNotifyService;
 import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService;
 import com.yeshi.fanli.service.inter.user.vip.UserVipConfigService;
@@ -43,6 +44,7 @@
 import com.yeshi.fanli.util.annotation.RequestSerializableByKeyService;
 import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory;
 import com.yeshi.fanli.util.rocketmq.MQTopicName;
+import com.yeshi.fanli.util.user.UserLevelUtil;
 
 @Service
 public class UserVIPPreInfoServiceImpl implements UserVIPPreInfoService {
@@ -64,7 +66,6 @@
 
 	@Resource
 	private UserInfoExtraService userInfoExtraService;
-
 
 	@Resource
 	private UserInfoService userInfoService;
@@ -90,17 +91,49 @@
 	@Resource(name = "producer")
 	private Producer producer;
 
+	@Resource
+	private TeamUserLevelStatisticService teamUserLevelStatisticService;
+
+	@Transactional
 	@Override
 	public void addUserVIPPreInfo(UserVIPPreInfo info) throws UserVIPPreInfoException {
-		if (info == null || info.getUid() == null || info.getProcess() == null)
+		if (info == null || info.getUid() == null || info.getProcess() == null || info.getSourceType() == null)
 			throw new UserVIPPreInfoException(1, "淇℃伅涓嶅畬鏁�");
+		for (Long fuid : Constant.NO_UPGRADE_UIDS) {// 绂佹涓嶈兘鍗囩骇鐨勭敤鎴峰崌绾�
+			if (info.getUid().longValue() == fuid)
+				throw new UserVIPPreInfoException(100, "绂佹鍗囩骇");
+		}
 
 		UserVIPPreInfo oldInfo = userVIPPreInfoMapper.selectByUidAndProcess(info.getUid(), info.getProcess());
 		if (oldInfo != null)
 			throw new UserVIPPreInfoException(2, "杩涘害宸插瓨鍦�");
 		if (info.getCreateTime() == null)
 			info.setCreateTime(new Date());
+
+		UserVIPPreInfo old = getLatestProcessInfo(info.getUid());
+
 		userVIPPreInfoMapper.insertSelective(info);
+		// 璁剧疆缁熻鏁版嵁
+		teamUserLevelStatisticService.setUserLevel(info.getUid(), UserLevelUtil.getByLevel(info.getProcess()));
+
+		// 鍙戦�佺瓑绾у彉鍖栨秷鎭�
+		if (!Constant.IS_TEST) {
+			UserLevelEnum oldLevel = null;
+			if (old == null)
+				oldLevel = UserLevelEnum.daRen;
+			else {
+				oldLevel = UserLevelUtil.getByLevel(old.getProcess());
+			}
+
+			if (oldLevel == UserLevelEnum.normalVIP)
+				oldLevel = UserLevelEnum.daRen;
+
+			UserLevelChangedMQMsg msg = new UserLevelChangedMQMsg(info.getUid(), oldLevel,
+					UserLevelUtil.getByLevel(info.getProcess()), new Date());
+			Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userLevelChanged, msg);
+			producer.send(message);
+		}
+
 	}
 
 	@Override
@@ -172,32 +205,37 @@
 		// 楠岃瘉鏄惁婊¤冻鍗囩骇楂樼骇浼氬憳
 		if (doneZiGou >= limitZiGou7) {
 			try {
-				twoProcess(uid, limitZiGou7, null);
+				twoProcess(uid, limitZiGou7, null, false);
 			} catch (UserVIPPreInfoException e) {
-				
+
 			}
 		}
 	}
 
 	@Override
+	@RequestSerializableByKeyService(key = "#uid")
+	@Transactional(rollbackFor = Exception.class)
+	public void upgradeVipByTeamNum(Long uid) {
+		vipTeamVerify(uid);
+	}
+
+	@Override
 	@RequestSerializableByKeyService(key = "#tid")
 	@Transactional(rollbackFor = Exception.class)
-	public void upgradeVipByTeamNum(Long tid) {
+	public void upgradeBossVipByTeamNum(Long tid) {
 		UserInfo boss = threeSaleSerivce.getBoss(tid);
 		if (boss == null) {
 			return;
 		}
-		Long bossId = boss.getId();
+		vipTeamVerify(boss.getId());
+	}
 
-		// 楠岃瘉涓婁笂绾� -闂存帴绮変笣鏄惁婊¤冻
-		executor.execute(new Runnable() {
-			@Override
-			public void run() {
-				upgradeVipByTeamNum(bossId);
-			}
-		});
-
-		UserVIPPreInfo latest = getLatestProcessInfo(bossId);
+	/**
+	 * 楠岃瘉鐢ㄦ埛鏄惁婊¤冻鍗囩骇闃熷憳鏉′欢
+	 * @param uid
+	 */
+	private void vipTeamVerify(Long uid) {
+		UserVIPPreInfo latest = getLatestProcessInfo(uid);
 		if (latest != null && latest.getProcess() == UserVIPPreInfo.PROCESS_2) {
 			return;
 		}
@@ -205,7 +243,7 @@
 		// 鏈夋晥绮変笣
 		int doneFirst = 0;
 		int doneSecond = 0;
-		UserInviteValidNum userInviteValidNum = userInviteValidNumService.selectByPrimaryKey(bossId);
+		UserInviteValidNum userInviteValidNum = userInviteValidNumService.selectByPrimaryKey(uid);
 		if (userInviteValidNum != null) {
 			doneFirst = userInviteValidNum.getNumFirst() == null ? 0 : userInviteValidNum.getNumFirst();
 			doneSecond = userInviteValidNum.getNumSecond() == null ? 0 : userInviteValidNum.getNumSecond();
@@ -213,11 +251,17 @@
 
 		long limitFirst7 = 0;
 		String first7 = userVipConfigService.getValueByKey("vip_pre_7_first_level_team_count");
+		if (Constant.IS_TEST)
+			first7 = "30";
+
 		if (!StringUtil.isNullOrEmpty(first7)) {
 			limitFirst7 = Long.parseLong(first7);
 		}
+
 		long limitSecond7 = 0;
 		String second7 = userVipConfigService.getValueByKey("vip_pre_7_second_level_team_count");
+		if (Constant.IS_TEST)
+			second7 = "30";
 		if (!StringUtil.isNullOrEmpty(second7)) {
 			limitSecond7 = Long.parseLong(second7);
 		}
@@ -225,9 +269,9 @@
 		// 楠岃瘉鏄惁婊¤冻鍗囩骇楂樼骇浼氬憳
 		if (doneFirst >= limitFirst7 && doneSecond >= limitSecond7) {
 			try {
-				twoProcess(bossId, limitFirst7, limitSecond7);
+				twoProcess(uid, limitFirst7, limitSecond7, true);
 			} catch (UserVIPPreInfoException e) {
-				 
+
 			}
 		}
 	}
@@ -242,12 +286,12 @@
 	 * @param secondTeam
 	 */
 	@Transactional(rollbackFor = Exception.class)
-	private void twoProcess(Long uid, long limit1, Long limit2) throws UserVIPPreInfoException{
+	private void twoProcess(Long uid, long limit1, Long limit2, boolean teamPass) throws UserVIPPreInfoException {
 		String item = null;
-		if (limit2 == null) {
-			item = "杩斿埄+鍒嗕韩璁㈠崟";
-		} else {
+		if (teamPass) {
 			item = "鐩存帴+闂存帴绮変笣";
+		} else {
+			item = "杩斿埄+鍒嗕韩璁㈠崟";
 		}
 
 		Date upgradeTime = new Date();
@@ -256,6 +300,11 @@
 		info.setProcess(UserVIPPreInfo.PROCESS_2);
 		info.setCreateTime(upgradeTime);
 		info.setUpdateTime(upgradeTime);
+		if (teamPass)
+			info.setSourceType(UserVIPPreInfo.SOURCE_TYPE_TEAM);
+		else
+			info.setSourceType(UserVIPPreInfo.SOURCE_TYPE_ORDER);
+
 		addUserVIPPreInfo(info);
 
 		// 鍗囩骇寮规鎻愮ず
@@ -275,7 +324,7 @@
 				registerTime = userInfoRegister.getCreateTime();
 			}
 			int daysBetween = TimeUtil.getDayDifferenceCount(registerTime, upgradeTime);
-			userAccountMsgNotificationService.vipPreUpgrade(uid, "蹇渷杈句汉", "楂樼骇浼氬憳", daysBetween, limit1, limit2);
+			userAccountMsgNotificationService.vipPreUpgrade(uid, "蹇渷杈句汉", "楂樼骇浼氬憳", daysBetween, limit1, limit2, teamPass);
 
 			// 鐩存帴绮変笣鍗囩骇鎻愰啋
 			ThreeSale threeSale = threeSaleSerivce.getMyBoss(uid);
@@ -289,12 +338,6 @@
 			LogHelper.error(e);
 		}
 
-		if (!Constant.IS_TEST) {
-			UserLevelChangedMQMsg msg = new UserLevelChangedMQMsg(uid, UserLevelEnum.daRen, UserLevelEnum.highVIP,
-					new Date());
-			Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userLevelChanged, msg);
-			producer.send(message);
-		}
 	}
 
 	@Override
@@ -302,4 +345,19 @@
 		return userVIPPreInfoMapper.selectByUidAndProcess(uid, process);
 	}
 
+	@Override
+	public void deleteByPrimaryKey(Long id) {
+		userVIPPreInfoMapper.deleteByPrimaryKey(id);
+	}
+
+	@Override
+	public List<UserVIPPreInfo> listByProcess(int process, Date minTime, Date maxTime, int page, int pageSize) {
+		return userVIPPreInfoMapper.listByProcess(process, minTime, maxTime, (page - 1) * pageSize, pageSize);
+	}
+
+	@Override
+	public long countByProcess(int process, Date minTime, Date maxTime) {
+		return userVIPPreInfoMapper.countByProcess(process, minTime, maxTime);
+	}
+
 }

--
Gitblit v1.8.0