From 678dd30c708e7457228a7696573ada707f810269 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期五, 06 十二月 2019 17:27:15 +0800
Subject: [PATCH] 会员审核 + 队员激活

---
 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 1f45dd5..0d36fe6 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
@@ -13,24 +13,38 @@
 
 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.dto.msg.MsgOtherVIPDTO;
+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.UserInviteSeparate;
 import com.yeshi.fanli.entity.bus.user.vip.UserVIPInfo;
 import com.yeshi.fanli.entity.shop.BanLiShopOrder;
 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.integral.IntegralDetailService;
+import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
 import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
 import com.yeshi.fanli.service.inter.user.vip.UserVipConfigService;
+import com.yeshi.fanli.util.TimeUtil;
 
 @Service
 public class UserVIPInfoServiceImpl implements UserVIPInfoService {
 
 	@Resource
 	private UserVIPInfoMapper userVIPInfoMapper;
+	
+	@Resource
+	private UserInfoService userInfoService;
 	
 	@Resource
 	private UserInfoExtraService userInfoExtraService;
@@ -46,6 +60,19 @@
 	
 	@Resource
 	private BanLiShopOrderService banLiShopOrderService;
+	
+	@Resource
+	private UserOtherMsgNotificationService userOtherMsgNotificationService;
+	
+	@Resource
+	private ThreeSaleSerivce threeSaleSerivce;
+	
+	@Resource
+	private UserInviteSeparateService userInviteSeparateService;
+	
+	@Resource
+	private ConfigService configService;
+
 	
 
 	@Override
@@ -66,20 +93,66 @@
 	@Transactional
 	@Override
 	public void passVIPApply(Long uid) throws UserVIPInfoException {
-		UserVIPInfo userInfo = userVIPInfoMapper.selectByPrimaryKeyForUpdate(uid);
-		if (userInfo == null) {
+		UserVIPInfo userVIPInfo = userVIPInfoMapper.selectByPrimaryKeyForUpdate(uid);
+		if (userVIPInfo == null) {
 			throw new UserVIPInfoException(1, "鐢ㄦ埛淇℃伅涓嶅瓨鍦�");
 		}
-		if (userInfo.getState() != UserVIPInfo.STATE_VERIFING) {
+		if (userVIPInfo.getState() != UserVIPInfo.STATE_VERIFING) {
 			throw new UserVIPInfoException(2, "鐢宠鏈浜庡鏍哥姸鎬�");
 		}
-
+		
+		if (!verifyConform(uid))
+			throw new UserVIPInfoException(1, "绯荤粺楠岃瘉锛氫笉婊¤冻鍗囩骇鏉′欢");
+		
 		UserVIPInfo info = new UserVIPInfo();
-		info.setId(userInfo.getId());
+		info.setId(userVIPInfo.getId());
 		info.setSuccessTime(new Date());
 		info.setState(UserVIPInfo.STATE_SUCCESS);
 		info.setUpdateTime(new Date());
 		userVIPInfoMapper.updateByPrimaryKeySelective(info);
+		
+		// 涓嬬骇鐨勮秴绾т細鍛� 涓嶈劚绂�
+		userInviteSeparateService.updateInvalidByBossId(uid);
+		
+		// 娑堟伅
+		MsgOtherVIPDTO msgOther = new MsgOtherVIPDTO();
+		msgOther.setContent1("鎭枩浣狅紝宸叉垚涓鸿秴绾т細鍛�");
+		msgOther.setContent2("婊¤冻鍗囩骇鏉′欢");
+		msgOther.setContent3(TimeUtil.formatDateDot(new Date()));
+		userOtherMsgNotificationService.passVIPApplyMsg(uid, "濡傛湁鐤戦棶璇疯仈绯绘垜鐨�-浜哄伐瀹㈡湇", msgOther);
+		
+		// 鏄惁瀛樺湪涓婄骇
+		ThreeSale threeSale = threeSaleSerivce.getMyBoss(uid);
+		if (threeSale == null) 
+			return;
+		// 涓婄骇鏄惁涓轰細鍛�
+		Long bossId = threeSale.getBoss().getId();
+		UserVIPInfo bossVIP = userVIPInfoMapper.selectByPrimaryKeyForUpdate(bossId);
+		if (bossVIP != null && bossVIP.getState() != null && bossVIP.getState() == UserVIPInfo.STATE_SUCCESS)
+			return;
+		
+		// 涔嬪墠鎻掑叆璁板綍澶辨晥
+		userInviteSeparateService.updateStateByWorkerIdAndBossId(uid, bossId, UserInviteSeparate.STATE_INVALID);
+		
+		// 闄愬埗鏃堕棿
+		int limitDays = Integer.parseInt(configService.get("invite_separate_limit_days"));
+		UserInviteSeparate inviteSeparate = new UserInviteSeparate();
+		inviteSeparate.setBossId(bossId);
+		inviteSeparate.setWorkerId(uid);
+		inviteSeparate.setState(UserInviteSeparate.STATE_INIT);
+		inviteSeparate.setEndTime(DateUtil.plusDayDate(limitDays, new Date()));
+		inviteSeparate.setCreateTime(new Date());
+		inviteSeparate.setUpdateTime(new Date());
+		userInviteSeparateService.insertSelective(inviteSeparate);
+		
+		
+		UserInfo userInfo = userInfoService.selectByPKey(uid);
+		// 娑堟伅
+		MsgOtherVIPDTO msgboss = new MsgOtherVIPDTO();
+		msgboss.setContent1(userInfo.getNickName() +" "+ uid);
+		msgboss.setContent2("浜�" + TimeUtil.formatDateDot(new Date()) + "鎴愬姛鍗囩骇鎴愪负瓒呯骇浼氬憳");
+		msgboss.setContent3("浠婃棩璧�"+limitDays+"澶╁唴锛屼綘鏈兘鎴愪负瓒呯骇浼氬憳灏嗕細涓庡叾浠ュ強鍏剁洿鎺ョ矇涓濊劚绂婚個璇峰叧绯� ");
+		userOtherMsgNotificationService.teamVIPCallBoss(bossId, "濡傛湁鐤戦棶璇疯仈绯绘垜鐨�-浜哄伐瀹㈡湇", msgboss);
 	}
 
 	@Transactional
@@ -98,6 +171,12 @@
 		info.setState(UserVIPInfo.STATE_INVALID);
 		info.setUpdateTime(new Date());
 		userVIPInfoMapper.updateByPrimaryKeySelective(info);
+		
+		// 娑堟伅
+		MsgOtherVIPDTO msgOther = new MsgOtherVIPDTO();
+		msgOther.setContent1("寰堟姳姝夛紝鏈�氳繃瓒呯骇浼氬憳鐢宠");
+		msgOther.setContent2("鏈弧瓒宠秴绾т細鍛樺崌绾ф潯浠舵垨鐤戜技鍑虹幇杩濊 ");
+		userOtherMsgNotificationService.rejectVIPApply(uid, "濡傛湁鐤戦棶璇疯仈绯绘垜鐨�-浜哄伐瀹㈡湇", msgOther);
 	}
 
 	@Transactional
@@ -212,4 +291,68 @@
 		// 绗﹀悎鏉′欢
 		return true;
 	}
+	
+	
+	@Override
+	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);
+	}
+	
+	
+	@Override
+	public void InviteSeparate(Long workerId, Long bossId) {
+		if (workerId == null || bossId == null)
+			return;
+		
+		// 鏌ヨ璁板綍
+		UserInviteSeparate userInviteSeparate = userInviteSeparateService.selectByWorkerIdAndBossId(workerId, bossId);
+		if (userInviteSeparate == null)
+			return;
+		
+		// 鏄惁瀛樺湪閭�璇峰叧绯�
+		ThreeSale threeSale = threeSaleSerivce.getMyBoss(workerId);
+		if (threeSale == null) 
+			return;
+		Long bossIdExist = threeSale.getBoss().getId();
+		if (bossIdExist == null || bossId.longValue() != bossIdExist.longValue())
+			return;
+		
+		// 涓婄骇浼氬憳鎯呭喌
+		boolean separate = false;
+		UserVIPInfo userVIPInfo = userVIPInfoMapper.selectByPrimaryKey(bossId);
+		if (userVIPInfo != null && userVIPInfo.getState() != null && userVIPInfo.getState() == UserVIPInfo.STATE_SUCCESS) {
+			if (userInviteSeparate.getEndTime().getTime() < userVIPInfo.getSuccessTime().getTime()) {
+				separate = true; // 缁撴潫鏃堕棿宸茬粡瓒呰繃
+			}
+		} else {
+			separate = true; // 涓婄骇闈炰細鍛� 
+		}
+		
+		if (!separate) {
+			// 鏈劚绂�
+			userInviteSeparateService.updateStateByWorkerIdAndBossId(workerId, bossId, UserInviteSeparate.STATE_INVALID);
+		} else {
+			// 鑴辩鍏崇郴
+			userInviteSeparateService.updateStateByWorkerIdAndBossId(workerId, bossId, UserInviteSeparate.STATE_SUCCESS);
+			
+			// 鑴辩閭�璇峰叧绯�
+			threeSaleSerivce.inviteSeparate(workerId, bossId);
+			
+			int limitDays = Integer.parseInt(configService.get("invite_separate_limit_days"));
+			// 娑堟伅
+			UserInfo userInfo = userInfoService.selectByPKey(workerId);
+			MsgOtherVIPDTO msgboss = new MsgOtherVIPDTO();
+			msgboss.setContent1(userInfo.getNickName() + workerId + "浜�" +TimeUtil.formatDateDot(userInviteSeparate.getCreateTime())+"鎴愬姛鍗囩骇鎴愪负瓒呯骇浼氬憳 ");
+			msgboss.setContent2("寰堥仐鎲撅紝浣犳湭鑳藉湪"+limitDays+"澶╁崌绾т负瓒呯骇浼氬憳 ");
+			msgboss.setContent3(" 宸蹭笌鍏朵互鍙婂叾鐩存帴绮変笣鑴辩浜嗛個璇峰叧绯�  ");
+			userOtherMsgNotificationService.teamSplitCallBoss(bossId, "濡傛湁鐤戦棶璇疯仈绯绘垜鐨�-浜哄伐瀹㈡湇", msgboss);
+		}
+	}
+	
+	
 }

--
Gitblit v1.8.0