fusenapi/model/gmodel/fsguestmodel.go

53 lines
1.7 KiB
Go
Raw Normal View History

2023-06-14 10:17:45 +00:00
package gmodel
2023-06-15 08:08:43 +00:00
import (
"context"
"fusenapi/utils/auth"
"time"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
2023-06-14 10:17:45 +00:00
type FsGuest struct {
2023-06-15 08:08:43 +00:00
GuestId int64 `gorm:"primary_key" json:"guest_id"` // 游客ID
AuthKey *string `gorm:"" json:"auth_key"` // jwt token
Status *int64 `gorm:"" json:"status"` // 1正常 0不正常
IsDel *int64 `gorm:"" json:"is_del"` // 是否删除 1删除
CreatedAt *int64 `gorm:"" json:"created_at"` // 添加时间
UpdatedAt *int64 `gorm:"" json:"updated_at"` // 更新时间
IsOpenRender *int64 `gorm:"" json:"is_open_render"` // 是否打开个性化渲染1开启0关闭
IsThousandFace *int64 `gorm:"" json:"is_thousand_face"` // 是否已经存在千人千面1存在0不存在
IsLowRendering *int64 `gorm:"" json:"is_low_rendering"` // 是否开启低渲染模型渲染
IsRemoveBg *int64 `gorm:"" json:"is_remove_bg"` // 用户上传logo是否去除背景
}
type FsGuestModel struct{ db *gorm.DB }
func NewFsGuestModel(db *gorm.DB) *FsGuestModel { return &FsGuestModel{db} }
func (m *FsGuestModel) GenerateGuestID(ctx context.Context, AccessSecret *string) (authKey string, err error) {
err = m.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
now := time.Now().Unix()
var record = &FsGuest{}
tx.Create(record)
authKey, err = auth.GenerateJwtToken(AccessSecret, now, 31536000, 0, record.GuestId)
if err != nil {
logx.Error(err)
tx.Rollback()
return err
}
record.AuthKey = &authKey
record.CreatedAt = &now
tx.Updates(record)
return nil
})
if err != nil {
return "", err
}
return authKey, nil
2023-06-14 10:17:45 +00:00
}