backend/app/brahma/api/murder/internal/model/user.go

43 lines
1.4 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package model
import (
"context"
"git.icechen.cn/monorepo/backend/pkg/orm"
)
type User struct {
NickName string `json:"nick_name" gorm:"column:nick_name"` // 用户昵称
AvatarUrl string `json:"avatar_url" gorm:"column:avatar_url"` // 用户头像图片的 URL。URL 最后一个数值代表正方形头像大小(有 0、46、64、96、132 数值可选0 代表 640x640 的正方形头像46 表示 46x46 的正方形头像剩余数值以此类推。默认132用户没有头像时该项为空。若用户更换头像原有头像 URL 将失效。
Openid string `json:"openid" gorm:"column:openid"` // 用户唯一标识
SessionKey string `json:"session_key" gorm:"column:session_key"` // 会话密钥
Typeid string `json:"typeid" gorm:"column:typeid"` // 某个小程序的唯一id配置文件里面的key
}
func (m *User) TableName() string {
return "user"
}
func GetUserInfo(ctx context.Context, typeId, openId string) (*User, error) {
db, err := orm.GetContextDB(ctx)
if err != nil {
return nil, err
}
i := new(User)
affected := db.First(i, "typeid = ? AND openid = ?", typeId, openId).RowsAffected
if affected == 1 {
return i, nil
}
return nil, nil
}
func NewUser(ctx context.Context, user *User) error {
db, err := orm.GetContextDB(ctx)
if err != nil {
return err
}
if err = db.Create(user).Error; err != nil {
return err
}
return nil
}