zwxi 10 月之前
父節點
當前提交
731b8f57ba
共有 1 個文件被更改,包括 11 次插入3 次删除
  1. 11 3
      controllers/wechat.go

+ 11 - 3
controllers/wechat.go

@@ -86,8 +86,8 @@ func (this *WechatCommonController) WechatLoginByGzh() {
 		br.ErrMsg = "获取unionid失败,unionid:" + wxUserInfo.Unionid
 		return
 	}
-	total, err := models.GetCygxUserRecordCount(openId)
-	if err != nil {
+	mfyxUserRecord, err := models.GetCygxUserRecordByOpenid(openId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "获取用户信息失败"
 		br.ErrMsg = "查询数量失败,Err:" + err.Error()
 		return
@@ -113,8 +113,16 @@ func (this *WechatCommonController) WechatLoginByGzh() {
 	if user != nil {
 		items.CygxUserId = user.UserId
 		items.CygxBindAccount = user.Mobile
+		if mfyxUserRecord != nil && mfyxUserRecord.CygxUserId != user.UserId {
+			err = models.UpdateCygxUserRecordMobile(user.UserId, user.Mobile, unionId)
+			if err != nil {
+				br.Msg = "修复用户信息失败"
+				br.ErrMsg = "修复用户信息失败,Err:" + err.Error()
+				return
+			}
+		}
 	}
-	if total == 0 {
+	if mfyxUserRecord == nil {
 		_, err = models.AddMfyxGzhUserRecord(items)
 		if err != nil {
 			br.Msg = "获取用户信息失败"