package services import ( "errors" "fmt" "hongze/hongze_cygxzs/models" "hongze/hongze_cygxzs/utils" "time" ) func AddCygxUserRecord(wxUserInfo *WxUserInfo) { items := new(models.CygxUserRecord) items.OpenId = wxUserInfo.Openid items.UnionId = wxUserInfo.Unionid items.NickName = wxUserInfo.Nickname items.Sex = wxUserInfo.Sex items.Province = wxUserInfo.Province items.City = wxUserInfo.City items.Country = wxUserInfo.Country items.Headimgurl = wxUserInfo.Headimgurl items.CreateTime = time.Now() 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.CygxUserId = user.UserId items.CygxBindAccount = user.Mobile } _, err = models.AddCygxUserRecord(items) if err != nil { go utils.SendAlarmMsg("发送邮件:用户关注查研观向小助手时记录相关信息失败,Openid:"+wxUserInfo.Openid+err.Error(), 2) } } // 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 }