|
|
// Code generated by goctl. DO NOT EDIT!
|
|
|
|
|
|
package model
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormx"
|
|
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
|
|
"github.com/zeromicro/go-zero/core/stringx"
|
|
|
"gorm.io/gorm"
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
giftFieldNames = builder.RawFieldNames(&Gift{})
|
|
|
giftRows = strings.Join(giftFieldNames, ",")
|
|
|
giftRowsExpectAutoSet = strings.Join(stringx.Remove(giftFieldNames, "`create_time`", "`update_time`"), ",")
|
|
|
giftRowsWithPlaceHolder = strings.Join(stringx.Remove(giftFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
|
|
)
|
|
|
|
|
|
type (
|
|
|
giftModel interface {
|
|
|
gormx.TxModel
|
|
|
Insert(ctx context.Context, tx *gorm.DB, data *Gift) error
|
|
|
FindOne(ctx context.Context, tx *gorm.DB, id int64) (*Gift, error)
|
|
|
FindOneByGiftIdPlatform(ctx context.Context, tx *gorm.DB, giftId string, platform string) (*Gift, error)
|
|
|
Update(ctx context.Context, tx *gorm.DB, data *Gift) error
|
|
|
Delete(ctx context.Context, tx *gorm.DB, id int64) error
|
|
|
}
|
|
|
|
|
|
defaultGiftModel struct {
|
|
|
gormx.GormConn
|
|
|
table string
|
|
|
}
|
|
|
|
|
|
Gift struct {
|
|
|
Id int64 `gorm:"column:id;primaryKey"` // 主键
|
|
|
GiftId string `gorm:"column:gift_id"` // 礼物ID,不同平台可能类型都不同,用varchar
|
|
|
GiftName string `gorm:"column:gift_name"` // 礼物名
|
|
|
Platform string `gorm:"column:platform"` // 平台
|
|
|
PPriceFree int64 `gorm:"column:p_price_free"` // 平台免费价值单价B站: 银瓜子虎牙: 银豆
|
|
|
Price float64 `gorm:"column:price"` // 转换后的礼物价值,1RMB:1000(p)
|
|
|
Pic string `gorm:"pic"` // 礼物基本图
|
|
|
CreateTime time.Time `gorm:"column:create_time;default:null"` // 创建时间
|
|
|
PPricePaid int64 `gorm:"column:p_price_paid"` // 平台收费价值单价B站: 金瓜子虎牙: 金豆
|
|
|
}
|
|
|
)
|
|
|
|
|
|
var GiftTableName = "`gift`"
|
|
|
|
|
|
func newGiftModel(conn *gorm.DB) *defaultGiftModel {
|
|
|
return &defaultGiftModel{
|
|
|
GormConn: gormx.NewConn(conn),
|
|
|
table: GiftTableName,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (m *defaultGiftModel) Insert(ctx context.Context, tx *gorm.DB, data *Gift) error {
|
|
|
err := gormx.WithTx(ctx, m.DB, tx).Create(&data).Error
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
func (m *defaultGiftModel) FindOne(ctx context.Context, tx *gorm.DB, id int64) (*Gift, error) {
|
|
|
var resp Gift
|
|
|
err := gormx.WithTx(ctx, m.DB, tx).Model(&Gift{}).Where("`id` = ?", id).Take(&resp).Error
|
|
|
err = gormx.WrapSelectErr(err)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
return &resp, nil
|
|
|
}
|
|
|
|
|
|
func (m *defaultGiftModel) FindOneByGiftIdPlatform(ctx context.Context, tx *gorm.DB, giftId string, platform string) (*Gift, error) {
|
|
|
var resp Gift
|
|
|
err := gormx.WithTx(ctx, m.DB, tx).Model(&Gift{}).Where("`gift_id` = ? and `platform` = ?", giftId, platform).Take(&resp).Error
|
|
|
err = gormx.WrapSelectErr(err)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
return &resp, nil
|
|
|
}
|
|
|
|
|
|
func (m *defaultGiftModel) Update(ctx context.Context, tx *gorm.DB, data *Gift) error {
|
|
|
|
|
|
result := gormx.WithTx(ctx, m.DB, tx).Save(data)
|
|
|
return gormx.WrapUpdateErr(result.Error, result.RowsAffected)
|
|
|
|
|
|
}
|
|
|
|
|
|
func (m *defaultGiftModel) Delete(ctx context.Context, tx *gorm.DB, id int64) error {
|
|
|
err := gormx.WithTx(ctx, m.DB, tx).Delete(&Gift{}, id).Error
|
|
|
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
func (m *defaultGiftModel) tableName() string {
|
|
|
return m.table
|
|
|
}
|
|
|
|
|
|
func (Gift) TableName() string {
|
|
|
return GiftTableName
|
|
|
}
|