From f7ed4e6bbe9be95d268481e66d70d90e70e07e12 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 28 一月 2019 19:45:53 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java |   90 ++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 81 insertions(+), 9 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java
index d2c7cc0..e325927 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java
@@ -8,6 +8,7 @@
 import java.util.List;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 
 import org.springframework.stereotype.Service;
@@ -43,14 +44,20 @@
 import com.yeshi.fanli.exception.UserAccountException;
 import com.yeshi.fanli.log.LogHelper;
 import com.yeshi.fanli.service.inter.hongbao.HongBaoService;
+import com.yeshi.fanli.service.inter.msg.UserAccountMsgNotificationService;
 import com.yeshi.fanli.service.inter.user.SpreadUserImgService;
 import com.yeshi.fanli.service.inter.user.UserAccountService;
+import com.yeshi.fanli.service.inter.user.UserExtraTaoBaoInfoService;
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.FileUtil;
 import com.yeshi.fanli.util.StringUtil;
 import com.yeshi.fanli.util.TimeUtil;
 import com.yeshi.fanli.util.factory.AccountDetailsFactory;
+import com.yeshi.fanli.util.factory.msg.MsgAccountDetailFactory;
 import com.yeshi.fanli.util.wx.WXLoginUtil;
+
+import net.sf.json.JSONObject;
+
 import org.yeshi.utils.JsonUtil;
 import org.yeshi.utils.tencentcloud.COSManager;
 
@@ -95,11 +102,27 @@
 	@Resource
 	private SpreadUserImgService spreadUserImgService;
 
+	@Resource
+	private UserAccountMsgNotificationService userAccountMsgNotificationService;
+	
+	@Resource
+	private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
+
 	@Transactional
 	@Override
-	public LoginResult login(HttpSession session, Boolean first, String appId, String code, String phone,
+	public LoginResult login(HttpServletRequest request, Boolean first, String appId, String code, String phone,
 			UserInfo tbUserInfo, boolean wxinstall, int loginType) throws UserAccountException {
 
+		JSONObject logInfo = new JSONObject();
+		logInfo.put("appId", appId);
+		logInfo.put("code", code);
+		logInfo.put("phone", phone);
+		if (tbUserInfo != null)
+			logInfo.put("tbUserInfo", tbUserInfo.getId());
+		logInfo.put("loginType", loginType);
+		LogHelper.lgoinInfo(logInfo.toString());
+
+		HttpSession session = request.getSession();
 		if (first != null && first == true)
 			session.removeAttribute("LAST_LOGIN_USER");
 		// 浼氳瘽涓笂娆$櫥褰曠殑鐢ㄦ埛
@@ -154,6 +177,11 @@
 							updateUserInfo.setPortrait(weiXinUser.getHeadimgurl());
 						updateUserInfo.setWxPic(weiXinUser.getHeadimgurl());
 						updateUserInfo.setWxName(weiXinUser.getNickname());
+						// 璁剧疆鐧诲綍鏃堕棿涓庣櫥褰曠被鍨�
+						updateUserInfo.setLastLoginTime(System.currentTimeMillis());
+						updateUserInfo.setLoginType(loginType);
+						updateUserInfo.setLastLoginIp(request.getRemoteHost());
+
 						userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
 						// 鍒犻櫎閭�璇峰浘鐗�
 						spreadUserImgService.deleteImgUrl(userInfo.getId());
@@ -167,6 +195,9 @@
 					userInfo.setWxOpenId(weiXinUser.getOpenid());
 					userInfo.setWxUnionId(weiXinUser.getUnionid());
 					userInfo.setWxPic(weiXinUser.getHeadimgurl());
+					userInfo.setLastLoginTime(System.currentTimeMillis());
+					userInfo.setLoginType(loginType);
+					userInfo.setLastLoginIp(request.getRemoteHost());
 					addUser(userInfo);
 
 					return new LoginResult(LoginResult.TYPE_NORMAL, userInfo);
@@ -197,13 +228,17 @@
 							// 缁戝畾鍏崇郴
 							UserInfo updateUserInfo = new UserInfo(userInfo.getId());
 
-							if (!StringUtil.isNullOrEmpty(lastUser.getPhone()))
+							if (!StringUtil.isNullOrEmpty(lastUser.getPhone())) {
 								updateUserInfo.setPhone(lastUser.getPhone());
-
+								userAccountMsgNotificationService.bindingSuccess(userInfo.getId(),
+										MsgAccountDetailFactory.TYPE_PHONE);
+							}
 							if (!StringUtil.isNullOrEmpty(lastUser.getOpenid())) {
 								updateUserInfo.setOpenid(lastUser.getOpenid());
 								updateUserInfo.setTbName(lastUser.getTbName());
 								updateUserInfo.setTbPic(lastUser.getTbPic());
+								userAccountMsgNotificationService.bindingSuccess(userInfo.getId(),
+										MsgAccountDetailFactory.TYPE_TB);
 							}
 							updateUserInfo.setLastLoginTime(System.currentTimeMillis());
 							userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
@@ -247,6 +282,8 @@
 							userInfo.setTbPic(lastUser.getTbPic());
 						}
 						userInfo.setLastLoginTime(System.currentTimeMillis());
+						userInfo.setLoginType(loginType);
+						userInfo.setLastLoginIp(request.getRemoteHost());
 						addUser(userInfo);
 						session.removeAttribute("LAST_LOGIN_USER");
 						return new LoginResult(LoginResult.TYPE_NORMAL, userInfo);
@@ -292,6 +329,15 @@
 	@Override
 	public LoginResult loginNoInstallWX(String appId, String code, String phone, UserInfo tbUserInfo, int loginType)
 			throws UserAccountException {
+		JSONObject logInfo = new JSONObject();
+		logInfo.put("appId", appId);
+		logInfo.put("code", code);
+		logInfo.put("phone", phone);
+		if (tbUserInfo != null)
+			logInfo.put("tbUserInfo", tbUserInfo.getId());
+		logInfo.put("loginType", loginType);
+		LogHelper.lgoinInfo(logInfo.toString());
+
 		UserInfo userInfo = null;
 		WeiXinUser weiXinUser = null;
 		switch (loginType) {
@@ -499,6 +545,7 @@
 			moneyRecordMapper.insertSelective(moneyRecord);
 		}
 
+		userAccountMsgNotificationService.connectSuccess(mainUser.getId(), lessUser.getId());
 	}
 
 	/**
@@ -508,7 +555,12 @@
 	 * @param unionId
 	 * @return
 	 */
-	public UserInfo getUserInfoByWXUnionId(String appId, String unionId) {
+	public UserInfo getUserInfoByWXUnionId(String appId, String unionId) throws UserAccountException {
+		if (StringUtil.isNullOrEmpty(appId))
+			throw new UserAccountException(1, "appId涓虹┖");
+		if (StringUtil.isNullOrEmpty(unionId))
+			throw new UserAccountException(2, "unionId涓虹┖");
+
 		return userInfoMapper.getUserInfoByAppIdAndWXUnionId(appId, unionId);
 	}
 
@@ -519,8 +571,11 @@
 	 * @param openId
 	 * @return
 	 */
-	public UserInfo getUserInfoByTaoBaoOpenId(String appId, String openId) {
-
+	public UserInfo getUserInfoByTaoBaoOpenId(String appId, String openId) throws UserAccountException {
+		if (StringUtil.isNullOrEmpty(appId))
+			throw new UserAccountException(1, "appId涓虹┖");
+		if (StringUtil.isNullOrEmpty(openId))
+			throw new UserAccountException(2, "openId涓虹┖");
 		return userInfoMapper.getUserInfoByAppIdAndTaoBaoOpenId(appId, openId);
 	}
 
@@ -531,8 +586,11 @@
 	 * @param phone
 	 * @return
 	 */
-	public UserInfo getUserInfoByPhone(String appId, String phone) {
-
+	public UserInfo getUserInfoByPhone(String appId, String phone) throws UserAccountException {
+		if (StringUtil.isNullOrEmpty(appId))
+			throw new UserAccountException(1, "appId涓虹┖");
+		if (StringUtil.isNullOrEmpty(phone))
+			throw new UserAccountException(2, "phone涓虹┖");
 		return userInfoMapper.getUserInfoByAppIdAndPhone(appId, phone);
 	}
 
@@ -613,6 +671,7 @@
 		UserInfo update = new UserInfo(user.getId());
 		update.setPhone(phone);
 		userInfoMapper.updateByPrimaryKeySelective(update);
+		userAccountMsgNotificationService.bindingSuccess(uid, MsgAccountDetailFactory.TYPE_PHONE);
 	}
 
 	@Override
@@ -633,6 +692,7 @@
 		UserInfo updateUserInfo = new UserInfo(uid);
 		updateUserInfo.setPhone("");
 		userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
+		userAccountMsgNotificationService.unBindingSuccess(uid, MsgAccountDetailFactory.TYPE_PHONE);
 	}
 
 	@Override
@@ -642,8 +702,12 @@
 		if (user == null)
 			throw new UserAccountException(4, "鐢ㄦ埛涓嶅瓨鍦�");
 
-		if (!StringUtil.isNullOrEmpty(user.getOpenid()))
+		if (!StringUtil.isNullOrEmpty(user.getOpenid()) && !user.getOpenid().equalsIgnoreCase(tbOpenId))
 			throw new UserAccountException(5, "褰撳墠璐﹀彿宸茬粡缁戝畾浜嗘窐瀹濓紝璇峰厛瑙g粦");
+
+		//缁戝畾鍚屼竴涓窐瀹濆彿
+		if (!StringUtil.isNullOrEmpty(user.getOpenid()) && user.getOpenid().equalsIgnoreCase(tbOpenId))
+			return;
 
 		UserInfo taoBaoUser = getUserInfoByTaoBaoOpenId(user.getAppId(), tbOpenId);
 		if (taoBaoUser != null)
@@ -658,6 +722,8 @@
 			update.setPortrait(tbPortrait);
 		}
 		userInfoMapper.updateByPrimaryKeySelective(update);
+
+		userAccountMsgNotificationService.bindingSuccess(uid, MsgAccountDetailFactory.TYPE_TB);
 	}
 
 	@Override
@@ -682,6 +748,10 @@
 		}
 
 		userInfoMapper.updateByPrimaryKeySelective(update);
+		
+		userExtraTaoBaoInfoService.unBindUid(uid);
+
+		userAccountMsgNotificationService.unBindingSuccess(uid, MsgAccountDetailFactory.TYPE_TB);
 	}
 
 	@Override
@@ -714,6 +784,8 @@
 			updateUserInfo.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
 		}
 		userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
+
+		userAccountMsgNotificationService.changeBindingSuccess(uid, MsgAccountDetailFactory.TYPE_WX);
 	}
 
 	@Override

--
Gitblit v1.8.0