package model import ( "git.icechen.cn/monorepo/backend/pkg/orm" "gorm.io/gorm" ) type UserInfo struct { gorm.Model AccessToken string `json:"access_token,omitempty" gorm:"access_token"` TokenType string `json:"token_type,omitempty" gorm:"token_type"` ExpiresIn int `json:"expires_in,omitempty" gorm:"expires_in"` Name string `json:"name,omitempty" gorm:"name"` EnName string `json:"en_name,omitempty" gorm:"en_name"` AvatarUrl string `json:"avatar_url,omitempty" gorm:"avatar_url"` AvatarThumb string `json:"avatar_thumb,omitempty" gorm:"avatar_thumb"` AvatarMiddle string `json:"avatar_middle,omitempty" gorm:"avatar_middle"` AvatarBig string `json:"avatar_big,omitempty" gorm:"avatar_big"` OpenId string `json:"open_id,omitempty" gorm:"open_id;uniqueIndex"` UnionId string `json:"union_id,omitempty" gorm:"union_id;uniqueIndex"` Email string `json:"email,omitempty" gorm:"email;uniqueIndex"` UserId string `json:"user_id,omitempty" gorm:"user_id"` Mobile string `json:"mobile,omitempty" gorm:"mobile;uniqueIndex"` TenantKey string `json:"tenant_key,omitempty" gorm:"tenant_key"` RefreshExpiresIn int `json:"refresh_expires_in,omitempty" gorm:"refresh_expires_in"` RefreshToken string `json:"refresh_token,omitempty" gorm:"refresh_token"` } func (UserInfo) TableName() string { return "user_info" } // CreateUser 创建用户 func CreateUser(user *UserInfo) error { return orm.DB.Where("open_id = ?", user.OpenId).Assign(user).FirstOrCreate(user).Error } // GetUserByID 根据ID获取用户信息 func GetUserByID(userID uint) (info UserInfo, err error) { err = orm.DB.First(&info, userID).Error return }