|
@@ -16,6 +16,7 @@ import cn.com.ty.lift.system.utils.PasswordUtils;
|
|
|
import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.session.data.redis.RedisOperationsSessionRepository;
|
|
@@ -260,15 +261,26 @@ public class LoginService implements ILoginService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public RestResponse appBindMobile(HttpServletRequest request, UserRequest userRequest) {
|
|
|
+ public RestResponse appBindMobile(UserRequest userRequest) {
|
|
|
+ //通过授权码获取用户openId
|
|
|
+ String openId = userRequest.getWeChatOpenId();
|
|
|
+ UserAccount oldBindUser = userAccountService.getOne(new QueryWrapper<UserAccount>().eq(
|
|
|
+ "wechat_open_id", openId
|
|
|
+ ));
|
|
|
+ if (oldBindUser != null) {
|
|
|
+ //解除上一个手机的绑定信息
|
|
|
+ if (!userAccountService.update(Wrappers.<UserAccount>update().set("wechat_open_id", null))) {
|
|
|
+ return RestResponse.fail(ApiConstants.RESULT_ERROR, "解除原来绑定失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //获取当前用户id
|
|
|
UserAccount userAccount = userAccountService.getByUserId(userRequest.getUserId());
|
|
|
- if(userAccount == null) {
|
|
|
+ if (userAccount == null) {
|
|
|
return RestResponse.fail(ApiConstants.RESULT_ERROR, "用户不存在无法绑定");
|
|
|
}
|
|
|
- //通过授权码获取用户openId
|
|
|
- String openId = userRequest.getWeChatOpenId();
|
|
|
userAccount.setWechatOpenId(openId);
|
|
|
if (!userAccountService.updateById(userAccount)) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
return RestResponse.fail(ApiConstants.RESULT_ERROR, "绑定微信失败");
|
|
|
}
|
|
|
return RestResponse.success(null, ApiConstants.RESULT_SUCCESS, "绑定微信成功");
|