package services import ( "errors" "hongze/hongze_cygxzs/models" "hongze/hongze_cygxzs/utils" ) var ERR_NO_USER_RECORD = errors.New("用户关系没有入库") var ERR_USER_NOT_BIND = errors.New("用户没有绑定") //通过用户 关系表记录 和 用户记录 格式化返回 用户数据 func formatWxUserAndUserRecord(wxUser *models.WxUserItem, userRecord *models.UserRecord) { wxUser.OpenId = userRecord.OpenId wxUser.UnionId = userRecord.UnionId wxUser.NickName = userRecord.NickName //wxUser.RealName = userRecord.RealName //wxUser.BindAccount = userRecord.BindAccount wxUser.Headimgurl = userRecord.Headimgurl wxUser.SessionKey = userRecord.SessionKey } func GetWxUserItemByOpenId(unionId string) (item *models.WxUserItem, err error) { //通过openid获取用户关联信息 item = new(models.WxUserItem) item.UnionId = unionId // 先写入 unionId userRecord, userRecordErr := models.GetUserRecordByUnionId(unionId) if userRecordErr != nil && userRecordErr.Error() != utils.ErrNoRow() { err = userRecordErr return } //如果 userRecord 表中的手机号不为空,那么就通过手机号来获取详情 if userRecord != nil { if userRecord.BindAccount != "" { user, userErr := models.GetWxUserItemByUserMobile(userRecord.BindAccount) if userErr != nil && userErr.Error() != utils.ErrNoRow() { err = userErr return } if user != nil { item = user } } } return }