Browse Source

Merge branch 'master' of http://8.136.199.33:3000/hongze/hongze_cygx

rdluck 4 years ago
parent
commit
e3eb80b967
3 changed files with 30 additions and 3 deletions
  1. 7 0
      models/user_record.go
  2. 22 2
      services/user.go
  3. 1 1
      utils/constants.go

+ 7 - 0
models/user_record.go

@@ -83,3 +83,10 @@ func GetUserRecordByMobile(platform int, bindAccount string) (item *UserRecord,
 	err = orm.NewOrm().Raw(sql, platform, bindAccount).QueryRow(&item)
 	return
 }
+
+//获取该用户第一个的 三方信息(微信头像信息)
+func GetUserThirdRecordByUserId(userId int)  (item *UserRecord, err error) {
+	sql := `SELECT * FROM user_record WHERE user_id = ? order by user_record_id asc`
+	err = orm.NewOrm().Raw(sql, userId).QueryRow(&item)
+	return
+}

+ 22 - 2
services/user.go

@@ -218,6 +218,18 @@ func BindWxUser(openid, mobile, email string) (wxUser *models.WxUserItem, err er
 		return
 	}
 	userRecord.UserId = userId
+
+	//如果当前该第三方用户信息的昵称为空串的话,那么需要去查询该用户的第一个绑定信息的数据作为来源做数据修复
+	if userRecord.NickName == ""{
+		oldUserRecord, err := models.GetUserThirdRecordByUserId(userId)
+		if err == nil && oldUserRecord != nil{
+			//如果该用户绑定的第一条数据的头像信息不为空串,那么就去做新数据的修复
+			if oldUserRecord.NickName != ""{
+				_ = models.ModifyUserRecordByDetail(userRecord.OpenId, userRecord.UnionId, oldUserRecord.NickName, oldUserRecord.Headimgurl, oldUserRecord.City, oldUserRecord.Province, oldUserRecord.Country, oldUserRecord.Sex, userId)
+			}
+		}
+	}
+
 	//格式化用户数据
 	formatWxUserAndUserRecord(wxUser, userRecord)
 	return
@@ -231,12 +243,20 @@ func WxLogin(code, openId, unionId string, wxUserInfo *WxUserInfo) (token string
 	//firstLogin==1,强制绑定手机号或者邮箱
 	firstLogin = 1
 	fmt.Println("GetWxUserItemByOpenId ", openId)
+
+QUERY_WX_USER:
 	wxUser, wxUserErr := GetWxUserItemByOpenId(openId)
 	fmt.Println("wxUserErr", wxUserErr)
 	if wxUserErr == ERR_NO_USER_RECORD { //没有用户openid记录
+		//先添加第三方信息(openid等信息)
 		_, recordErr := AddUserRecord(openId, unionId, wxUserInfo.Nickname, "", wxUserInfo.Province, wxUserInfo.City, wxUserInfo.Country, wxUserInfo.Headimgurl, wxUserInfo.SessionKey, utils.WxPlatform, wxUserInfo.Sex, 0)
-		err = recordErr
-		return
+		//如果插入失败,那么直接将错误信息返回
+		if recordErr != nil{
+			err = recordErr
+			return
+		}
+		//插入成功后,需要重新查询该用户,并进入下面的逻辑
+		goto QUERY_WX_USER
 	} else if wxUserErr == ERR_USER_NOT_BIND {
 		//没有用户信息
 		//wxUser.FirstLogin = 1

+ 1 - 1
utils/constants.go

@@ -20,7 +20,7 @@ const (
 
 const (
 	APPNAME          = "弘则-查研观向"
-	EmailSendToUsers = "glji@hzinsights.com"
+	EmailSendToUsers = "glji@hzinsights.com;pyan@hzinsights.com"
 )
 
 //手机号,电子邮箱正则