From b2901a0793cfe3a1eb04318c1f8786c988e83108 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期五, 16 八月 2019 14:28:14 +0800
Subject: [PATCH] 的

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java |  140 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 136 insertions(+), 4 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java
index 03a867b..888c037 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java
@@ -322,7 +322,7 @@
 	}
 	
 	@Override
-	public String activateInviteCode(Long uid, String inviteCode, String platform, String version) throws UserInfoExtraException{
+	public String activateInviteCode(Long uid, String inviteCode) throws UserInfoExtraException{
 		if (uid == null || inviteCode == null) {
 			throw new UserInfoExtraException(1, "鐢ㄦ埛id銆侀個璇风爜涓嶈兘涓虹┖");
 		}
@@ -349,7 +349,7 @@
 		
 		// 缁戝畾鍏崇郴
 		try {
-			threeSaleSerivce.bindRelationshipByInviteCode(invitee, inviter, platform, version);
+			threeSaleSerivce.bindRelationshipByInviteCode(invitee, inviter);
 		} catch (ThreeSaleException e) {
 			try {
 				LogHelper.errorDetailInfo(e);
@@ -384,7 +384,7 @@
 	
 	
 	@Override
-	public void activationInviteWX(Long uid, String code, String platform, String version) throws UserInfoExtraException{
+	public void activationInviteWX(Long uid, String code) throws UserInfoExtraException{
 		if (uid == null || code == null) {
 			throw new UserInfoExtraException(1, "婵�娲讳俊鎭笉瀹屾暣");
 		}
@@ -465,7 +465,7 @@
 		
 		// 缁戝畾鍏崇郴
 		try {
-			threeSaleSerivce.bindRelationshipByWX(invitee, inviterId, threeSale, platform, version);
+			threeSaleSerivce.bindRelationshipByWX(invitee, inviterId, threeSale);
 		} catch (ThreeSaleException e) {
 			try {
 				LogHelper.errorDetailInfo(e);
@@ -581,4 +581,136 @@
 	}
 	
 	
+	
+	@Override
+	public UserInfo getUserByInviteCode(String inviteCode) throws UserInfoExtraException{
+		if (StringUtil.isNullOrEmpty(inviteCode)) {
+			throw new UserInfoExtraException(1, "閭�璇风爜涓嶈兘涓虹┖");
+		}
+		// 閭�璇蜂汉淇℃伅
+		UserInfo inviter = userInfoService.getInfoByPhoneOrInviteCode(inviteCode, inviteCode);
+		if (inviter == null) {
+			throw new UserInfoExtraException(1, "涓婄骇閭�璇风爜涓嶅瓨鍦�");
+		}
+		return inviter;
+	}
+	
+	
+	@Override
+	public UserInfo getInviterInfo(Long uid, String code) throws UserInfoExtraException{
+		if (code == null) {
+			throw new UserInfoExtraException(1, "code淇℃伅涓嶅畬鏁�");
+		}
+		
+		// 鐢ㄦ埛淇℃伅
+		UserInfo invitee = userInfoService.selectByPKey(uid);
+		if (invitee == null) {
+			throw new UserInfoExtraException(1, "鐢ㄦ埛涓嶅瓨鍦�");
+		}
+		
+		// 鐢ㄦ埛棰濆淇℃伅
+		UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid);
+		if (extra != null) {
+			String inviteCodeHas = extra.getInviteCode();
+			if (inviteCodeHas != null && inviteCodeHas.trim().length() > 0) {
+				throw new UserInfoExtraException(1, "宸茬粡婵�娲�, 鏃犻渶鍐嶆婵�娲�");
+			}
+		}
+		
+		// 鑾峰彇寰俊淇℃伅
+		WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code);
+		if (weiXinUser == null) {
+			throw new UserInfoExtraException(1, "寰俊鎺堟潈澶辫触");
+		}
+		String wxUnionId = weiXinUser.getUnionid();
+		if (wxUnionId == null || wxUnionId.trim().length() == 0) {
+			throw new UserInfoExtraException(1, "寰俊鎺堟潈澶辫触");
+		}
+		
+		// 楠岃瘉鏁版嵁
+		String wxUnionIdExist = invitee.getWxUnionId();
+		if (StringUtil.isNullOrEmpty(wxUnionIdExist)) {
+			UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid());
+			if (newUser != null) {
+				throw new UserInfoExtraException(1, "姝ゅ井淇″凡琚叾浠栧笎鍙风粦瀹�");
+			}
+		} else if (!wxUnionId.equals(wxUnionIdExist)){
+			throw new UserInfoExtraException(1, "缁戝畾寰俊涓庢縺娲诲井淇′笉涓�鑷�");
+		}
+		
+		// 閭�璇蜂汉ID
+		Long inviterId = userInviteRecordService.getNewestInviterId(wxUnionId);
+		if (inviterId == null) {
+			throw new UserInfoExtraException(1, "娌℃湁瀵瑰簲鐨勯個璇峰叧绯�");
+		}
+		
+		UserInfo inviter = userInfoService.selectByPKey(inviterId);
+		if (inviter == null) {
+			throw new UserInfoExtraException(1, "瀵瑰簲鐨勯個璇峰叧绯讳笉瀛樺湪");
+		}
+		return inviter;
+	}
+	
+	
+
+	@Override
+	public String activateUser(Long uid, String inviteUid) throws UserInfoExtraException{
+		if (uid == null || inviteUid == null) {
+			throw new UserInfoExtraException(1, "浼犻�抜d涓嶈兘涓虹┖");
+		}
+		
+		// 琚個璇蜂汉淇℃伅
+		UserInfo invitee = userInfoService.selectByPKey(uid);
+		if (invitee == null) {
+			throw new UserInfoExtraException(1, "鐢ㄦ埛涓嶅瓨鍦�");
+		}
+		
+		UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid);
+		if (extra != null) {
+			String inviteCodeHas = extra.getInviteCode();
+			if (inviteCodeHas != null && inviteCodeHas.trim().length() > 0) {
+				throw new UserInfoExtraException(1, "宸插瓨鍦ㄩ個璇风爜,璇峰埛鏂伴〉闈�");
+			}
+		}
+		
+		// 閭�璇蜂汉淇℃伅
+		UserInfo inviter = userInfoService.getInfoByPhoneOrInviteCode(inviteCode, inviteCode);
+		if (inviter == null) {
+			throw new UserInfoExtraException(1, "涓婄骇閭�璇风爜涓嶅瓨鍦�");
+		}
+		
+		// 缁戝畾鍏崇郴
+		try {
+			threeSaleSerivce.bindRelationshipByInviteCode(invitee, inviter);
+		} catch (ThreeSaleException e) {
+			try {
+				LogHelper.errorDetailInfo(e);
+			} catch (Exception e1) {
+				e1.printStackTrace();
+			}
+			throw new UserInfoExtraException(1, "婵�娲诲け璐�");
+		}
+		
+		
+		// 閭�璇风爜鏈夋晥銆佺敓鎴愰個璇风爜
+		String code = UserUtil.getInviteCode(uid); 
+		if (code == null || code.trim().length() == 0) {
+			throw new UserInfoExtraException(1, "婵�娲荤爜鐢熸垚澶辫触");
+		}
+		
+		UserInfoExtra userInfoExtra = new UserInfoExtra();
+		userInfoExtra.setUserInfo(invitee);
+		userInfoExtra.setInviteCode(code);
+		
+		// 淇濆瓨棰濆淇℃伅
+		saveUserInfoExtra(userInfoExtra);
+		
+		
+		Long id = userInfoExtra.getId();
+		if (id == null) {
+			throw new UserInfoExtraException(1, "婵�娲荤爜鐢熸垚澶辫触");
+		}
+		
+		return code;
+	}
 }

--
Gitblit v1.8.0