|
|
|
|
// Code generated by goctl. DO NOT EDIT!
|
|
|
|
|
|
|
|
|
|
package model
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"gorm.io/plugin/optimisticlock"
|
|
|
|
|
"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 (
|
|
|
|
|
userIntegralFieldNames = builder.RawFieldNames(&UserIntegral{})
|
|
|
|
|
userIntegralRows = strings.Join(userIntegralFieldNames, ",")
|
|
|
|
|
userIntegralRowsExpectAutoSet = strings.Join(stringx.Remove(userIntegralFieldNames, "`create_time`", "`update_time`"), ",")
|
|
|
|
|
userIntegralRowsWithPlaceHolder = strings.Join(stringx.Remove(userIntegralFieldNames, "`user_id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type (
|
|
|
|
|
userIntegralModel interface {
|
|
|
|
|
gormx.TxModel
|
|
|
|
|
Insert(ctx context.Context, tx *gorm.DB, data *UserIntegral) error
|
|
|
|
|
FindOne(ctx context.Context, tx *gorm.DB, userId int64) (*UserIntegral, error)
|
|
|
|
|
Update(ctx context.Context, tx *gorm.DB, data *UserIntegral) error
|
|
|
|
|
Delete(ctx context.Context, tx *gorm.DB, userId int64) error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defaultUserIntegralModel struct {
|
|
|
|
|
gormx.GormConn
|
|
|
|
|
table string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UserIntegral struct {
|
|
|
|
|
UserId int64 `gorm:"column:user_id;primaryKey"` // 用户ID
|
|
|
|
|
Integral int64 `gorm:"column:integral"` // 用户积分,1 RMB:1000
|
|
|
|
|
Version optimisticlock.Version `gorm:"column:version"` // 乐观锁
|
|
|
|
|
CreateTime time.Time `gorm:"column:create_time;default:null"` // 创建时间
|
|
|
|
|
UpdateTime time.Time `gorm:"column:update_time;default:null"` // 更新时间
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var UserIntegralTableName = "`user_integral`"
|
|
|
|
|
|
|
|
|
|
func newUserIntegralModel(conn *gorm.DB) *defaultUserIntegralModel {
|
|
|
|
|
return &defaultUserIntegralModel{
|
|
|
|
|
GormConn: gormx.NewConn(conn),
|
|
|
|
|
table: UserIntegralTableName,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *defaultUserIntegralModel) Insert(ctx context.Context, tx *gorm.DB, data *UserIntegral) error {
|
|
|
|
|
err := gormx.WithTx(ctx, m.DB, tx).Create(&data).Error
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *defaultUserIntegralModel) FindOne(ctx context.Context, tx *gorm.DB, userId int64) (*UserIntegral, error) {
|
|
|
|
|
var resp UserIntegral
|
|
|
|
|
err := gormx.WithTx(ctx, m.DB, tx).Model(&UserIntegral{}).Where("`user_id` = ?", userId).Take(&resp).Error
|
|
|
|
|
switch err {
|
|
|
|
|
case nil:
|
|
|
|
|
return &resp, nil
|
|
|
|
|
case gormx.ErrNotFound:
|
|
|
|
|
return nil, ErrNotFound
|
|
|
|
|
default:
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *defaultUserIntegralModel) Update(ctx context.Context, tx *gorm.DB, data *UserIntegral) error {
|
|
|
|
|
|
|
|
|
|
result := gormx.WithTx(ctx, m.DB, tx).Save(data)
|
|
|
|
|
if result.Error != nil {
|
|
|
|
|
return result.Error
|
|
|
|
|
}
|
|
|
|
|
if result.RowsAffected == 0 {
|
|
|
|
|
return gormx.ErrRowsAffectedZero
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *defaultUserIntegralModel) Delete(ctx context.Context, tx *gorm.DB, userId int64) error {
|
|
|
|
|
err := gormx.WithTx(ctx, m.DB, tx).Delete(&UserIntegral{}, userId).Error
|
|
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *defaultUserIntegralModel) tableName() string {
|
|
|
|
|
return m.table
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (UserIntegral) TableName() string {
|
|
|
|
|
return UserIntegralTableName
|
|
|
|
|
}
|