浏览代码

fix(用户登录):如果微信用户已经绑定了其他账户,那么返回报错

Roc 3 年之前
父节点
当前提交
8404cfab43
共有 2 个文件被更改,包括 7 次插入1 次删除
  1. 5 0
      controllers/user.go
  2. 2 1
      services/user.go

+ 5 - 0
controllers/user.go

@@ -330,6 +330,11 @@ func (this *UserNotAuthController) Login() {
 	}
 	user, err = services.BindWxUser(openId, req.Mobile, req.Email, 1)
 	userId := user.UserId
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "登录失败"
+		br.ErrMsg = "登录失败:" + err.Error()
+		return
+	}
 
 	var token string
 	tokenItem, err := models.GetTokenByOpenId(openId)

+ 2 - 1
services/user.go

@@ -2,6 +2,7 @@ package services
 
 import (
 	"errors"
+	"fmt"
 	"hongze/hongze_api/models"
 	"hongze/hongze_api/utils"
 	"strconv"
@@ -220,7 +221,7 @@ func BindWxUser(openid, mobile, email string, registerPlatform int) (wxUser *mod
 	}
 	//如果存在该手机号/邮箱,那么需要校验
 	if userRecord.UserId > 0 && userRecord.UserId != userId {
-		err = errors.New("用户已绑定,不允许重复绑定")
+		err = errors.New(fmt.Sprint("用户已绑定其他账户,已绑定的用户编号:", userRecord.UserId, ",不允许重复绑定"))
 		return
 	}
 	if userRecord.UserId == 0 {