dao

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CreditLogStatusActive   uint8 = 1
	CreditLogStatusLocked   uint8 = 2
	CreditLogStatusInactive uint8 = 3
)

Variables

View Source
var (
	ErrCreateCreditConflict         = errors.New("创建积分主记录冲突")
	ErrUpdateCreditConflict         = errors.New("更新积分主记录冲突")
	ErrDuplicatedCreditLog          = errors.New("积分流水记录重复")
	ErrCreditNotEnough              = errors.New("积分不足")
	ErrRecordNotFound               = egorm.ErrRecordNotFound
	ErrInvalidLockedCreditLogStatus = errors.New("锁定的积分流水初始状态非法")
)

Functions

func InitTables

func InitTables(db *egorm.Component) error

Types

type Credit

type Credit struct {
	Id                 int64  `gorm:"primaryKey;autoIncrement;comment:积分主表自增ID"`
	Uid                int64  `gorm:"not null;uniqueIndex:unq_user_id;comment:用户ID"`
	TotalCredits       uint64 `gorm:"not null;default 0;comment:可用的积分总数"`
	LockedTotalCredits uint64 `gorm:"not null;default 0;comment:锁定的积分总数"`
	Version            int64  `gorm:"not null;default 1;comment:版本号"`
	Ctime              int64
	Utime              int64
}

type CreditDAO

type CreditDAO interface {
	Upsert(ctx context.Context, l CreditLog) error
	FindCreditByUID(ctx context.Context, uid int64) (Credit, error)
	FindCreditLogsByUID(ctx context.Context, uid int64) ([]CreditLog, error)
	CreateCreditLockLog(ctx context.Context, l CreditLog) (int64, error)
	ConfirmCreditLockLog(ctx context.Context, uid, tid int64) error
	CancelCreditLockLog(ctx context.Context, uid, tid int64) error
	FindExpiredLockedCreditLogs(ctx context.Context, offset int, limit int, ctime int64) ([]CreditLog, error)
	TotalExpiredLockedCreditLogs(ctx context.Context, ctime int64) (int64, error)
}

func NewCreditGORMDAO added in v0.1.0

func NewCreditGORMDAO(db *egorm.Component) CreditDAO

type CreditLog

type CreditLog struct {
	Id            int64  `gorm:"primaryKey;autoIncrement;comment:积分流水表自增ID"`
	Key           string `gorm:"type:varchar(256);not null;uniqueIndex:unq_key;comment:去重key"`
	Uid           int64  `gorm:"not null;index:idx_user_id;comment:用户ID"`
	Biz           string `gorm:"type:varchar(256);not null;comment:业务类型名,项目中模块目录名小写,user/member"`
	BizId         int64  `gorm:"not null;index:idx_biz_id;comment:业务ID"`
	Desc          string `gorm:"type:varchar(256);not null;comment:积分流水描述"`
	CreditChange  int64  `gorm:"not null;comment:积分变动数量,正数为增加,负数为减少"`
	CreditBalance uint64 `gorm:"not null;comment:变动后可用的积分总数"`
	Status        uint8  `gorm:"type:tinyint unsigned;not null;default:1;comment:流水状态 1=已生效, 2=已锁定, 3=已失效"`
	Ctime         int64
	Utime         int64
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL