From 2ba431be9c12a79783e0f9ef249292b7fa95f2a1 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期一, 25 一月 2021 19:13:58 +0800 Subject: [PATCH] 拼多多备案调整 --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java | 1401 +++++++++++++++++++++++++++++---------------------------- 1 files changed, 708 insertions(+), 693 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 65dd174..9628197 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 @@ -15,7 +15,9 @@ import javax.annotation.Resource; +import com.yeshi.fanli.dao.user.UserGoodsChannelConfigDao; import com.yeshi.fanli.entity.SystemEnum; +import com.yeshi.fanli.entity.goods.UserGoodsChannelConfig; import com.yeshi.fanli.util.*; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; @@ -68,819 +70,832 @@ @Service public class UserInfoExtraServiceImpl implements UserInfoExtraService { - @Resource - private UserInfoExtraMapper userInfoExtraMapper; + @Resource + private UserInfoExtraMapper userInfoExtraMapper; - @Resource - private UserRankRecordMapper userRankRecordMapper; + @Resource + private UserRankRecordMapper userRankRecordMapper; - @Resource - private UserRankService userRankService; + @Resource + private UserRankService userRankService; - @Resource - private CommonOrderCountService commonOrderCountService; + @Resource + private CommonOrderCountService commonOrderCountService; - @Resource - private ConfigService configService; + @Resource + private ConfigService configService; - @Resource - private ThreeSaleSerivce threeSaleSerivce; + @Resource + private ThreeSaleSerivce threeSaleSerivce; - @Resource - private UserInfoService userInfoService; + @Resource + private UserInfoService userInfoService; - @Resource - private UserAccountService userAccountService; + @Resource + private UserAccountService userAccountService; - @Resource - private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService; + @Resource + private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService; - @Resource - private UserInviteRecordService userInviteRecordService; + @Resource + private UserInviteRecordService userInviteRecordService; - @Resource - @Lazy - private UserActivedRecordService userActivedRecordService; - - @Resource - private UserAccountMsgNotificationService userAccountMsgNotificationService; + @Resource + @Lazy + private UserActivedRecordService userActivedRecordService; - @Resource - private RocketMQManager rocketMQManager; + @Resource + private UserAccountMsgNotificationService userAccountMsgNotificationService; - @Override - public UserInfoExtraVO getRankInfo(Long uid) throws UserInfoExtraException, Exception { + @Resource + private RocketMQManager rocketMQManager; - UserInfoExtraVO extraVO = userInfoExtraMapper.getInfoExtraVOByUid(uid); - if (extraVO == null) { - throw new UserInfoExtraException(1, "鐢ㄦ埛闄勫姞淇℃伅涓嶅瓨鍦�"); - } + @Override + public UserInfoExtraVO getRankInfo(Long uid) throws UserInfoExtraException, Exception { - SystemEnum system= userInfoService.getUserSystem(uid); + UserInfoExtraVO extraVO = userInfoExtraMapper.getInfoExtraVOByUid(uid); + if (extraVO == null) { + throw new UserInfoExtraException(1, "鐢ㄦ埛闄勫姞淇℃伅涓嶅瓨鍦�"); + } - // 绛夌骇瀵圭収琛� - String contrast = configService.getValue(ConfigKeyEnum.userRankContrast.getKey(),system); - extraVO.setRankContrast(contrast); - // 鐗瑰埆鎻愰啋 - String rankTip = configService.getValue(ConfigKeyEnum.userRankTip.getKey(),system); - extraVO.setRankTip(rankTip); + SystemEnum system = userInfoService.getUserSystem(uid); - Integer rankOrderNum = extraVO.getRankOrderNum(); + // 绛夌骇瀵圭収琛� + String contrast = configService.getValue(ConfigKeyEnum.userRankContrast.getKey(), system); + extraVO.setRankContrast(contrast); + // 鐗瑰埆鎻愰啋 + String rankTip = configService.getValue(ConfigKeyEnum.userRankTip.getKey(), system); + extraVO.setRankTip(rankTip); - UserRank userRank = extraVO.getUserRank(); - // 闈掗摐绛夌骇涓嶈繑鍥炴伃鍠滆鍙� 娉細闈掗摐绛夌骇id 蹇呴』涓�1 - if (userRank != null && userRank.getId() != null && userRank.getId() > 1) { + Integer rankOrderNum = extraVO.getRankOrderNum(); - String rankMsg = null; - Integer rankSource = extraVO.getRankSource(); - switch (rankSource) { - case Constant.TYPE_REBATE: - rankMsg = "杩斿埄璁㈠崟"; - break; - case Constant.TYPE_SHAER: - rankMsg = "鍒嗕韩璁㈠崟"; - break; - case Constant.TYPE_INVITE: - rankMsg = "閭�璇疯鍗�"; - break; - default: - break; - } + UserRank userRank = extraVO.getUserRank(); + // 闈掗摐绛夌骇涓嶈繑鍥炴伃鍠滆鍙� 娉細闈掗摐绛夌骇id 蹇呴』涓�1 + if (userRank != null && userRank.getId() != null && userRank.getId() > 1) { - List<Object> listMsg = new ArrayList<Object>(); + String rankMsg = null; + Integer rankSource = extraVO.getRankSource(); + switch (rankSource) { + case Constant.TYPE_REBATE: + rankMsg = "杩斿埄璁㈠崟"; + break; + case Constant.TYPE_SHAER: + rankMsg = "鍒嗕韩璁㈠崟"; + break; + case Constant.TYPE_INVITE: + rankMsg = "閭�璇疯鍗�"; + break; + default: + break; + } - if (rankMsg != null) { - String color_red = "#E5005C"; - String color_black = "#333333"; + List<Object> listMsg = new ArrayList<Object>(); - Map<String, String> map1 = new HashMap<String, String>(); - map1.put("content", "涓婃湀"); - map1.put("color", color_black); - listMsg.add(map1); + if (rankMsg != null) { + String color_red = "#E5005C"; + String color_black = "#333333"; - Map<String, String> map2 = new HashMap<String, String>(); - map2.put("content", rankMsg); - map2.put("color", color_red); - listMsg.add(map2); + Map<String, String> map1 = new HashMap<String, String>(); + map1.put("content", "涓婃湀"); + map1.put("color", color_black); + listMsg.add(map1); - Map<String, String> map3 = new HashMap<String, String>(); - map3.put("content", "杈惧埌浜�"); - map3.put("color", color_black); - listMsg.add(map3); + Map<String, String> map2 = new HashMap<String, String>(); + map2.put("content", rankMsg); + map2.put("color", color_red); + listMsg.add(map2); - Map<String, String> map4 = new HashMap<String, String>(); - map4.put("content", rankOrderNum + ""); - map4.put("color", color_red); - listMsg.add(map4); + Map<String, String> map3 = new HashMap<String, String>(); + map3.put("content", "杈惧埌浜�"); + map3.put("color", color_black); + listMsg.add(map3); - Map<String, String> map5 = new HashMap<String, String>(); - map5.put("content", "鍗�"); - map5.put("color", color_black); - listMsg.add(map5); - extraVO.setGalaMsg(listMsg); - } - } + Map<String, String> map4 = new HashMap<String, String>(); + map4.put("content", rankOrderNum + ""); + map4.put("color", color_red); + listMsg.add(map4); - return extraVO; - } + Map<String, String> map5 = new HashMap<String, String>(); + map5.put("content", "鍗�"); + map5.put("color", color_black); + listMsg.add(map5); + extraVO.setGalaMsg(listMsg); + } + } - @Override - public void updateUserRankByUid(Long uid) throws UserInfoExtraException { - if (uid == null || uid == 0) { - return; - } + return extraVO; + } - boolean isupdateRank = true; - UserInfoExtra extra = new UserInfoExtra(); + @Override + public void updateUserRankByUid(Long uid) throws UserInfoExtraException { + if (uid == null || uid == 0) { + return; + } - UserInfoExtra userInfoExtra = userInfoExtraMapper.getInfoExtraByUid(uid); - if (userInfoExtra != null && userInfoExtra.getId() != null) { - // 鍒ゆ柇褰撴湀鏄惁宸叉洿鏂� - Date rankUpdateTime = userInfoExtra.getRankUpdateTime(); - if (rankUpdateTime != null) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); - if (sdf.format(rankUpdateTime).equals(sdf.format(new Date()))) { - isupdateRank = false; - } - } - extra.setId(userInfoExtra.getId()); - } else { - extra.setUserInfo(new UserInfo(uid)); - } + boolean isupdateRank = true; + UserInfoExtra extra = new UserInfoExtra(); - // 鏇存柊绛夌骇 - if (isupdateRank) { - List<UserRank> listRank = userRankService.getAllRank(); - if (listRank == null || listRank.size() == 0) { - throw new UserInfoExtraException(1, "绯荤粺绛夌骇涓嶅瓨鍦�"); - } + UserInfoExtra userInfoExtra = userInfoExtraMapper.getInfoExtraByUid(uid); + if (userInfoExtra != null && userInfoExtra.getId() != null) { + // 鍒ゆ柇褰撴湀鏄惁宸叉洿鏂� + Date rankUpdateTime = userInfoExtra.getRankUpdateTime(); + if (rankUpdateTime != null) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); + if (sdf.format(rankUpdateTime).equals(sdf.format(new Date()))) { + isupdateRank = false; + } + } + extra.setId(userInfoExtra.getId()); + } else { + extra.setUserInfo(new UserInfo(uid)); + } - int selfOrderNum = 0; - int sharedOrderNum = 0; - int inviteOrderNum = 0; - Map<String, Object> map = commonOrderCountService.lastMonthSettleOrderNumber(uid); - if (map != null) { - // 杩斿埄璁㈠崟 - if (map.get("totalSelf") != null) { - selfOrderNum = Integer.parseInt(map.get("totalSelf").toString()); - } + // 鏇存柊绛夌骇 + if (isupdateRank) { + List<UserRank> listRank = userRankService.getAllRank(); + if (listRank == null || listRank.size() == 0) { + throw new UserInfoExtraException(1, "绯荤粺绛夌骇涓嶅瓨鍦�"); + } - // 鍒嗕韩璁㈠崟 - if (map.get("totalShared") != null) { - sharedOrderNum = Integer.parseInt(map.get("totalShared").toString()); - } + int selfOrderNum = 0; + int sharedOrderNum = 0; + int inviteOrderNum = 0; + Map<String, Object> map = commonOrderCountService.lastMonthSettleOrderNumber(uid); + if (map != null) { + // 杩斿埄璁㈠崟 + if (map.get("totalSelf") != null) { + selfOrderNum = Integer.parseInt(map.get("totalSelf").toString()); + } - // 閭�璇疯鍗� - if (map.get("totalInvite") != null) { - inviteOrderNum = Integer.parseInt(map.get("totalInvite").toString()); - } - } + // 鍒嗕韩璁㈠崟 + if (map.get("totalShared") != null) { + sharedOrderNum = Integer.parseInt(map.get("totalShared").toString()); + } - UserRank rank = null; - for (UserRank userRank : listRank) { - // 閭�璇锋弧瓒� - Integer inviteNum = userRank.getInviteNum(); - if (inviteOrderNum >= inviteNum) { - rank = userRank; - extra.setRankOrderNum(inviteOrderNum); - extra.setRankSource(Constant.TYPE_INVITE); - } + // 閭�璇疯鍗� + if (map.get("totalInvite") != null) { + inviteOrderNum = Integer.parseInt(map.get("totalInvite").toString()); + } + } - // 鍒嗕韩婊¤冻 - int shareNum = userRank.getShareNum(); - if (sharedOrderNum >= shareNum) { - rank = userRank; - extra.setRankOrderNum(sharedOrderNum); - extra.setRankSource(Constant.TYPE_SHAER); - } + UserRank rank = null; + for (UserRank userRank : listRank) { + // 閭�璇锋弧瓒� + Integer inviteNum = userRank.getInviteNum(); + if (inviteOrderNum >= inviteNum) { + rank = userRank; + extra.setRankOrderNum(inviteOrderNum); + extra.setRankSource(Constant.TYPE_INVITE); + } - // 杩斿埄婊¤冻 - int directNum = userRank.getRebateNum(); - if (selfOrderNum >= directNum) { - rank = userRank; - extra.setRankOrderNum(selfOrderNum); - extra.setRankSource(Constant.TYPE_REBATE); - } + // 鍒嗕韩婊¤冻 + int shareNum = userRank.getShareNum(); + if (sharedOrderNum >= shareNum) { + rank = userRank; + extra.setRankOrderNum(sharedOrderNum); + extra.setRankSource(Constant.TYPE_SHAER); + } - if (rank != null) { - extra.setUserRank(rank); - } else { - rank = userRank; - // 榛樿鏈�浣庣瓑绾�:闈掗摐 - extra.setUserRank(rank); - extra.setRankOrderNum(selfOrderNum); - extra.setRankSource(Constant.TYPE_REBATE); - break; - } - } + // 杩斿埄婊¤冻 + int directNum = userRank.getRebateNum(); + if (selfOrderNum >= directNum) { + rank = userRank; + extra.setRankOrderNum(selfOrderNum); + extra.setRankSource(Constant.TYPE_REBATE); + } - // 绛夌骇鏇存柊鏃堕棿 褰撴湀1鍙� - Calendar calendar1 = Calendar.getInstance(); - calendar1.set(Calendar.DAY_OF_MONTH, 1); - extra.setRankUpdateTime(calendar1.getTime()); + if (rank != null) { + extra.setUserRank(rank); + } else { + rank = userRank; + // 榛樿鏈�浣庣瓑绾�:闈掗摐 + extra.setUserRank(rank); + extra.setRankOrderNum(selfOrderNum); + extra.setRankSource(Constant.TYPE_REBATE); + break; + } + } - // 淇濆瓨绛夌骇淇℃伅 - saveUserInfoExtra(extra); + // 绛夌骇鏇存柊鏃堕棿 褰撴湀1鍙� + Calendar calendar1 = Calendar.getInstance(); + calendar1.set(Calendar.DAY_OF_MONTH, 1); + extra.setRankUpdateTime(calendar1.getTime()); - // 淇濆瓨绛夌骇鍙樺寲璁板綍 - UserRankRecord userRankRecord = new UserRankRecord(); - userRankRecord.setUid(uid); - userRankRecord.setRankId(rank.getId()); - userRankRecord.setCreateTime(new Date()); - userRankRecordMapper.insertSelective(userRankRecord); - } - } + // 淇濆瓨绛夌骇淇℃伅 + saveUserInfoExtra(extra); - @Override - public void createUserInfoExtra(Long uid) throws UserInfoExtraException { - UserInfoExtra userInfoExtra = userInfoExtraMapper.getInfoExtraByUid(uid); - if (userInfoExtra != null) { - return; - } + // 淇濆瓨绛夌骇鍙樺寲璁板綍 + UserRankRecord userRankRecord = new UserRankRecord(); + userRankRecord.setUid(uid); + userRankRecord.setRankId(rank.getId()); + userRankRecord.setCreateTime(new Date()); + userRankRecordMapper.insertSelective(userRankRecord); + } + } - userInfoExtra = new UserInfoExtra(); - userInfoExtra.setUserInfo(new UserInfo(uid)); - userInfoExtra.setFirstLoginTime(new Date()); - userInfoExtra.setCreateTime(new Date()); - userInfoExtra.setUpdateTime(new Date()); - userInfoExtra.setActiveTime(new Date()); - userInfoExtraMapper.insertSelective(userInfoExtra); - } + @Override + public void createUserInfoExtra(Long uid) throws UserInfoExtraException { + UserInfoExtra userInfoExtra = userInfoExtraMapper.getInfoExtraByUid(uid); + if (userInfoExtra != null) { + return; + } - @Override - public UserInfoExtra saveUserInfoExtra(UserInfoExtra userInfoExtra) throws UserInfoExtraException { + userInfoExtra = new UserInfoExtra(); + userInfoExtra.setUserInfo(new UserInfo(uid)); + userInfoExtra.setFirstLoginTime(new Date()); + userInfoExtra.setCreateTime(new Date()); + userInfoExtra.setUpdateTime(new Date()); + userInfoExtra.setActiveTime(new Date()); + userInfoExtraMapper.insertSelective(userInfoExtra); + } - if (userInfoExtra == null) { - throw new UserInfoExtraException(1, "闄勫姞淇℃伅涓嶈兘涓虹┖"); - } + @Override + public UserInfoExtra saveUserInfoExtra(UserInfoExtra userInfoExtra) throws UserInfoExtraException { - Long extraId = userInfoExtra.getId(); - if (extraId != null) { - userInfoExtra.setUpdateTime(new Date()); - userInfoExtraMapper.updateByPrimaryKeySelective(userInfoExtra); - } else { - UserInfo userInfo = userInfoExtra.getUserInfo(); - if (userInfo == null || userInfo.getId() == null) { - throw new UserInfoExtraException(1, "鐢ㄦ埛涓嶅瓨鍦�"); - } + if (userInfoExtra == null) { + throw new UserInfoExtraException(1, "闄勫姞淇℃伅涓嶈兘涓虹┖"); + } - Long uid = userInfo.getId(); - UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); - if (extra != null && extra.getId() != null) { - userInfoExtra.setId(extra.getId()); - userInfoExtra.setUpdateTime(new Date()); - userInfoExtraMapper.updateByPrimaryKeySelective(userInfoExtra); - } else { - userInfoExtra.setCreateTime(new Date()); - userInfoExtra.setUpdateTime(new Date()); - userInfoExtraMapper.insertSelective(userInfoExtra); - } + Long extraId = userInfoExtra.getId(); + if (extraId != null) { + userInfoExtra.setUpdateTime(new Date()); + userInfoExtraMapper.updateByPrimaryKeySelective(userInfoExtra); + } else { + UserInfo userInfo = userInfoExtra.getUserInfo(); + if (userInfo == null || userInfo.getId() == null) { + throw new UserInfoExtraException(1, "鐢ㄦ埛涓嶅瓨鍦�"); + } - } - return userInfoExtra; - } + Long uid = userInfo.getId(); + UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); + if (extra != null && extra.getId() != null) { + userInfoExtra.setId(extra.getId()); + userInfoExtra.setUpdateTime(new Date()); + userInfoExtraMapper.updateByPrimaryKeySelective(userInfoExtra); + } else { + userInfoExtra.setCreateTime(new Date()); + userInfoExtra.setUpdateTime(new Date()); + userInfoExtraMapper.insertSelective(userInfoExtra); + } - @Override - @Transactional(rollbackFor = Exception.class) - public String activateInviteCode(Long uid, String inviteCode) throws UserInfoExtraException { - if (uid == null || inviteCode == null) - throw new UserInfoExtraException(1, "婵�娲讳俊鎭笉鑳戒负绌�"); + } + return userInfoExtra; + } - // 琚個璇蜂汉淇℃伅 - UserInfo invitee = userInfoService.selectByPKey(uid); - if (invitee == null) - throw new UserInfoExtraException(1, "鐢ㄦ埛涓嶅瓨鍦�"); + @Override + @Transactional(rollbackFor = Exception.class) + public String activateInviteCode(Long uid, String inviteCode) throws UserInfoExtraException { + if (uid == null || inviteCode == null) + throw new UserInfoExtraException(1, "婵�娲讳俊鎭笉鑳戒负绌�"); - // 棰濆淇℃伅 - UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); - if (extra != null && !StringUtil.isNullOrEmpty(extra.getInviteCode())) - throw new UserInfoExtraException(1, "宸茬粡婵�娲�, 鏃犻渶鍐嶆婵�娲�"); + // 琚個璇蜂汉淇℃伅 + UserInfo invitee = userInfoService.selectByPKey(uid); + if (invitee == null) + throw new UserInfoExtraException(1, "鐢ㄦ埛涓嶅瓨鍦�"); - inviteCode = inviteCode.toUpperCase(); - - // 閭�璇风爜瀵瑰簲鐢ㄦ埛淇℃伅 - UserInfo boss = userInfoService.getUserInfoByInviteCode(inviteCode); - if (boss == null || boss.getState() != UserInfo.STATE_NORMAL) - throw new UserInfoExtraException(1, "涓婄骇閭�璇风爜涓嶅瓨鍦�"); + // 棰濆淇℃伅 + UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); + if (extra != null && !StringUtil.isNullOrEmpty(extra.getInviteCode())) + throw new UserInfoExtraException(1, "宸茬粡婵�娲�, 鏃犻渶鍐嶆婵�娲�"); - // 鐢熸垚閭�璇峰叧绯� - return inviteCodeActive(uid, boss.getId()); - } + inviteCode = inviteCode.toUpperCase(); - @Override - @Transactional(rollbackFor = Exception.class) - public void activationInviteWX(WXAccountInfoDTO wxAccount, Long uid, String code) throws UserInfoExtraException { - if (uid == null || code == null) - throw new UserInfoExtraException(1, "婵�娲讳俊鎭笉瀹屾暣"); + // 閭�璇风爜瀵瑰簲鐢ㄦ埛淇℃伅 + UserInfo boss = userInfoService.getUserInfoByInviteCode(inviteCode); + if (boss == null || boss.getState() != UserInfo.STATE_NORMAL) + throw new UserInfoExtraException(1, "涓婄骇閭�璇风爜涓嶅瓨鍦�"); - UserInfo invitee = userInfoService.selectByPKey(uid); - if (invitee == null) - throw new UserInfoExtraException(1, "鐢ㄦ埛涓嶅瓨鍦�"); + // 鐢熸垚閭�璇峰叧绯� + return inviteCodeActive(uid, boss.getId()); + } - // 棰濆淇℃伅 - UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); - if (extra != null && !StringUtil.isNullOrEmpty(extra.getInviteCode())) - throw new UserInfoExtraException(1, "宸茬粡婵�娲�, 鏃犻渶鍐嶆婵�娲�"); + @Override + @Transactional(rollbackFor = Exception.class) + public void activationInviteWX(WXAccountInfoDTO wxAccount, Long uid, String code) throws UserInfoExtraException { + if (uid == null || code == null) + throw new UserInfoExtraException(1, "婵�娲讳俊鎭笉瀹屾暣"); - // 鑾峰彇寰俊淇℃伅 - WeiXinUser weiXinUser = WXAppLoginUtil.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, "寰俊鎺堟潈澶辫触"); - } + UserInfo invitee = userInfoService.selectByPKey(uid); + if (invitee == null) + throw new UserInfoExtraException(1, "鐢ㄦ埛涓嶅瓨鍦�"); - // 楠岃瘉鏁版嵁 - String wxUnionIdExist = invitee.getWxUnionId(); - if (StringUtil.isNullOrEmpty(wxUnionIdExist)) { - UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(),invitee.getSystem()); - if (newUser != null) { - throw new UserInfoExtraException(1, "姝ゅ井淇″凡琚叾浠栧笎鍙风粦瀹�"); - } + // 棰濆淇℃伅 + UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); + if (extra != null && !StringUtil.isNullOrEmpty(extra.getInviteCode())) + 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()); + // 鑾峰彇寰俊淇℃伅 + WeiXinUser weiXinUser = WXAppLoginUtil.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 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 wxUnionIdExist = invitee.getWxUnionId(); + if (StringUtil.isNullOrEmpty(wxUnionIdExist)) { + UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(), invitee.getSystem()); + if (newUser != null) { + throw new UserInfoExtraException(1, "姝ゅ井淇″凡琚叾浠栧笎鍙风粦瀹�"); + } - // 灏嗛粯璁ゅご鍍忔浛鎹㈡垚寰俊澶村儚 - 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(FilePathEnum.userWXPortrait.getPath() + "%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); - } + // 鑷姩缁戝畾寰俊 + 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(FilePathEnum.userWXPortrait.getPath() + "%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, "缁戝畾寰俊涓庢縺娲诲井淇′笉涓�鑷�"); + } + + // 鏄惁瀛樺湪閭�璇蜂汉 + Long inviterId = userInviteRecordService.getNewestInviterId(wxUnionId); + if (inviterId == null) + throw new UserInfoExtraException(1, "娌℃湁瀵瑰簲鐨勯個璇峰叧绯�"); + + UserInfo boss = userInfoService.selectByPKey(inviterId); + if (boss == null || boss.getState() != UserInfo.STATE_NORMAL) { + throw new UserInfoExtraException(1, "娌℃湁瀵瑰簲鐨勯個璇峰叧绯�"); + } + + // 閭�璇风爜婵�娲� + inviteCodeActive(uid, boss.getId()); + } + + @Override + @Transactional(rollbackFor = Exception.class) + 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, "鐢ㄦ埛涓嶅瓨鍦�"); + } + + 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(), invitee.getSystem()); + 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(FilePathEnum.userWXPortrait.getPath() + "%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); + if (inviterId == null) { + throw new UserInfoExtraException(1, "娌℃湁瀵瑰簲鐨勯個璇峰叧绯�"); + } + + UserInfo boss = userInfoService.selectByPKey(inviterId); + if (boss == null || boss.getState() != UserInfo.STATE_NORMAL) { + throw new UserInfoExtraException(1, "娌℃湁瀵瑰簲鐨勯個璇峰叧绯�"); + } - userInfoService.updateByPrimaryKeySelective(updateUserInfo); + // 閭�璇风爜婵�娲� + inviteCodeActive(uid, boss.getId()); + } - } else if (!wxUnionId.equals(wxUnionIdExist)) { - throw new UserInfoExtraException(1, "缁戝畾寰俊涓庢縺娲诲井淇′笉涓�鑷�"); - } - // 鏄惁瀛樺湪閭�璇蜂汉 - Long inviterId = userInviteRecordService.getNewestInviterId(wxUnionId); - if (inviterId == null) - throw new UserInfoExtraException(1, "娌℃湁瀵瑰簲鐨勯個璇峰叧绯�"); - - UserInfo boss = userInfoService.selectByPKey(inviterId); - if (boss == null || boss.getState() != UserInfo.STATE_NORMAL) { - throw new UserInfoExtraException(1, "娌℃湁瀵瑰簲鐨勯個璇峰叧绯�"); - } + /** + * 閭�璇峰叧绯荤敓鎴愭縺娲荤爜 + * + * @param uid + * @param bossId + * @return + * @throws UserInfoExtraException + */ + private String inviteCodeActive(Long uid, Long bossId) throws UserInfoExtraException { + UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); + if (extra != null && !StringUtil.isNullOrEmpty(extra.getInviteCode())) { + throw new UserInfoExtraException(1, "宸茬粡婵�娲�, 鏃犻渶鍐嶆婵�娲�"); + } - // 閭�璇风爜婵�娲� - inviteCodeActive(uid, boss.getId()); - } + // 缁戝畾鍏崇郴 + try { + threeSaleSerivce.bindInviteRelationship(uid, bossId); + } catch (ThreeSaleException e) { + try { + LogHelper.errorDetailInfo(e); + } catch (Exception e1) { + e1.printStackTrace(); + } + throw new UserInfoExtraException(1, "鍏崇郴缁戝畾鏃跺け璐�"); + } - @Override - @Transactional(rollbackFor = Exception.class) - public void activeInviteWX(Long uid, WeiXinUser weiXinUser) throws UserInfoExtraException { - if (uid == null || weiXinUser == null) { - throw new UserInfoExtraException(1, "婵�娲讳俊鎭笉瀹屾暣"); - } + // 鐢熸垚閭�璇风爜 + String inviteCode = createInviteCode(uid); + if (StringUtil.isNullOrEmpty(inviteCode)) + throw new UserInfoExtraException(1, "婵�娲荤爜鐢熸垚澶辫触"); - // 鐢ㄦ埛淇℃伅 - UserInfo invitee = userInfoService.selectByPKey(uid); - if (invitee == null) { - throw new UserInfoExtraException(1, "鐢ㄦ埛涓嶅瓨鍦�"); - } + UserInfoExtra userInfoExtra = new UserInfoExtra(); + userInfoExtra.setUserInfo(new UserInfo(uid)); + 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); + } - String wxUnionId = weiXinUser.getUnionid(); - if (wxUnionId == null || wxUnionId.trim().length() == 0) { - throw new UserInfoExtraException(1, "寰俊鎺堟潈澶辫触"); - } + userActivedRecordService.add(new UserActivedRecord(uid)); - // 楠岃瘉鏁版嵁 - String wxUnionIdExist = invitee.getWxUnionId(); - if (StringUtil.isNullOrEmpty(wxUnionIdExist)) { - UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(),invitee.getSystem()); - if (newUser != null) { - throw new UserInfoExtraException(1, "姝ゅ井淇″凡琚叾浠栧笎鍙风粦瀹�"); - } + if (!Constant.IS_TEST) { // 鍙戦�佹縺娲绘垚鍔熸秷鎭� + Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.inviteCodeActive, + new InviteCodeActiveMQMsg(uid, new Date())); + rocketMQManager.sendNormalMsg(message, null); + } - // 鑷姩缁戝畾寰俊 - UserInfo updateUserInfo = new UserInfo(uid); - updateUserInfo.setWxOpenId(weiXinUser.getOpenid()); - updateUserInfo.setWxUnionId(weiXinUser.getUnionid()); - updateUserInfo.setWxName(weiXinUser.getNickname()); - updateUserInfo.setWxPic(weiXinUser.getHeadimgurl()); + return inviteCode; + } - // 灏嗛粯璁ゆ樀绉版浛鎹㈡垚寰俊鏄电О - 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(FilePathEnum.userWXPortrait.getPath() + "%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); - } + @Override + public void updateActiveTime(Long uid, Date date) { + UserInfoExtra userInfoExtra = new UserInfoExtra(); + userInfoExtra.setUserInfo(new UserInfo(uid)); + userInfoExtra.setActiveTime(date); + userInfoExtraMapper.updateInfoExtraByUid(userInfoExtra); + } - userInfoService.updateByPrimaryKeySelective(updateUserInfo); + @Override + public UserInfoExtra getUserInfoExtra(Long uid) { + return userInfoExtraMapper.getInfoExtraByUid(uid); + } - } else if (!wxUnionId.equals(wxUnionIdExist)) { - throw new UserInfoExtraException(1, "缁戝畾寰俊涓庢縺娲诲井淇′笉涓�鑷�"); - } + @Override + public UserInfoExtra getUserALLInfo(Long uid) { + return userInfoExtraMapper.gerUserRank(uid); + } - // 閭�璇蜂汉ID -1.5.3鏂扮増 - Long inviterId = userInviteRecordService.getNewestInviterId(wxUnionId); - if (inviterId == null) { - throw new UserInfoExtraException(1, "娌℃湁瀵瑰簲鐨勯個璇峰叧绯�"); - } - - UserInfo boss = userInfoService.selectByPKey(inviterId); - if (boss == null || boss.getState() != UserInfo.STATE_NORMAL) { - throw new UserInfoExtraException(1, "娌℃湁瀵瑰簲鐨勯個璇峰叧绯�"); - } - - // 閭�璇风爜婵�娲� - inviteCodeActive(uid, boss.getId()); - } - - - /** - * 閭�璇峰叧绯荤敓鎴愭縺娲荤爜 - * @param uid - * @param bossId - * @return - * @throws UserInfoExtraException - */ - private String inviteCodeActive(Long uid, Long bossId) throws UserInfoExtraException{ - UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); - if (extra != null && !StringUtil.isNullOrEmpty(extra.getInviteCode())) { - throw new UserInfoExtraException(1, "宸茬粡婵�娲�, 鏃犻渶鍐嶆婵�娲�"); - } - - // 缁戝畾鍏崇郴 - try { - threeSaleSerivce.bindInviteRelationship(uid, bossId); - } catch (ThreeSaleException e) { - try { - LogHelper.errorDetailInfo(e); - } catch (Exception e1) { - e1.printStackTrace(); - } - throw new UserInfoExtraException(1, "鍏崇郴缁戝畾鏃跺け璐�"); - } + @Override + @Transactional + public UserInfoExtra getByUidForUpdate(Long uid) { + return userInfoExtraMapper.getByUidForUpdate(uid); + } - // 鐢熸垚閭�璇风爜 - String inviteCode = createInviteCode(uid); - if (StringUtil.isNullOrEmpty(inviteCode)) - throw new UserInfoExtraException(1, "婵�娲荤爜鐢熸垚澶辫触"); + @Override + @Transactional + public void updateGoldCoin(Long id, Integer goldCoin) { + userInfoExtraMapper.updateGoldCoin(id, goldCoin); + } - UserInfoExtra userInfoExtra = new UserInfoExtra(); - userInfoExtra.setUserInfo(new UserInfo(uid)); - 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); - } - - userActivedRecordService.add(new UserActivedRecord(uid)); + @Override + public void addGoldCoinByUid(Long uid, Integer goldCoin) { + userInfoExtraMapper.addGoldCoinByUid(uid, goldCoin); + } - if (!Constant.IS_TEST) { // 鍙戦�佹縺娲绘垚鍔熸秷鎭� - Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.inviteCodeActive, - new InviteCodeActiveMQMsg(uid, new Date())); - rocketMQManager.sendNormalMsg(message, null); - } - - return inviteCode; - } - - + @Override + public void updateByPrimaryKeySelective(UserInfoExtra record) { + userInfoExtraMapper.updateByPrimaryKeySelective(record); + } - @Override - public void updateActiveTime(Long uid, Date date) { - UserInfoExtra userInfoExtra = new UserInfoExtra(); - userInfoExtra.setUserInfo(new UserInfo(uid)); - userInfoExtra.setActiveTime(date); - userInfoExtraMapper.updateInfoExtraByUid(userInfoExtra); - } + @Override + public UserInfoExtraVO getInfoExtraVOByUid(Long uid) { + return userInfoExtraMapper.getInfoExtraVOByUid(uid); + } - @Override - public UserInfoExtra getUserInfoExtra(Long uid) { - return userInfoExtraMapper.getInfoExtraByUid(uid); - } + @Override + public String getInviteCodeByUid(Long uid) { + UserInfoExtra userInfoExtra = userInfoExtraMapper.getInfoExtraByUid(uid); + if (userInfoExtra != null) { + // vip閭�璇风爜浼樺厛 + if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCodeVip())) + return userInfoExtra.getInviteCodeVip(); - @Override - public UserInfoExtra getUserALLInfo(Long uid) { - return userInfoExtraMapper.gerUserRank(uid); - } + if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode())) + return userInfoExtra.getInviteCode(); - @Override - @Transactional - public UserInfoExtra getByUidForUpdate(Long uid) { - return userInfoExtraMapper.getByUidForUpdate(uid); - } + // 鏄惁婊¤冻鐢熶骇閭�璇风爜 + int relationshipNum = threeSaleSerivce.getSuccessRelationshipNum(uid); + if (relationshipNum > 0) { + try { + String inviteCode = createInviteCode(uid); + if (!StringUtil.isNullOrEmpty(inviteCode)) { + UserInfoExtra extra = new UserInfoExtra(); + extra.setId(userInfoExtra.getId()); + extra.setInviteCode(inviteCode); + userInfoExtraMapper.updateByPrimaryKeySelective(extra); + return inviteCode; + } + } catch (Exception e) { + LogHelper.errorDetailInfo(e); + } + } + } + return ""; + } - @Override - @Transactional - public void updateGoldCoin(Long id, Integer goldCoin) { - userInfoExtraMapper.updateGoldCoin(id, goldCoin); - } + /** + * 鐢熶骇閭�璇风爜 + * + * @param uid + * @return + */ + private String createInviteCode(Long uid) { + String inviteCode = null; + for (int i = 1; i <= 5; i++) { + inviteCode = UserUtil.getInviteCode(i, uid); + long countCode = userInfoExtraMapper.countByInviteCode(inviteCode); + if (countCode <= 0) + break; + } + return inviteCode; + } - @Override - public void addGoldCoinByUid(Long uid, Integer goldCoin) { - userInfoExtraMapper.addGoldCoinByUid(uid, goldCoin); - } + @Override + public long countByRankId(Long rankId) { + return userInfoExtraMapper.countByRankId(rankId); + } - @Override - public void updateByPrimaryKeySelective(UserInfoExtra record) { - userInfoExtraMapper.updateByPrimaryKeySelective(record); - } + @Override + public boolean isNewUser(Long uid) { + boolean isNew = false; + if (uid == null) { + return isNew; + } - @Override - public UserInfoExtraVO getInfoExtraVOByUid(Long uid) { - return userInfoExtraMapper.getInfoExtraVOByUid(uid); - } + UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); + if (extra != null && extra.getFirstLoginTime() != null) { + try { + int day = DateUtil.daysBetween(extra.getFirstLoginTime(), new Date()); + if (day <= 15) { + isNew = true; + } + } catch (ParseException e) { + e.printStackTrace(); + } + } + return isNew; + } - @Override - public String getInviteCodeByUid(Long uid) { - UserInfoExtra userInfoExtra = userInfoExtraMapper.getInfoExtraByUid(uid); - if (userInfoExtra != null) { - // vip閭�璇风爜浼樺厛 - if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCodeVip())) - return userInfoExtra.getInviteCodeVip(); + @Override + public UserRank gerUserRank(Long uid) { + if (uid == null) { + return null; + } - if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode())) - return userInfoExtra.getInviteCode(); + UserInfoExtra userInfoExtra = userInfoExtraMapper.gerUserRank(uid); + if (userInfoExtra == null) { + return null; + } + return userInfoExtra.getUserRank(); + } - // 鏄惁婊¤冻鐢熶骇閭�璇风爜 - int relationshipNum = threeSaleSerivce.getSuccessRelationshipNum(uid); - if (relationshipNum > 0) { - try { - String inviteCode = createInviteCode(uid); - if (!StringUtil.isNullOrEmpty(inviteCode)) { - UserInfoExtra extra = new UserInfoExtra(); - extra.setId(userInfoExtra.getId()); - extra.setInviteCode(inviteCode); - userInfoExtraMapper.updateByPrimaryKeySelective(extra); - return inviteCode; - } - } catch (Exception e) { - LogHelper.errorDetailInfo(e); - } - } - } - return ""; - } + @Override + public UserInfo getUserByInviteCode(String inviteCode) throws UserInfoExtraException { + if (StringUtil.isNullOrEmpty(inviteCode)) + throw new UserInfoExtraException(1, "閭�璇风爜涓嶈兘涓虹┖"); - /** - * 鐢熶骇閭�璇风爜 - * - * @param uid - * @return - */ - private String createInviteCode(Long uid) { - String inviteCode = null; - for (int i = 1; i <= 5; i++) { - inviteCode = UserUtil.getInviteCode(i, uid); - long countCode = userInfoExtraMapper.countByInviteCode(inviteCode); - if (countCode <= 0) - break; - } - return inviteCode; - } + UserInfo inviter = userInfoService.getUserInfoByInviteCode(inviteCode); + if (inviter == null) + throw new UserInfoExtraException(1, "涓婄骇閭�璇风爜涓嶅瓨鍦�"); - @Override - public long countByRankId(Long rankId) { - return userInfoExtraMapper.countByRankId(rankId); - } + if (inviter.getState() != UserInfo.STATE_NORMAL) { + throw new UserInfoExtraException(1, "涓婄骇閭�璇风爜涓嶅瓨鍦�"); + } - @Override - public boolean isNewUser(Long uid) { - boolean isNew = false; - if (uid == null) { - return isNew; - } + return inviter; + } - UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); - if (extra != null && extra.getFirstLoginTime() != null) { - try { - int day = DateUtil.daysBetween(extra.getFirstLoginTime(), new Date()); - if (day <= 15) { - isNew = true; - } - } catch (ParseException e) { - e.printStackTrace(); - } - } - return isNew; - } + @Override + public UserInfo getInviterInfo(Long uid, String wxUnionId) throws UserInfoExtraException { + if (wxUnionId == null) { + throw new UserInfoExtraException(1, "unionId淇℃伅涓嶅畬鏁�"); + } - @Override - public UserRank gerUserRank(Long uid) { - if (uid == null) { - return null; - } + // 鐢ㄦ埛淇℃伅 + UserInfo invitee = userInfoService.selectByPKey(uid); + if (invitee == null) { + throw new UserInfoExtraException(1, "鐢ㄦ埛涓嶅瓨鍦�"); + } - UserInfoExtra userInfoExtra = userInfoExtraMapper.gerUserRank(uid); - if (userInfoExtra == null) { - return null; - } - return userInfoExtra.getUserRank(); - } + // 鐢ㄦ埛棰濆淇℃伅 + UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); + if (extra != null) { + String inviteCodeHas = extra.getInviteCode(); + if (inviteCodeHas != null && inviteCodeHas.trim().length() > 0) { + throw new UserInfoExtraException(1, "宸茬粡婵�娲�, 鏃犻渶鍐嶆婵�娲�"); + } + } - @Override - public UserInfo getUserByInviteCode(String inviteCode) throws UserInfoExtraException { - if (StringUtil.isNullOrEmpty(inviteCode)) - throw new UserInfoExtraException(1, "閭�璇风爜涓嶈兘涓虹┖"); + // 楠岃瘉鏁版嵁 + String wxUnionIdExist = invitee.getWxUnionId(); + if (StringUtil.isNullOrEmpty(wxUnionIdExist)) { + UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(wxUnionId, invitee.getSystem()); + if (newUser != null) { + throw new UserInfoExtraException(1, "姝ゅ井淇″凡琚叾浠栧笎鍙风粦瀹�"); + } + } else if (!wxUnionId.equals(wxUnionIdExist)) { + throw new UserInfoExtraException(1, "缁戝畾寰俊涓庢縺娲诲井淇′笉涓�鑷�"); + } - UserInfo inviter = userInfoService.getUserInfoByInviteCode(inviteCode); - if (inviter == null) - throw new UserInfoExtraException(1, "涓婄骇閭�璇风爜涓嶅瓨鍦�"); - - if (inviter.getState() != UserInfo.STATE_NORMAL) { - throw new UserInfoExtraException(1, "涓婄骇閭�璇风爜涓嶅瓨鍦�"); - } + // 閭�璇蜂汉ID + Long inviterId = userInviteRecordService.getNewestInviterId(wxUnionId); + if (inviterId == null) { + throw new UserInfoExtraException(1, "娌℃湁瀵瑰簲鐨勯個璇峰叧绯�"); + } - return inviter; - } + UserInfo inviter = userInfoService.selectByPKey(inviterId); + if (inviter == null) { + throw new UserInfoExtraException(1, "瀵瑰簲鐨勯個璇峰叧绯讳笉瀛樺湪"); + } - @Override - public UserInfo getInviterInfo(Long uid, String wxUnionId) throws UserInfoExtraException { - if (wxUnionId == null) { - throw new UserInfoExtraException(1, "unionId淇℃伅涓嶅畬鏁�"); - } + if (inviter.getState() != UserInfo.STATE_NORMAL) { + throw new UserInfoExtraException(1, "瀵瑰簲鐨勯個璇峰叧绯讳笉瀛樺湪"); + } - // 鐢ㄦ埛淇℃伅 - UserInfo invitee = userInfoService.selectByPKey(uid); - if (invitee == null) { - throw new UserInfoExtraException(1, "鐢ㄦ埛涓嶅瓨鍦�"); - } + return inviter; + } - // 鐢ㄦ埛棰濆淇℃伅 - UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); - if (extra != null) { - String inviteCodeHas = extra.getInviteCode(); - if (inviteCodeHas != null && inviteCodeHas.trim().length() > 0) { - throw new UserInfoExtraException(1, "宸茬粡婵�娲�, 鏃犻渶鍐嶆婵�娲�"); - } - } - // 楠岃瘉鏁版嵁 - String wxUnionIdExist = invitee.getWxUnionId(); - if (StringUtil.isNullOrEmpty(wxUnionIdExist)) { - UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(wxUnionId,invitee.getSystem()); - if (newUser != null) { - throw new UserInfoExtraException(1, "姝ゅ井淇″凡琚叾浠栧笎鍙风粦瀹�"); - } - } else if (!wxUnionId.equals(wxUnionIdExist)) { - throw new UserInfoExtraException(1, "缁戝畾寰俊涓庢縺娲诲井淇′笉涓�鑷�"); - } + @Transactional(rollbackFor = Exception.class) + @Override + public void updateInviteCodeVip(String inviteCodeVip, Long uid) throws UserInfoExtraException { + if (inviteCodeVip == null || inviteCodeVip.length() < 4 || inviteCodeVip.length() > 12) + throw new UserInfoExtraException(1, "閭�璇风爜蹇呴』涓�4鍒�12浣�"); - // 閭�璇蜂汉ID - Long inviterId = userInviteRecordService.getNewestInviterId(wxUnionId); - if (inviterId == null) { - throw new UserInfoExtraException(1, "娌℃湁瀵瑰簲鐨勯個璇峰叧绯�"); - } + UserInfoExtra extra = getUserInfoExtra(uid); + if (extra == null) + throw new UserInfoExtraException(2, "鐢ㄦ埛淇℃伅涓嶅瓨鍦�"); - UserInfo inviter = userInfoService.selectByPKey(inviterId); - if (inviter == null) { - throw new UserInfoExtraException(1, "瀵瑰簲鐨勯個璇峰叧绯讳笉瀛樺湪"); - } - - if (inviter.getState() != UserInfo.STATE_NORMAL) { - throw new UserInfoExtraException(1, "瀵瑰簲鐨勯個璇峰叧绯讳笉瀛樺湪"); - } - - return inviter; - } + if (StringUtil.isNullOrEmpty(extra.getInviteCode())) + throw new UserInfoExtraException(3, "閭�璇风爜灏氭湭婵�娲�"); + if (!StringUtil.isNullOrEmpty(extra.getInviteCodeVip())) + throw new UserInfoExtraException(4, "鍙兘淇敼涓�娆�"); - @Transactional(rollbackFor = Exception.class) - @Override - public void updateInviteCodeVip(String inviteCodeVip, Long uid) throws UserInfoExtraException { - if (inviteCodeVip == null || inviteCodeVip.length() < 4 || inviteCodeVip.length() > 12) - throw new UserInfoExtraException(1, "閭�璇风爜蹇呴』涓�4鍒�12浣�"); + // 杞崲鎴愬ぇ鍐� + inviteCodeVip = inviteCodeVip.toUpperCase(); - UserInfoExtra extra = getUserInfoExtra(uid); - if (extra == null) - throw new UserInfoExtraException(2, "鐢ㄦ埛淇℃伅涓嶅瓨鍦�"); + // 楠岃瘉鐗规畩鐮� + if (InviteCodeFilterUtil.isSpecialCode(inviteCodeVip)) + throw new UserInfoExtraException(5, "閭�璇风爜宸插瓨鍦�"); - if (StringUtil.isNullOrEmpty(extra.getInviteCode())) - throw new UserInfoExtraException(3, "閭�璇风爜灏氭湭婵�娲�"); + if (inviteCodeVip.equalsIgnoreCase(extra.getInviteCode())) + throw new UserInfoExtraException(5, "涓嶈兘涓哄師閭�璇风爜"); - if (!StringUtil.isNullOrEmpty(extra.getInviteCodeVip())) - throw new UserInfoExtraException(4, "鍙兘淇敼涓�娆�"); + long count = userInfoExtraMapper.countByInviteCode(inviteCodeVip); + if (count > 0) + throw new UserInfoExtraException(6, "閭�璇风爜宸插瓨鍦�"); - // 杞崲鎴愬ぇ鍐� - inviteCodeVip = inviteCodeVip.toUpperCase(); + UserInfoExtra update = new UserInfoExtra(); + update.setId(extra.getId()); + update.setInviteCodeVip(inviteCodeVip); + update.setUpdateTime(new Date()); + userInfoExtraMapper.updateByPrimaryKeySelective(update); - // 楠岃瘉鐗规畩鐮� - if (InviteCodeFilterUtil.isSpecialCode(inviteCodeVip)) - throw new UserInfoExtraException(5, "閭�璇风爜宸插瓨鍦�"); + if (!Constant.IS_TEST) { // 鍙戦�侀個璇风爜鏇存敼鎴愬姛鐨勬秷鎭� + Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userInfoUpdate, + new UserInfoUpdateMQMsg(uid, UserInfoUpdateTypeEnum.inviteCode, inviteCodeVip, + new Date())); + rocketMQManager.sendNormalMsg(message, null); + } - if (inviteCodeVip.equalsIgnoreCase(extra.getInviteCode())) - throw new UserInfoExtraException(5, "涓嶈兘涓哄師閭�璇风爜"); + // 娑堟伅 + userAccountMsgNotificationService.createChangeInviteCode(uid, extra.getInviteCode(), inviteCodeVip); + } - long count = userInfoExtraMapper.countByInviteCode(inviteCodeVip); - if (count > 0) - throw new UserInfoExtraException(6, "閭�璇风爜宸插瓨鍦�"); + @Override + public void uploadERCode(MultipartFile file, Long uid) { + UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); + if (extra == null) + return; - UserInfoExtra update = new UserInfoExtra(); - update.setId(extra.getId()); - update.setInviteCodeVip(inviteCodeVip); - update.setUpdateTime(new Date()); - userInfoExtraMapper.updateByPrimaryKeySelective(update); + // 鍘嬬缉 + String targetPath = FileUtil.getCacheDir() + "/erCode_" + uid + "_" + System.currentTimeMillis() + ".jpg"; + try { + Thumbnails.of(file.getInputStream()).size(200, 200).toFile(targetPath); + } catch (IOException e) { + LogHelper.errorDetailInfo(e); + return; + } - if (!Constant.IS_TEST) { // 鍙戦�侀個璇风爜鏇存敼鎴愬姛鐨勬秷鎭� - Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userInfoUpdate, - new UserInfoUpdateMQMsg(uid, UserInfoUpdateTypeEnum.inviteCode, inviteCodeVip, - new Date())); - rocketMQManager.sendNormalMsg(message, null); - } - - // 娑堟伅 - userAccountMsgNotificationService.createChangeInviteCode(uid, extra.getInviteCode(), inviteCodeVip); - } + // 鎵ц涓婁紶 + String filePath = FilePathEnum.userERcode.getPath() + UUID.randomUUID().toString().replace("-", "") + ".jpg"; + String fileLink = COSManager.getInstance().uploadFile(new File(targetPath), filePath).getUrl(); - @Override - public void uploadERCode(MultipartFile file, Long uid) { - UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); - if (extra == null) - return; + // 鍒犻櫎鏈湴鍥剧墖 + if (new File(targetPath).exists()) { + new File(targetPath).delete(); + } - // 鍘嬬缉 - String targetPath = FileUtil.getCacheDir() + "/erCode_" + uid + "_" + System.currentTimeMillis() + ".jpg"; - try { - Thumbnails.of(file.getInputStream()).size(200, 200).toFile(targetPath); - } catch (IOException e) { - LogHelper.errorDetailInfo(e); - return; - } + // 鍘熶簩缁寸爜 + String erCode = extra.getErCode(); - // 鎵ц涓婁紶 - String filePath = FilePathEnum.userERcode.getPath() + UUID.randomUUID().toString().replace("-", "") + ".jpg"; - String fileLink = COSManager.getInstance().uploadFile(new File(targetPath), filePath).getUrl(); + UserInfoExtra update = new UserInfoExtra(); + update.setId(extra.getId()); + update.setErCode(fileLink); + userInfoExtraMapper.updateByPrimaryKeySelective(update); - // 鍒犻櫎鏈湴鍥剧墖 - if (new File(targetPath).exists()) { - new File(targetPath).delete(); - } + // 鍘熶簩缁寸爜 + if (!StringUtil.isNullOrEmpty(erCode)) { + COSManager.getInstance().deleteFile(erCode); + } + } - // 鍘熶簩缁寸爜 - String erCode = extra.getErCode(); + @Resource + private UserGoodsChannelConfigDao userGoodsChannelConfigDao; - UserInfoExtra update = new UserInfoExtra(); - update.setId(extra.getId()); - update.setErCode(fileLink); - userInfoExtraMapper.updateByPrimaryKeySelective(update); + @Override + public String getPddFanliCustomerParams(Long uid) { + UserGoodsChannelConfig config = userGoodsChannelConfigDao.get(uid); + if (config == null || StringUtil.isNullOrEmpty(config.getPddFanliCustomerParams())) { + return uid + ""; + } + return config.getPddFanliCustomerParams(); + } - // 鍘熶簩缁寸爜 - if (!StringUtil.isNullOrEmpty(erCode)) { - COSManager.getInstance().deleteFile(erCode); - } - } } -- Gitblit v1.8.0