Browse Source

no message

xingzai 4 months ago
parent
commit
92a89942a1
4 changed files with 46 additions and 0 deletions
  1. 1 0
      controllers/wechat.go
  2. 8 0
      models/cygx_user_record.go
  3. 8 0
      models/user_record.go
  4. 29 0
      services/user_record.go

+ 1 - 0
controllers/wechat.go

@@ -260,6 +260,7 @@ func (this *WechatController) UserInfo() {
 			resp.RealName = user.RealName
 			resp.CompanyName = user.CompanyName
 			resp.HasPermission = 1
+			go services.UpdateCygxUserRecordMobile(user.Mobile, user.UserId) //更新用户手机号与Openid绑定关系
 		} else {
 			resp.Mobile = user.Mobile
 			resp.RealName = user.RealName

+ 8 - 0
models/cygx_user_record.go

@@ -71,3 +71,11 @@ func UpdateCygxUserRecordMobile(userId int, mobile, openId string) (err error) {
 	_, err = o.Raw(msql, userId, mobile, openId).Exec()
 	return
 }
+
+// 根据openid更新用户绑定的手机号
+func UpdateCygxUserRecordMobileByOpenId(userId int, mobile, openId string) (err error) {
+	o := orm.NewOrmUsingDB("hz_cygx")
+	msql := ` UPDATE cygx_user_record SET cygx_user_id = ?,cygx_bind_account= ? WHERE open_id = ? `
+	_, err = o.Raw(msql, userId, mobile, openId).Exec()
+	return
+}

+ 8 - 0
models/user_record.go

@@ -32,6 +32,14 @@ func GetUserRecordByUnionId(unionId string) (item *UserRecord, err error) {
 	return
 }
 
+// 根据BindAccount 获取用户关系
+// 4是查研观向   create_platform
+func GetUserRecordByBindAccount(bindAccount string) (item *UserRecord, err error) {
+	sql := `SELECT * FROM user_record WHERE bind_account=?  AND create_platform = 4   `
+	err = orm.NewOrm().Raw(sql, bindAccount).QueryRow(&item)
+	return
+}
+
 // 根据用户id和平台id获取用户关系
 func GetUserRecordByUserOpenId(open_id string) (item *UserRecord, err error) {
 	sql := `SELECT

+ 29 - 0
services/user_record.go

@@ -1,6 +1,8 @@
 package services
 
 import (
+	"errors"
+	"fmt"
 	"hongze/hongze_cygxzs/models"
 	"hongze/hongze_cygxzs/utils"
 	"time"
@@ -33,3 +35,30 @@ func AddCygxUserRecord(wxUserInfo *WxUserInfo) {
 	}
 
 }
+
+// UpdateCygxUserRecordMobile 更新用户手机号与Openid绑定关系
+func UpdateCygxUserRecordMobile(mobile string, uid int) {
+	if mobile == "" || uid == 0 {
+		return
+	}
+	var err error
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg(fmt.Sprint("更新用户手机号与Openid绑定关系失败 mobile:", mobile, err.Error()), 2)
+		}
+	}()
+	userRecord, e := models.GetUserRecordByBindAccount(mobile)
+	if e != nil {
+		err = errors.New("GetUserRecordByBindAccount, Err: " + e.Error())
+		return
+	}
+
+	if userRecord.UnionId != "" {
+		e = models.UpdateCygxUserRecordMobile(uid, mobile, userRecord.UnionId)
+		if e != nil {
+			err = errors.New("UpdateCygxUserRecordMobile, Err: " + e.Error())
+			return
+		}
+	}
+	return
+}