|
|
@ -134,7 +134,7 @@ public class UserService implements IUserService { |
|
|
|
SysAuthExample sysAuthExample = new SysAuthExample(); |
|
|
|
sysAuthExample.createCriteria().andCredentialEqualTo(wxOauth2UserInfo.getUnionId()); |
|
|
|
List<SysAuth> sysAuthList = authDao.selectByExample(sysAuthExample); |
|
|
|
if(CollectionUtil.isNotEmpty(sysAuthList)){ |
|
|
|
if (CollectionUtil.isNotEmpty(sysAuthList)) { |
|
|
|
//添加认证方式
|
|
|
|
theAuth = new SysAuth(); |
|
|
|
theAuth.setId(snowflake.nextId()); |
|
|
@ -143,7 +143,7 @@ public class UserService implements IUserService { |
|
|
|
theAuth.setIdentifier(wxOauth2UserInfo.getOpenId()); |
|
|
|
theAuth.setCredential(wxOauth2UserInfo.getUnionId()); |
|
|
|
authDao.insertSelective(theAuth); |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
//新建用户并保存微信信息
|
|
|
|
SysUser user = new SysUser(); |
|
|
|
user.setId(snowflake.nextId()); |
|
|
@ -195,7 +195,7 @@ public class UserService implements IUserService { |
|
|
|
private UserVo.UserSign wxLogin(WebConstant.IDENTIFY_TYPE identifyType, String code) throws Exception { |
|
|
|
UserVo.UserSign userSignVo = null; |
|
|
|
//获取微信信息并保存
|
|
|
|
log.info("公众号登陆,{}",code); |
|
|
|
log.info("公众号登陆,{}", code); |
|
|
|
WxOauth2UserInfo wxOauth2UserInfo = WxGzhUtil.getOauth2UserInfo(identifyType, code); |
|
|
|
|
|
|
|
SysAuth theAuth = null; |
|
|
@ -210,7 +210,7 @@ public class UserService implements IUserService { |
|
|
|
SysAuthExample sysAuthExample = new SysAuthExample(); |
|
|
|
sysAuthExample.createCriteria().andCredentialEqualTo(wxOauth2UserInfo.getUnionId()); |
|
|
|
List<SysAuth> sysAuthList = authDao.selectByExample(sysAuthExample); |
|
|
|
if(CollectionUtil.isNotEmpty(sysAuthList)){ |
|
|
|
if (CollectionUtil.isNotEmpty(sysAuthList)) { |
|
|
|
// SysAuth sysAuth = sysAuthList.get(0);
|
|
|
|
//添加认证方式
|
|
|
|
theAuth = new SysAuth(); |
|
|
@ -220,7 +220,7 @@ public class UserService implements IUserService { |
|
|
|
theAuth.setIdentifier(wxOauth2UserInfo.getOpenId()); |
|
|
|
theAuth.setCredential(wxOauth2UserInfo.getUnionId()); |
|
|
|
authDao.insertSelective(theAuth); |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
//新建用户并保存微信信息
|
|
|
|
SysUser user = new SysUser(); |
|
|
|
user.setId(snowflake.nextId()); |
|
|
@ -294,7 +294,7 @@ public class UserService implements IUserService { |
|
|
|
theAuth = authList.get(0); |
|
|
|
} else { |
|
|
|
// throw new BaseException(CodeEnum.NOT_REGISTER);
|
|
|
|
theAuth = wxRegist(phone,null,WebConstant.IDENTIFY_TYPE.Phone); |
|
|
|
theAuth = wxRegist(phone, null, WebConstant.IDENTIFY_TYPE.Phone); |
|
|
|
} |
|
|
|
userSignVo = new UserVo.UserSign(); |
|
|
|
userSignVo.setUserId(theAuth.getUserId()); |
|
|
@ -346,7 +346,7 @@ public class UserService implements IUserService { |
|
|
|
WxXcxUtil.WechatUser wechatUser = WxXcxUtil.getUserInfo(code); |
|
|
|
String openId = wechatUser.openid; |
|
|
|
String unionId = wechatUser.unionid; |
|
|
|
log.info("小程序登录,openid:{} ,unionId:{}",openId,unionId); |
|
|
|
log.info("小程序登录,openid:{} ,unionId:{}", openId, unionId); |
|
|
|
//1.查找对应账户,不存在则注册
|
|
|
|
List<SysAuth> authList = null; |
|
|
|
SysAuth theAuth = null; |
|
|
@ -358,7 +358,7 @@ public class UserService implements IUserService { |
|
|
|
SysAuthExample sysAuthExample = new SysAuthExample(); |
|
|
|
sysAuthExample.createCriteria().andCredentialEqualTo(unionId); |
|
|
|
List<SysAuth> sysAuthList = authDao.selectByExample(sysAuthExample); |
|
|
|
if(CollectionUtil.isNotEmpty(sysAuthList)){ |
|
|
|
if (CollectionUtil.isNotEmpty(sysAuthList)) { |
|
|
|
// SysAuth sysAuth = sysAuthList.get(0);
|
|
|
|
//添加认证方式
|
|
|
|
theAuth = new SysAuth(); |
|
|
@ -368,7 +368,7 @@ public class UserService implements IUserService { |
|
|
|
theAuth.setIdentifier(openId); |
|
|
|
theAuth.setCredential(unionId); |
|
|
|
authDao.insertSelective(theAuth); |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
//新建用户并保存微信信息
|
|
|
|
SysUser user = new SysUser(); |
|
|
|
user.setId(snowflake.nextId()); |
|
|
@ -408,7 +408,7 @@ public class UserService implements IUserService { |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private SysAuth wxRegist(String identifier, String credential,WebConstant.IDENTIFY_TYPE identifyType) { |
|
|
|
private SysAuth wxRegist(String identifier, String credential, WebConstant.IDENTIFY_TYPE identifyType) { |
|
|
|
//1.添加user
|
|
|
|
SysUser user = new SysUser(); |
|
|
|
user.setId(snowflake.nextId()); |
|
|
@ -519,8 +519,8 @@ public class UserService implements IUserService { |
|
|
|
} |
|
|
|
|
|
|
|
//2.生成随机验证码
|
|
|
|
String verifyCode = RandomUtil.randomNumbers(4); |
|
|
|
// String verifyCode = "1111";
|
|
|
|
// String verifyCode = RandomUtil.randomNumbers(4);
|
|
|
|
String verifyCode = "1111"; |
|
|
|
|
|
|
|
//3.保存到redis中
|
|
|
|
Integer codeValidInSeconds = WebConstant.Expired_Verify_Code_In_Seconds; |
|
|
@ -529,7 +529,7 @@ public class UserService implements IUserService { |
|
|
|
redisUtil.set(RedisKeyManager.getSigninSmsExistKey(phone), verifyCode, codeExistINSeconds); |
|
|
|
|
|
|
|
//5.发送验证码
|
|
|
|
SmsUtil.sendSms(phone, verifyCode, client_type.phase, codeValidInSeconds); |
|
|
|
// SmsUtil.sendSms(phone, verifyCode, client_type.phase, codeValidInSeconds);
|
|
|
|
|
|
|
|
//6.返回
|
|
|
|
smsCodeVo = new UserVo.SmsCode(); |
|
|
@ -629,7 +629,7 @@ public class UserService implements IUserService { |
|
|
|
List<ProMember> proMemberList = memberDao.selectByExample(memberExample); |
|
|
|
if (CollectionUtil.isNotEmpty(proMemberList)) { |
|
|
|
SysUser user = userDao.selectByPrimaryKey(userId); |
|
|
|
if(ObjectUtil.isNotNull(user)) { |
|
|
|
if (ObjectUtil.isNotNull(user)) { |
|
|
|
for (ProMember member : proMemberList) { |
|
|
|
if (ObjectUtil.isNull(member.getUserId()) || member.getUserId() == 0) { |
|
|
|
member.setUserId(userId); |
|
|
@ -729,10 +729,10 @@ public class UserService implements IUserService { |
|
|
|
List<SysAuth> phoneList = null; |
|
|
|
SysAuth theAuth = null; |
|
|
|
SysAuthExample phoneExample = new SysAuthExample(); |
|
|
|
authExample.createCriteria().andIdentifyTypeEqualTo((byte) WebConstant.IDENTIFY_TYPE.Phone.value) |
|
|
|
phoneExample.createCriteria().andIdentifyTypeEqualTo((byte) WebConstant.IDENTIFY_TYPE.Phone.value) |
|
|
|
.andIdentifierEqualTo(wxPhone.getPhone()); |
|
|
|
phoneList = authDao.selectByExample(phoneExample); |
|
|
|
if (CollectionUtil.isNotEmpty(phoneList)) {//已被注册 提示
|
|
|
|
if (CollectionUtil.isNotEmpty(phoneList)) { |
|
|
|
throw new BaseException(CodeEnum.MERGE_WX_PHONE); |
|
|
|
} else { |
|
|
|
// throw new BaseException(CodeEnum.NOT_REGISTER);
|
|
|
@ -745,7 +745,7 @@ public class UserService implements IUserService { |
|
|
|
authDao.insertSelective(auth); |
|
|
|
|
|
|
|
//给手机号一样的所有项目内的成员添加userId
|
|
|
|
memberHandler(currentUserId,wxPhone.getPhone()); |
|
|
|
memberHandler(currentUserId, wxPhone.getPhone()); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
@ -757,7 +757,7 @@ public class UserService implements IUserService { |
|
|
|
authExample.createCriteria().andIdentifyTypeEqualTo((byte) WebConstant.IDENTIFY_TYPE.Phone.value) |
|
|
|
.andIdentifierEqualTo(wxPhone.getPhone()); |
|
|
|
List<SysAuth> authList = authDao.selectByExample(authExample); |
|
|
|
if(CollectionUtil.isNotEmpty(authList)) { |
|
|
|
if (CollectionUtil.isNotEmpty(authList)) { |
|
|
|
userSignVo = new UserVo.UserSign(); |
|
|
|
userSignVo.setAuthId(authList.get(0).getId()); |
|
|
|
userSignVo.setUserId(authList.get(0).getUserId()); |
|
|
@ -982,7 +982,7 @@ public class UserService implements IUserService { |
|
|
|
//获取用户的基本信息、
|
|
|
|
UserVo.WxInfo wxInfo = null; |
|
|
|
SysUser user = userDao.selectByPrimaryKey(userSignVo.getUserId()); |
|
|
|
if(ObjectUtil.isNotNull(user)) { |
|
|
|
if (ObjectUtil.isNotNull(user)) { |
|
|
|
wxInfo = new UserVo.WxInfo(); |
|
|
|
BeanUtil.copyProperties(user, wxInfo); |
|
|
|
wxInfo.setSex(user.getGender()); |
|
|
@ -1009,6 +1009,7 @@ public class UserService implements IUserService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 合并账号 |
|
|
|
* |
|
|
|
* @param currentUserId |
|
|
|
* @param wxPhone |
|
|
|
* @return |
|
|
@ -1019,36 +1020,36 @@ public class UserService implements IUserService { |
|
|
|
//直接合并
|
|
|
|
//1.查找手机号原来的userId
|
|
|
|
Long userId = selectUserIdByPhone(wxPhone.getPhone()); |
|
|
|
if(ObjectUtil.isNotNull(userId)){ |
|
|
|
if (ObjectUtil.isNotNull(userId)) { |
|
|
|
//处理账号认证信息,保留手机号的账号,删除现在的账号
|
|
|
|
SysAuthExample authExample = new SysAuthExample(); |
|
|
|
authExample.createCriteria().andIdentifyTypeEqualTo((byte) WebConstant.IDENTIFY_TYPE.Account.value) |
|
|
|
.andUserIdEqualTo(currentUserId); |
|
|
|
List<SysAuth> authList = authDao.selectByExample(authExample); |
|
|
|
if(CollectionUtil.isNotEmpty(authList)){ |
|
|
|
for(SysAuth auth : authList){ |
|
|
|
if (CollectionUtil.isNotEmpty(authList)) { |
|
|
|
for (SysAuth auth : authList) { |
|
|
|
auth.setRecStatus((byte) 2); |
|
|
|
authDao.updateByPrimaryKeySelective(auth); |
|
|
|
} |
|
|
|
} |
|
|
|
userDao.replaceAuth(userId,currentUserId); |
|
|
|
userDao.replaceAuth(userId, currentUserId); |
|
|
|
//查询所有关联userId的数据库表 auth表 attention表 balance表 project表 member表 DeliverPostLog表 proLog表
|
|
|
|
//依次将查出的数据的旧userId 替换成新的userId
|
|
|
|
userDao.replaceAttention(userId,currentUserId); |
|
|
|
userDao.replaceBalance(userId,currentUserId); |
|
|
|
userDao.replaceProject(userId,currentUserId); |
|
|
|
userDao.replaceMember(userId,currentUserId); |
|
|
|
userDao.replaceDeliverPostLog(userId,currentUserId); |
|
|
|
userDao.replaceProLog(userId,currentUserId); |
|
|
|
userDao.replaceAttention(userId, currentUserId); |
|
|
|
userDao.replaceBalance(userId, currentUserId); |
|
|
|
userDao.replaceProject(userId, currentUserId); |
|
|
|
userDao.replaceMember(userId, currentUserId); |
|
|
|
userDao.replaceDeliverPostLog(userId, currentUserId); |
|
|
|
userDao.replaceProLog(userId, currentUserId); |
|
|
|
//将以前的余额添加至此账号
|
|
|
|
SysUser oldUser = userDao.selectByPrimaryKey(userId); |
|
|
|
SysUser newUser = userDao.selectByPrimaryKey(currentUserId); |
|
|
|
updateBalance(oldUser,newUser); |
|
|
|
updateBalance(oldUser, newUser); |
|
|
|
//将以前的user删除
|
|
|
|
oldUser.setRecStatus((byte) 2); |
|
|
|
userDao.updateByPrimaryKeySelective(oldUser); |
|
|
|
|
|
|
|
}else { |
|
|
|
} else { |
|
|
|
throw new BaseException(CodeEnum.PARAM_ERROR); |
|
|
|
} |
|
|
|
} else { |
|
|
@ -1057,7 +1058,7 @@ public class UserService implements IUserService { |
|
|
|
authExample.createCriteria().andIdentifyTypeEqualTo((byte) WebConstant.IDENTIFY_TYPE.Phone.value) |
|
|
|
.andIdentifierEqualTo(wxPhone.getPhone()); |
|
|
|
List<SysAuth> authList = authDao.selectByExample(authExample); |
|
|
|
if(CollectionUtil.isNotEmpty(authList)){ |
|
|
|
if (CollectionUtil.isNotEmpty(authList)) { |
|
|
|
SysAuth auth = authList.get(0); |
|
|
|
auth.setUserId(currentUserId); |
|
|
|
authDao.updateByPrimaryKeySelective(auth); |
|
|
@ -1069,7 +1070,7 @@ public class UserService implements IUserService { |
|
|
|
authExample.createCriteria().andIdentifyTypeEqualTo((byte) WebConstant.IDENTIFY_TYPE.Phone.value) |
|
|
|
.andIdentifierEqualTo(wxPhone.getPhone()); |
|
|
|
List<SysAuth> authList = authDao.selectByExample(authExample); |
|
|
|
if(CollectionUtil.isNotEmpty(authList)) { |
|
|
|
if (CollectionUtil.isNotEmpty(authList)) { |
|
|
|
userSignVo = new UserVo.UserSign(); |
|
|
|
userSignVo.setAuthId(authList.get(0).getId()); |
|
|
|
userSignVo.setUserId(authList.get(0).getUserId()); |
|
|
@ -1077,7 +1078,8 @@ public class UserService implements IUserService { |
|
|
|
|
|
|
|
return userSignVo; |
|
|
|
} |
|
|
|
private void updateBalance(SysUser oldUser,SysUser newUser){ |
|
|
|
|
|
|
|
private void updateBalance(SysUser oldUser, SysUser newUser) { |
|
|
|
newUser.setBalance(newUser.getBalance() + oldUser.getBalance()); |
|
|
|
userDao.updateByPrimaryKeySelective(newUser); |
|
|
|
//添加一条余额变更记录
|
|
|
@ -1092,6 +1094,7 @@ public class UserService implements IUserService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 修改用户信息(添加微信信息) |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
@ -1099,33 +1102,102 @@ public class UserService implements IUserService { |
|
|
|
//通过userid查找到用户
|
|
|
|
SysUser user = userDao.selectByPrimaryKey(currentUserId); |
|
|
|
|
|
|
|
if(StrUtil.isNotEmpty(userInfo.getNickname())){ |
|
|
|
if (StrUtil.isNotEmpty(userInfo.getNickname())) { |
|
|
|
user.setNickname(userInfo.getNickname()); |
|
|
|
} |
|
|
|
if(StrUtil.isNotEmpty(userInfo.getHeadImgUrl())){ |
|
|
|
if (StrUtil.isNotEmpty(userInfo.getHeadImgUrl())) { |
|
|
|
user.setAvatarUrl(userInfo.getHeadImgUrl()); |
|
|
|
} |
|
|
|
if(ObjectUtil.isNotNull(userInfo.getSex())){ |
|
|
|
if (ObjectUtil.isNotNull(userInfo.getSex())) { |
|
|
|
user.setGender(userInfo.getSex()); |
|
|
|
} |
|
|
|
if(StrUtil.isNotEmpty(userInfo.getCountry())){ |
|
|
|
if (StrUtil.isNotEmpty(userInfo.getCountry())) { |
|
|
|
user.setCountry(userInfo.getCountry()); |
|
|
|
} |
|
|
|
if(StrUtil.isNotEmpty(userInfo.getProvince())){ |
|
|
|
if (StrUtil.isNotEmpty(userInfo.getProvince())) { |
|
|
|
user.setProvince(userInfo.getProvince()); |
|
|
|
} |
|
|
|
if(StrUtil.isNotEmpty(userInfo.getCity())){ |
|
|
|
if (StrUtil.isNotEmpty(userInfo.getCity())) { |
|
|
|
user.setCity(userInfo.getCity()); |
|
|
|
} |
|
|
|
if(StrUtil.isNotEmpty(userInfo.getLanguage())){ |
|
|
|
if (StrUtil.isNotEmpty(userInfo.getLanguage())) { |
|
|
|
user.setLanguage(userInfo.getLanguage()); |
|
|
|
} |
|
|
|
userDao.updateByPrimaryKeySelective(user); |
|
|
|
|
|
|
|
UserVo.WxInfo wxInfo = new UserVo.WxInfo(); |
|
|
|
BeanUtil.copyProperties(user,wxInfo); |
|
|
|
BeanUtil.copyProperties(user, wxInfo); |
|
|
|
wxInfo.setHeadImgUrl(user.getAvatarUrl()); |
|
|
|
wxInfo.setSex(user.getGender()); |
|
|
|
return wxInfo; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 解除已绑定的手机号 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void relievePhone(Long userId, String phone) { |
|
|
|
SysAuthExample authExample = new SysAuthExample(); |
|
|
|
authExample.createCriteria().andUserIdEqualTo(userId) |
|
|
|
.andIdentifyTypeEqualTo((byte) WebConstant.IDENTIFY_TYPE.Phone.value) |
|
|
|
.andIdentifierEqualTo(phone); |
|
|
|
List<SysAuth> authList = authDao.selectByExample(authExample); |
|
|
|
if (CollectionUtil.isNotEmpty(authList)) { |
|
|
|
SysAuth auth = authList.get(0); |
|
|
|
auth.setRecStatus((byte) 2); |
|
|
|
authDao.updateByPrimaryKeySelective(auth); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 更改绑定手机号(不要密码) |
|
|
|
* @param userId |
|
|
|
* @param phoneInfo |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public UserVo.UserSign changePhoneNotPassword(Long userId, UserDto.WxBindingPhone phoneInfo) throws Exception { |
|
|
|
UserVo.UserSign userSign = null; |
|
|
|
if (isSmsCodeCorrect(phoneInfo.getPhone(), phoneInfo.getSmsCode())) { |
|
|
|
//查找新手机号的的绑定信息
|
|
|
|
Long newPhoneUserId = selectUserIdByPhone(phoneInfo.getPhone()); |
|
|
|
if (ObjectUtil.isNull(newPhoneUserId)) { |
|
|
|
|
|
|
|
//查找此用户的的手机号
|
|
|
|
SysAuthExample phoneExample = new SysAuthExample(); |
|
|
|
phoneExample.createCriteria().andUserIdEqualTo(userId) |
|
|
|
.andIdentifyTypeEqualTo((byte) WebConstant.IDENTIFY_TYPE.Phone.value); |
|
|
|
List<SysAuth> phoneAuthList = authDao.selectByExample(phoneExample); |
|
|
|
if (CollectionUtil.isNotEmpty(phoneAuthList)) { |
|
|
|
//修改
|
|
|
|
SysAuth phoneAuth = phoneAuthList.get(0); |
|
|
|
phoneAuth.setIdentifier(phoneInfo.getPhone()); |
|
|
|
authDao.updateByPrimaryKeySelective(phoneAuth); |
|
|
|
|
|
|
|
userSign = new UserVo.UserSign(); |
|
|
|
userSign.setUserId(phoneAuth.getUserId()); |
|
|
|
userSign.setAuthId(phoneAuth.getId()); |
|
|
|
|
|
|
|
}else { |
|
|
|
//添加一条手机号认证信息
|
|
|
|
SysAuth sysAuth = new SysAuth(); |
|
|
|
sysAuth.setId(snowflake.nextId()); |
|
|
|
sysAuth.setUserId(userId); |
|
|
|
sysAuth.setIdentifyType((byte) WebConstant.IDENTIFY_TYPE.Phone.value); |
|
|
|
sysAuth.setIdentifier(phoneInfo.getPhone()); |
|
|
|
authDao.insertSelective(sysAuth); |
|
|
|
|
|
|
|
userSign = new UserVo.UserSign(); |
|
|
|
userSign.setUserId(sysAuth.getUserId()); |
|
|
|
userSign.setAuthId(sysAuth.getId()); |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
throw new BaseException(CodeEnum.MERGE_WX_PHONE); |
|
|
|
} |
|
|
|
} else { |
|
|
|
throw new BaseException(CodeEnum.SMS_CODE_CORRECT); |
|
|
|
} |
|
|
|
return userSign; |
|
|
|
} |
|
|
|
} |
|
|
|