Browse Source

test(微信PC端登录逻辑)

Roc 4 years ago
parent
commit
52c0c48b05
2 changed files with 12 additions and 14 deletions
  1. 5 9
      controllers/user_pc.go
  2. 7 5
      services/user.go

+ 5 - 9
controllers/user_pc.go

@@ -431,11 +431,9 @@ func (this *UserPcNotAuthController) PcBind() {
 		return
 	}
 	unionId := this.User.UnionId
-	userId := this.User.UserId
 	openId := this.User.OpenId
 
 	utils.FileLog.Info("绑定unionId:%s", unionId)
-	utils.FileLog.Info("userId:%d", userId)
 
 	if req.BindType == 1 { //手机号
 		if req.Mobile == "" {
@@ -502,14 +500,12 @@ func (this *UserPcNotAuthController) PcBind() {
 		return
 	}
 
-
 	user,err := services.BindWxUser(openId,req.Mobile,req.Email)
 	if err != nil{
 		br.Msg = "绑定失败:"+err.Error()
 		return
 	}
-	newUserId := user.UserId
-
+	userId := user.UserId
 	var token string
 	tokenItem, err := models.GetTokenByOpenId(openId)
 	if err != nil && err.Error() != utils.ErrNoRow() {
@@ -554,7 +550,7 @@ func (this *UserPcNotAuthController) PcBind() {
 		return
 	}
 
-	cp, err := models.GetCompanyProductsByUserId(newUserId)
+	cp, err := models.GetCompanyProductsByUserId(userId)
 	if err != nil {
 		br.Msg = "登录失败"
 		br.ErrMsg = "登录失败,获取客户信息失败:" + err.Error()
@@ -574,7 +570,7 @@ func (this *UserPcNotAuthController) PcBind() {
 		}
 	}
 
-	newUser, err := models.GetWxUserItemByUserId(newUserId)
+	newUser, err := models.GetWxUserItemByUserId(userId)
 	if err != nil {
 		br.Msg = "登录失败"
 		br.ErrMsg = "获取客户信息失败 GetWxUserItemByUserId:" + err.Error()
@@ -590,13 +586,13 @@ func (this *UserPcNotAuthController) PcBind() {
 		loginLog.Email=req.Email
 		loginLog.UnionId=unionId
 		loginLog.Handle="pc_bind"
-		loginLog.Remark=strconv.Itoa(newUserId)
+		loginLog.Remark=strconv.Itoa(userId)
 		loginLog.CreateTime = time.Now()
 		go models.AddWxUserLog(loginLog)
 	}
 
 	resp := new(models.LoginResp)
-	resp.UserId = newUserId
+	resp.UserId = userId
 	resp.UserPermission = userPermission
 	resp.Authorization = token
 	resp.Email = newUser.Email

+ 7 - 5
services/user.go

@@ -205,12 +205,14 @@ func BindWxUser(openid,mobile,email string) (wxUser *models.WxUserItem,err error
 		err = errors.New("用户已绑定,不允许重复绑定")
 		return
 	}
-
-	err = models.BindUserRecordByOpenid(userId,openid,bindAccount)
-	if err != nil{
-		return
+	if userRecord.UserId == 0{
+		err = models.BindUserRecordByOpenid(userId,openid,bindAccount)
+		if err != nil{
+			return
+		}
+		userRecord.UserId = userId
 	}
-	userRecord.UserId = userId
+
 	//如果当前该第三方用户信息的昵称为空串的话,那么需要去查询该用户的第一个绑定信息的数据作为来源做数据修复
 	if userRecord.NickName == ""{
 		oldUserRecord, err := models.GetUserThirdRecordByUserId(userId)