backend/app/zeus/service/lark/internal/model/user_info.go

43 lines
1.7 KiB
Go
Raw Permalink Normal View History

2022-01-11 04:00:39 +08:00
package model
2022-01-12 00:40:37 +08:00
import (
"git.icechen.cn/monorepo/backend/pkg/orm"
"gorm.io/gorm"
)
2022-01-11 04:00:39 +08:00
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"`
2022-01-12 00:40:37 +08:00
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"`
2022-01-11 04:00:39 +08:00
UserId string `json:"user_id,omitempty" gorm:"user_id"`
2022-01-12 00:40:37 +08:00
Mobile string `json:"mobile,omitempty" gorm:"mobile;uniqueIndex"`
2022-01-11 04:00:39 +08:00
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"
}
2022-01-12 00:40:37 +08:00
// 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
}