From ee88b54979c633a4ade518d4c124a2d07d378562 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 11 十月 2019 10:56:18 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/div' into div --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 154 insertions(+), 16 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 54cdc66..7afb008 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 @@ -1,5 +1,6 @@ package com.yeshi.fanli.service.impl.user; +import java.io.InputStream; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -13,6 +14,9 @@ import org.springframework.stereotype.Service; import org.yeshi.utils.DateUtil; +import org.yeshi.utils.HttpUtil; +import org.yeshi.utils.entity.FileUploadResult; +import org.yeshi.utils.tencentcloud.COSManager; import com.yeshi.fanli.dao.mybatis.user.UserInfoExtraMapper; import com.yeshi.fanli.dao.mybatis.user.UserRankRecordMapper; @@ -399,7 +403,7 @@ } // 鑾峰彇寰俊淇℃伅 - WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUserWithSavePortrait(code, wxAccount.getAppId(), + WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret()); if (weiXinUser == null) { throw new UserInfoExtraException(1, "寰俊鎺堟潈澶辫触"); @@ -438,7 +442,20 @@ String defaultPortrait = Constant.systemCommonConfig.getDefaultPortrait(); if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl()) && !StringUtil.isNullOrEmpty(defaultPortrait) && defaultPortrait.equals(invitee.getPortrait())) { - updateUserInfo.setPortrait(weiXinUser.getHeadimgurl()); + String headimgurl = weiXinUser.getHeadimgurl(); + InputStream asInputStream = HttpUtil.getAsInputStream(headimgurl); + if (asInputStream == null) { + LogHelper.test("寰俊澶村儚涓嬭浇澶辫触: " +weiXinUser.getUnionid()+ " " + headimgurl); + } else { + FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, + String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + "")); + if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) { + headimgurl = result.getUrl(); + } else { + LogHelper.test("寰俊澶村儚涓婁紶澶辫触: " +weiXinUser.getUnionid()+ " " + headimgurl); + } + } + updateUserInfo.setPortrait(headimgurl); } userInfoService.updateByPrimaryKeySelective(updateUserInfo); @@ -500,6 +517,137 @@ } } + + @Override + public void activeInviteWX(Long uid, WeiXinUser weiXinUser) throws UserInfoExtraException { + if (uid == null || weiXinUser == null) { + throw new UserInfoExtraException(1, "婵�娲讳俊鎭笉瀹屾暣"); + } + + // 鐢ㄦ埛淇℃伅 + 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, "宸茬粡婵�娲�, 鏃犻渶鍐嶆婵�娲�"); + } + } + + 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, "姝ゅ井淇″凡琚叾浠栧笎鍙风粦瀹�"); + } + + // 鑷姩缁戝畾寰俊 + UserInfo updateUserInfo = new UserInfo(uid); + updateUserInfo.setWxOpenId(weiXinUser.getOpenid()); + updateUserInfo.setWxUnionId(weiXinUser.getUnionid()); + updateUserInfo.setWxName(weiXinUser.getNickname()); + updateUserInfo.setWxPic(weiXinUser.getHeadimgurl()); + + // 灏嗛粯璁ゆ樀绉版浛鎹㈡垚寰俊鏄电О + String defaultNickName = Constant.systemCommonConfig.getDefaultNickName(); + if (!StringUtil.isNullOrEmpty(defaultNickName) && !StringUtil.isNullOrEmpty(weiXinUser.getNickname())) { + defaultNickName = defaultNickName + uid; + if ((defaultNickName.equals(invitee.getNickName()) || "杩斿埄鍒�".equals(invitee.getNickName()) + || invitee.getNickName().startsWith(Constant.systemCommonConfig.getDefaultNickName()))) { + updateUserInfo.setNickName(weiXinUser.getNickname()); + } + } + + // 灏嗛粯璁ゅご鍍忔浛鎹㈡垚寰俊澶村儚 + String defaultPortrait = Constant.systemCommonConfig.getDefaultPortrait(); + if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl()) && !StringUtil.isNullOrEmpty(defaultPortrait) + && defaultPortrait.equals(invitee.getPortrait())) { + String headimgurl = weiXinUser.getHeadimgurl(); + InputStream asInputStream = HttpUtil.getAsInputStream(headimgurl); + if (asInputStream == null) { + LogHelper.test("寰俊澶村儚涓嬭浇澶辫触: " +weiXinUser.getUnionid()+ " " + headimgurl); + } else { + FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, + String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + "")); + if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) { + headimgurl = result.getUrl(); + } else { + LogHelper.test("寰俊澶村儚涓婁紶澶辫触: " +weiXinUser.getUnionid()+ " " + headimgurl); + } + } + updateUserInfo.setPortrait(headimgurl); + } + + userInfoService.updateByPrimaryKeySelective(updateUserInfo); + + } else if (!wxUnionId.equals(wxUnionIdExist)) { + throw new UserInfoExtraException(1, "缁戝畾寰俊涓庢縺娲诲井淇′笉涓�鑷�"); + } + + // 閭�璇蜂汉ID -1.5.3鏂扮増 + Long inviterId = userInviteRecordService.getNewestInviterId(wxUnionId); + + // 鍏煎1.5.3 涔嬪墠鐗堟湰 + ThreeSale threeSale = threeSaleSerivce.getByWorkerId(uid); + if (inviterId == null && threeSale != null) { + Long bossId = threeSale.getBoss().getId(); + UserInfoExtra inviterExtra = userInfoExtraMapper.getInfoExtraByUid(bossId); + if (inviterExtra != null && inviterExtra.getInviteCode() == null) { + // 鏇存柊閭�璇风爜 + UserInfoExtra inviterInfoExtra = new UserInfoExtra(); + inviterInfoExtra.setId(inviterExtra.getId()); + inviterInfoExtra.setInviteCode(UserUtil.getInviteCode(bossId)); + userInfoExtraMapper.updateByPrimaryKeySelective(inviterInfoExtra); + } + } + + // 娌℃湁琚個璇疯繃 + if (inviterId == null && threeSale == null) { + throw new UserInfoExtraException(1, "娌℃湁瀵瑰簲鐨勯個璇峰叧绯�"); + } + + // 缁戝畾鍏崇郴 + try { + threeSaleSerivce.bindRelationshipByWX(invitee, inviterId, threeSale); + } catch (ThreeSaleException e) { + try { + LogHelper.errorDetailInfo(e); + } catch (Exception e1) { + e1.printStackTrace(); + } + throw new UserInfoExtraException(1, "鍏崇郴缁戝畾鏃跺け璐�"); + } + + // 閭�璇风爜鏈夋晥銆佺敓鎴愰個璇风爜 + String inviteCode = UserUtil.getInviteCode(uid); + if (inviteCode == null || inviteCode.trim().length() == 0) { + throw new UserInfoExtraException(1, "婵�娲荤爜鐢熸垚澶辫触"); + } + // 淇濆瓨閭�璇风爜 + UserInfoExtra userInfoExtra = new UserInfoExtra(); + userInfoExtra.setUserInfo(invitee); + userInfoExtra.setInviteCode(inviteCode); + userInfoExtra.setUpdateTime(new Date()); + if (extra != null) { + userInfoExtra.setId(extra.getId()); + userInfoExtraMapper.updateByPrimaryKeySelective(userInfoExtra); + } else { + userInfoExtra.setCreateTime(new Date()); + userInfoExtraMapper.insertSelective(userInfoExtra); + } + } + @Override public UserInfoExtra getUserInfoExtra(Long uid) { return userInfoExtraMapper.getInfoExtraByUid(uid); @@ -606,9 +754,9 @@ } @Override - public UserInfo getInviterInfo(WXAccountInfoDTO wxAccount, Long uid, String code) throws UserInfoExtraException { - if (code == null) { - throw new UserInfoExtraException(1, "code淇℃伅涓嶅畬鏁�"); + public UserInfo getInviterInfo(Long uid, String wxUnionId) throws UserInfoExtraException { + if (wxUnionId == null) { + throw new UserInfoExtraException(1, "unionId淇℃伅涓嶅畬鏁�"); } // 鐢ㄦ埛淇℃伅 @@ -626,20 +774,10 @@ } } - // 鑾峰彇寰俊淇℃伅 - WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret()); - 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()); + UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(wxUnionId); if (newUser != null) { throw new UserInfoExtraException(1, "姝ゅ井淇″凡琚叾浠栧笎鍙风粦瀹�"); } -- Gitblit v1.8.0