| | |
| | | package com.yeshi.fanli.service.impl.user.wx;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | 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 {
|
| | |
|
| | | 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(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(loginData.getAppId(),
|
| | | 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, "确定邀请关系失败"); |
| | | } |
| | | } |
| | | |
| | | } |