xingzai 1 ano atrás
pai
commit
a9666e97f8

+ 10 - 7
controllers/wechat.go

@@ -91,6 +91,12 @@ func (this *WechatCommonController) WechatLoginByxzs() {
 		br.ErrMsg = "查询数量失败,Err:" + err.Error()
 		return
 	}
+	user, err := models.GetWxUserItemByUserUnionId(unionId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取用户信息失败"
+		br.ErrMsg = "获取本地用户信息失败,Err:" + err.Error()
+		return
+	}
 	items := new(models.CygxUserRecord)
 	items.OpenId = openId
 	items.UnionId = unionId
@@ -101,6 +107,10 @@ func (this *WechatCommonController) WechatLoginByxzs() {
 	items.Country = wxUserInfo.Country
 	items.Headimgurl = wxUserInfo.Headimgurl
 	items.CreateTime = time.Now()
+	if user != nil {
+		items.UserId = user.UserId
+		items.BindAccount = user.Mobile
+	}
 	if total == 0 {
 		_, err = models.AddCygxUserRecord(items)
 		if err != nil {
@@ -112,13 +122,6 @@ func (this *WechatCommonController) WechatLoginByxzs() {
 	timeUnix := time.Now().Unix()
 	timeUnixStr := strconv.FormatInt(timeUnix, 10)
 
-	user, err := models.GetWxUserItemByUserUnionId(unionId)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		br.Msg = "获取用户信息失败"
-		br.ErrMsg = "获取本地用户信息失败,Err:" + err.Error()
-		return
-	}
-
 	totalItem, err := models.GetTokenByOpenId(openId)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "获取用户信息失败"

+ 2 - 0
models/cygx_user_record.go

@@ -16,6 +16,8 @@ type CygxUserRecord struct {
 	Country      string    `description:"国家,如中国为CN,最大长度:30"`
 	Headimgurl   string    `description:"用户第三方(微信)头像,最大长度:512"`
 	CreateTime   time.Time `description:"创建时间,关系添加时间、用户授权时间"`
+	BindAccount  string    `descritpion:"绑定时的账号,最大长度:128"`
+	UserId       int       `description:"用户id"`
 }
 
 // 添加

+ 1 - 1
services/user_label.go

@@ -10,7 +10,7 @@ import (
 func UserSubmit(itemsFllow []*models.CygxIndustryFllow, itemsCategory []*models.CygxXzsChooseCategory, userId int) (err error) {
 	e := models.UpdateCygxUserLabelNofollow(userId)
 	if e != nil {
-		go utils.SendAlarmMsg("用户关注产业更新相关标签,UpdateCygxUserLabelNofollow,Err :"+e.Error(), 2)
+		go utils.SendAlarmMsg("用户关注产业更新相关标签,UserSubmit,Err :"+e.Error(), 2)
 	}
 	if len(itemsFllow) > 0 {
 		mapIndustryId := make(map[int]bool)

+ 11 - 1
services/user_record.go

@@ -17,7 +17,17 @@ func AddCygxUserRecord(wxUserInfo *WxUserInfo) {
 	items.Country = wxUserInfo.Country
 	items.Headimgurl = wxUserInfo.Headimgurl
 	items.CreateTime = time.Now()
-	_, err := models.AddCygxUserRecord(items)
+
+	user, err := models.GetWxUserItemByUserUnionId(wxUserInfo.Unionid)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		go utils.SendAlarmMsg("发送邮件:用户关注查研观向小助手时记录相关信息失败,GetWxUserItemByUserUnionId Openid:"+wxUserInfo.Openid+err.Error(), 2)
+		return
+	}
+	if user != nil {
+		items.UserId = user.UserId
+		items.BindAccount = user.Mobile
+	}
+	_, err = models.AddCygxUserRecord(items)
 	if err != nil {
 		go utils.SendAlarmMsg("发送邮件:用户关注查研观向小助手时记录相关信息失败,Openid:"+wxUserInfo.Openid+err.Error(), 2)
 	}