From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 25 二月 2025 16:41:22 +0800 Subject: [PATCH] 淘宝转链接口更新 --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/wx/WXMPUserLoginServiceImpl.java | 398 ++++++++++++++++++++++++++++---------------------------- 1 files changed, 201 insertions(+), 197 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/wx/WXMPUserLoginServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/wx/WXMPUserLoginServiceImpl.java index e0adf1a..9418f05 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/wx/WXMPUserLoginServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/wx/WXMPUserLoginServiceImpl.java @@ -1,197 +1,201 @@ -package com.yeshi.fanli.service.impl.user.wx; - -import javax.annotation.Resource; - -import com.yeshi.fanli.entity.SystemEnum; -import com.yeshi.fanli.util.SystemInfoUtil; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import com.yeshi.fanli.dto.user.wx.WXMPLoginData; -import com.yeshi.fanli.dto.user.wx.WXMPLoginResult; -import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode; -import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode.ForbiddenUserIdentifyCodeTypeEnum; -import com.yeshi.fanli.entity.bus.user.UserInfo; -import com.yeshi.fanli.exception.user.ThreeSaleException; -import com.yeshi.fanli.exception.user.UserAccountException; -import com.yeshi.fanli.service.inter.user.ForbiddenUserIdentifyCodeService; -import com.yeshi.fanli.service.inter.user.UserAccountService; -import com.yeshi.fanli.service.inter.user.UserInfoExtraService; -import com.yeshi.fanli.service.inter.user.UserInfoService; -import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce; -import com.yeshi.fanli.service.inter.user.wx.WXMPUserLoginService; -import com.yeshi.fanli.util.Constant; -import com.yeshi.fanli.util.StringUtil; - -@Service -public class WXMPUserLoginServiceImpl implements WXMPUserLoginService { - - @Resource - private ThreeSaleSerivce threeSaleSerivce; - - @Resource - private UserAccountService userAccountService; - - @Resource - private UserInfoService userInfoService; - - @Resource - private UserInfoExtraService userInfoExtraService; - - @Resource - private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService; - - @Transactional(rollbackFor = Exception.class) - @Override - public WXMPLoginResult wxmpLogin(WXMPLoginData loginData) throws UserAccountException { - SystemEnum system = SystemInfoUtil.getSystemByWXCXCAppId(loginData.getAppId()); - if (!StringUtil.isNullOrEmpty(loginData.getPhone())) {// 鐢佃瘽鍙风爜鐧诲綍 - ForbiddenUserIdentifyCode identifyCode1 = forbiddenUserIdentifyCodeService - .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.phone, loginData.getPhone()); - if (identifyCode1 != null && identifyCode1.getEffective() != null && identifyCode1.getEffective()) - throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC); - - - if (loginData.getLastUser() != null) {// 鐢佃瘽鍙风爜缁戝畾 - if (loginData.getLastUser().getId() != null) {// 缁戝畾 - // 缁戝畾鎵嬫満鍙� - userAccountService.bindPhoneNew(loginData.getLastUser().getId(), loginData.getPhone()); - // 鍒ゅ畾鏄惁婵�娲� - UserInfo boss = threeSaleSerivce.getBoss(loginData.getLastUser().getId()); - if (boss == null) {// 闇�瑕佺粦瀹氶個璇风爜 - return new WXMPLoginResult(WXMPLoginResult.CODE_BIND_INVITE_CODE, - userInfoService.getUserById(loginData.getLastUser().getId())); - } else {// 宸茬粡缁戝畾杩囦簡 - return new WXMPLoginResult(WXMPLoginResult.CODE_SUCCESS, - userInfoService.getUserById(loginData.getLastUser().getId())); - } - - } else { - UserInfo userInfo = new UserInfo(); - userInfo.setAppId(loginData.getAppId()); - userInfo.setNickName(Constant.systemCommonConfig.getDefaultNickName()); - userInfo.setPortrait(Constant.systemCommonConfig.getDefaultPortrait()); - userInfo.setPhone(loginData.getPhone()); - - if (!StringUtil.isNullOrEmpty(loginData.getLastUser().getNickName())) - userInfo.setNickName(loginData.getLastUser().getNickName()); - - if (!StringUtil.isNullOrEmpty(loginData.getLastUser().getPortrait())) - userInfo.setPortrait(loginData.getLastUser().getPortrait()); - - userInfo.setWxName(loginData.getLastUser().getWxName()); - userInfo.setWxUnionId(loginData.getLastUser().getWxUnionId()); - userInfo.setWxPic(loginData.getLastUser().getWxPic()); - - if (loginData.getBoss() == null) { - return new WXMPLoginResult(WXMPLoginResult.CODE_BIND_INVITE_CODE, userInfo); - } - - userInfo.setLoginType(3); - // 鍒涘缓鐢ㄦ埛 - addUser(userInfo); - // 缁戝畾涓婄骇 - return bindInviteCode(loginData.getBoss(), userInfo); - } - - } else {// 鐧诲綍 - UserInfo userInfo = userAccountService.getUserInfoByPhone(SystemInfoUtil.getSystemByWXCXCAppId(loginData.getAppId()), loginData.getPhone()); - if (userInfo != null) {// 宸插瓨鍦ㄧ殑鐢ㄦ埛 - String inviteCode = userInfoExtraService.getInviteCodeByUid(userInfo.getId()); - if (StringUtil.isNullOrEmpty(inviteCode)) {// 闇�瑕佺粦瀹氶個璇风爜 - if (loginData.getBoss() != null) { - // 缁戝畾涓婄骇 - return bindInviteCode(loginData.getBoss(), userInfo); - } else { - // 鎻愮ず瀹㈡埛绔渶瑕佺粦瀹氶個璇风爜 - return new WXMPLoginResult(WXMPLoginResult.CODE_BIND_INVITE_CODE, - userInfoService.getUserById(userInfo.getId())); - } - } - return new WXMPLoginResult(WXMPLoginResult.CODE_SUCCESS, userInfo); - } else {// 鏂扮敤鎴� - userInfo = new UserInfo(); - userInfo.setAppId(loginData.getAppId()); - userInfo.setNickName(Constant.systemCommonConfig.getDefaultNickName()); - userInfo.setPortrait(Constant.systemCommonConfig.getDefaultPortrait()); - userInfo.setPhone(loginData.getPhone()); - userInfo.setPlatform("wxmp"); - - if (loginData.getBoss() != null) { - userInfo.setLoginType(3); - userInfo.setLastLoginTime(System.currentTimeMillis()); - // 娉ㄥ唽鏂扮敤鎴� - addUser(userInfo); - // 寤虹珛閭�璇峰叧绯� - // 缁戝畾涓婄骇 - return bindInviteCode(loginData.getBoss(), userInfo); - } else { - // 鎻愮ず瀹㈡埛绔渶瑕佺粦瀹氶個璇风爜 - return new WXMPLoginResult(WXMPLoginResult.CODE_BIND_INVITE_CODE, userInfo); - } - } - } - } else if (loginData.getWxUser() != null) {// 寰俊鐧诲綍 - ForbiddenUserIdentifyCode identifyCode1 = forbiddenUserIdentifyCodeService.listByTypeAndIdentifyCode( - ForbiddenUserIdentifyCodeTypeEnum.wxUnionId, loginData.getWxUser().getUnionId()); - if (identifyCode1 != null && identifyCode1.getEffective() != null && identifyCode1.getEffective()) - throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC); - UserInfo userInfo = userAccountService.getUserInfoByWXUnionId(system, - loginData.getWxUser().getUnionId()); - if (userInfo != null) {// 宸插瓨鍦ㄧ殑鐢ㄦ埛 - // 鏄惁缁戝畾浜嗙數璇� - if (StringUtil.isNullOrEmpty(userInfo.getPhone())) { - return new WXMPLoginResult(WXMPLoginResult.CODE_BIND_PHONE, userInfo); - } - - // 閫氳繃寰俊缃戦〉閭�璇峰叧绯昏繘鏉ョ殑婵�娲荤敓鏁� - threeSaleSerivce.effective(userInfo); - - String inviteCode = userInfoExtraService.getInviteCodeByUid(userInfo.getId()); - if (StringUtil.isNullOrEmpty(inviteCode)) {// 闇�瑕佺粦瀹氶個璇风爜 - // 鎻愮ず瀹㈡埛绔渶瑕佺粦瀹氶個璇风爜 - return new WXMPLoginResult(WXMPLoginResult.CODE_BIND_INVITE_CODE, userInfo); - } - // 鐧诲綍鎴愬姛 - return new WXMPLoginResult(WXMPLoginResult.CODE_SUCCESS, userInfo); - - } else {// 鏂扮敤鎴� - userInfo = new UserInfo(); - userInfo.setAppId(loginData.getAppId()); - userInfo.setNickName(loginData.getWxUser().getNickName()); - userInfo.setPortrait(loginData.getWxUser().getAvatarUrl()); - userInfo.setWxUnionId(loginData.getWxUser().getUnionId()); - userInfo.setLoginType(2); - // 鎻愮ず缁戝畾鎵嬫満鍙� - return new WXMPLoginResult(WXMPLoginResult.CODE_BIND_PHONE, userInfo); - } - - } else { - if (loginData.getLastUser() != null && loginData.getBoss() != null) {// 閭�璇风爜缁戝畾 - UserInfo userInfo = loginData.getLastUser(); - if (loginData.getLastUser().getId() == null) {// 鏂板垱寤� - addUser(userInfo); - } - return bindInviteCode(loginData.getBoss(), userInfo); - } else { - throw new UserAccountException(1, "鏁版嵁涓嶅畬鏁�"); - } - } - - } - - private void addUser(UserInfo userInfo) { - userInfo.setPlatform("wxmp"); - userAccountService.addUser(userInfo); - } - - private WXMPLoginResult bindInviteCode(UserInfo boss, UserInfo worker) throws UserAccountException { - try { - threeSaleSerivce.bind(worker, boss); - return new WXMPLoginResult(WXMPLoginResult.CODE_SUCCESS, userInfoService.getUserById(worker.getId())); - } catch (ThreeSaleException e) { - throw new UserAccountException(201, "纭畾閭�璇峰叧绯诲け璐�"); - } - } - -} +package com.yeshi.fanli.service.impl.user.wx; + +import javax.annotation.Resource; + +import com.yeshi.fanli.entity.SystemEnum; +import com.yeshi.fanli.service.inter.config.SystemConfigService; +import com.yeshi.fanli.util.SystemInfoUtil; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.yeshi.fanli.dto.user.wx.WXMPLoginData; +import com.yeshi.fanli.dto.user.wx.WXMPLoginResult; +import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode; +import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode.ForbiddenUserIdentifyCodeTypeEnum; +import com.yeshi.fanli.entity.bus.user.UserInfo; +import com.yeshi.fanli.exception.user.ThreeSaleException; +import com.yeshi.fanli.exception.user.UserAccountException; +import com.yeshi.fanli.service.inter.user.ForbiddenUserIdentifyCodeService; +import com.yeshi.fanli.service.inter.user.UserAccountService; +import com.yeshi.fanli.service.inter.user.UserInfoExtraService; +import com.yeshi.fanli.service.inter.user.UserInfoService; +import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce; +import com.yeshi.fanli.service.inter.user.wx.WXMPUserLoginService; +import com.yeshi.fanli.util.Constant; +import com.yeshi.fanli.util.StringUtil; + +@Service +public class WXMPUserLoginServiceImpl implements WXMPUserLoginService { + + @Resource + private ThreeSaleSerivce threeSaleSerivce; + + @Resource + private UserAccountService userAccountService; + + @Resource + private UserInfoService userInfoService; + + @Resource + private UserInfoExtraService userInfoExtraService; + + @Resource + private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService; + + @Resource + private SystemConfigService systemConfigService; + + @Transactional(rollbackFor = Exception.class) + @Override + public WXMPLoginResult wxmpLogin(WXMPLoginData loginData) throws UserAccountException { + SystemEnum system = SystemInfoUtil.getSystemByWXCXCAppId(loginData.getAppId()); + if (!StringUtil.isNullOrEmpty(loginData.getPhone())) {// 鐢佃瘽鍙风爜鐧诲綍 + ForbiddenUserIdentifyCode identifyCode1 = forbiddenUserIdentifyCodeService + .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.phone, loginData.getPhone()); + if (identifyCode1 != null && identifyCode1.getEffective() != null && identifyCode1.getEffective()) + throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC); + + + if (loginData.getLastUser() != null) {// 鐢佃瘽鍙风爜缁戝畾 + if (loginData.getLastUser().getId() != null) {// 缁戝畾 + // 缁戝畾鎵嬫満鍙� + userAccountService.bindPhoneNew(loginData.getLastUser().getId(), loginData.getPhone()); + // 鍒ゅ畾鏄惁婵�娲� + UserInfo boss = threeSaleSerivce.getBoss(loginData.getLastUser().getId()); + if (boss == null) {// 闇�瑕佺粦瀹氶個璇风爜 + return new WXMPLoginResult(WXMPLoginResult.CODE_BIND_INVITE_CODE, + userInfoService.getUserById(loginData.getLastUser().getId())); + } else {// 宸茬粡缁戝畾杩囦簡 + return new WXMPLoginResult(WXMPLoginResult.CODE_SUCCESS, + userInfoService.getUserById(loginData.getLastUser().getId())); + } + + } else { + UserInfo userInfo = new UserInfo(); + userInfo.setAppId(loginData.getAppId()); + userInfo.setNickName(null); + userInfo.setPortrait(userInfoService.getDefaultPortrait(system)); + userInfo.setPhone(loginData.getPhone()); + + if (!StringUtil.isNullOrEmpty(loginData.getLastUser().getNickName())) + userInfo.setNickName(loginData.getLastUser().getNickName()); + + if (!StringUtil.isNullOrEmpty(loginData.getLastUser().getPortrait())) + userInfo.setPortrait(loginData.getLastUser().getPortrait()); + + userInfo.setWxName(loginData.getLastUser().getWxName()); + userInfo.setWxUnionId(loginData.getLastUser().getWxUnionId()); + userInfo.setWxPic(loginData.getLastUser().getWxPic()); + + if (loginData.getBoss() == null) { + return new WXMPLoginResult(WXMPLoginResult.CODE_BIND_INVITE_CODE, userInfo); + } + + userInfo.setLoginType(3); + // 鍒涘缓鐢ㄦ埛 + addUser(userInfo); + // 缁戝畾涓婄骇 + return bindInviteCode(loginData.getBoss(), userInfo); + } + + } else {// 鐧诲綍 + UserInfo userInfo = userAccountService.getUserInfoByPhone(SystemInfoUtil.getSystemByWXCXCAppId(loginData.getAppId()), loginData.getPhone()); + if (userInfo != null) {// 宸插瓨鍦ㄧ殑鐢ㄦ埛 + String inviteCode = userInfoExtraService.getInviteCodeByUid(userInfo.getId()); + if (StringUtil.isNullOrEmpty(inviteCode)) {// 闇�瑕佺粦瀹氶個璇风爜 + if (loginData.getBoss() != null) { + // 缁戝畾涓婄骇 + return bindInviteCode(loginData.getBoss(), userInfo); + } else { + // 鎻愮ず瀹㈡埛绔渶瑕佺粦瀹氶個璇风爜 + return new WXMPLoginResult(WXMPLoginResult.CODE_BIND_INVITE_CODE, + userInfoService.getUserById(userInfo.getId())); + } + } + return new WXMPLoginResult(WXMPLoginResult.CODE_SUCCESS, userInfo); + } else {// 鏂扮敤鎴� + userInfo = new UserInfo(); + userInfo.setAppId(loginData.getAppId()); + userInfo.setNickName(null); + userInfo.setPortrait(null); + userInfo.setPhone(loginData.getPhone()); + userInfo.setPlatform("wxmp"); + + if (loginData.getBoss() != null) { + userInfo.setLoginType(3); + userInfo.setLastLoginTime(System.currentTimeMillis()); + // 娉ㄥ唽鏂扮敤鎴� + addUser(userInfo); + // 寤虹珛閭�璇峰叧绯� + // 缁戝畾涓婄骇 + return bindInviteCode(loginData.getBoss(), userInfo); + } else { + // 鎻愮ず瀹㈡埛绔渶瑕佺粦瀹氶個璇风爜 + return new WXMPLoginResult(WXMPLoginResult.CODE_BIND_INVITE_CODE, userInfo); + } + } + } + } else if (loginData.getWxUser() != null) {// 寰俊鐧诲綍 + ForbiddenUserIdentifyCode identifyCode1 = forbiddenUserIdentifyCodeService.listByTypeAndIdentifyCode( + ForbiddenUserIdentifyCodeTypeEnum.wxUnionId, loginData.getWxUser().getUnionId()); + if (identifyCode1 != null && identifyCode1.getEffective() != null && identifyCode1.getEffective()) + throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC); + UserInfo userInfo = userAccountService.getUserInfoByWXUnionId(system, + loginData.getWxUser().getUnionId()); + if (userInfo != null) {// 宸插瓨鍦ㄧ殑鐢ㄦ埛 + // 鏄惁缁戝畾浜嗙數璇� + if (StringUtil.isNullOrEmpty(userInfo.getPhone())) { + return new WXMPLoginResult(WXMPLoginResult.CODE_BIND_PHONE, userInfo); + } + + // 閫氳繃寰俊缃戦〉閭�璇峰叧绯昏繘鏉ョ殑婵�娲荤敓鏁� + threeSaleSerivce.effective(userInfo); + + String inviteCode = userInfoExtraService.getInviteCodeByUid(userInfo.getId()); + if (StringUtil.isNullOrEmpty(inviteCode)) {// 闇�瑕佺粦瀹氶個璇风爜 + // 鎻愮ず瀹㈡埛绔渶瑕佺粦瀹氶個璇风爜 + return new WXMPLoginResult(WXMPLoginResult.CODE_BIND_INVITE_CODE, userInfo); + } + // 鐧诲綍鎴愬姛 + return new WXMPLoginResult(WXMPLoginResult.CODE_SUCCESS, userInfo); + + } else {// 鏂扮敤鎴� + userInfo = new UserInfo(); + userInfo.setAppId(loginData.getAppId()); + userInfo.setNickName(loginData.getWxUser().getNickName()); + userInfo.setPortrait(loginData.getWxUser().getAvatarUrl()); + userInfo.setWxUnionId(loginData.getWxUser().getUnionId()); + userInfo.setLoginType(2); + // 鎻愮ず缁戝畾鎵嬫満鍙� + return new WXMPLoginResult(WXMPLoginResult.CODE_BIND_PHONE, userInfo); + } + + } else { + if (loginData.getLastUser() != null && loginData.getBoss() != null) {// 閭�璇风爜缁戝畾 + UserInfo userInfo = loginData.getLastUser(); + if (loginData.getLastUser().getId() == null) {// 鏂板垱寤� + addUser(userInfo); + } + return bindInviteCode(loginData.getBoss(), userInfo); + } else { + throw new UserAccountException(1, "鏁版嵁涓嶅畬鏁�"); + } + } + + } + + private void addUser(UserInfo userInfo) { + userInfo.setPlatform("wxmp"); + userAccountService.addUser(userInfo); + } + + private WXMPLoginResult bindInviteCode(UserInfo boss, UserInfo worker) throws UserAccountException { + try { + threeSaleSerivce.bind(worker, boss); + return new WXMPLoginResult(WXMPLoginResult.CODE_SUCCESS, userInfoService.getUserById(worker.getId())); + } catch (ThreeSaleException e) { + throw new UserAccountException(201, "纭畾閭�璇峰叧绯诲け璐�"); + } + } + +} -- Gitblit v1.8.0