You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.4 KiB
Go

// Code generated by goctl. DO NOT EDIT!
package model
import (
"context"
"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc"
"time"
"gorm.io/gorm"
)
type (
userGiftModel interface {
Insert(ctx context.Context, data *UserGift) error
FindOne(ctx context.Context, id int64) (*UserGift, error)
Update(ctx context.Context, data *UserGift) error
Delete(ctx context.Context, id int64) error
}
defaultUserGiftModel struct {
conn *gorm.DB
table string
}
UserGift struct {
Id int64 `gorm:"column:id;primaryKey"` // 主键ID
UserId int64 `gorm:"column:user_id"` // 用户ID
Platform string `gorm:"column:platform"` // 直播平台使用varchar兼容更多平台
RoomId string `gorm:"column:room_id"` // 直播间ID使用varchar兼容更多平台
GiftId string `gorm:"column:gift_id"` // 礼物ID使用varchar兼容更多平台
GiftName string `gorm:"column:gift_name"` // 礼物名称
Price int64 `gorm:"column:price"` // 价值(收费礼物,平台货币)
FreePrice int64 `gorm:"column:free_price"` // 价值(免费)
Num int64 `gorm:"column:num"` // 单次送礼数量
CreateTime time.Time `gorm:"column:create_time;default:null"` // 创建时间
}
)
func newUserGiftModel(conn *gorm.DB) *defaultUserGiftModel {
return &defaultUserGiftModel{
conn: conn,
table: "`user_gift`",
}
}
func (m *defaultUserGiftModel) Insert(ctx context.Context, data *UserGift) error {
err := m.conn.WithContext(ctx).Create(&data).Error
return err
}
func (m *defaultUserGiftModel) FindOne(ctx context.Context, id int64) (*UserGift, error) {
var resp UserGift
err := m.conn.WithContext(ctx).Model(&UserGift{}).Where("`id` = ?", id).Take(&resp).Error
switch err {
case nil:
return &resp, nil
case gormc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultUserGiftModel) Update(ctx context.Context, data *UserGift) error {
err := m.conn.WithContext(ctx).Save(data).Error
return err
}
func (m *defaultUserGiftModel) Delete(ctx context.Context, id int64) error {
err := m.conn.WithContext(ctx).Delete(&UserGift{}, id).Error
return err
}
func (m *defaultUserGiftModel) tableName() string {
return m.table
}
func (UserGift) TableName() string {
model := newUserGiftModel(nil)
return model.tableName()
}