xrate

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: BSD-3-Clause-Clear Imports: 6 Imported by: 0

Documentation

Overview

中奖率支持模块

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BatchCreate

func BatchCreate(bat *Batch, uid uint) error

创建批次信息

bat	批次信息
uid	用户ID

func ProjectCreate

func ProjectCreate(stat *Project, uid uint) error

奖品信息创建

stat	奖品信息
uid		用户ID

func RateWinning

func RateWinning(p []RateWain) int

抽奖函数

p	待抽奖的对象信息

func Regedit

func Regedit(c *Config)

注入配置项

func StartCreate

func StartCreate(stat *Start, uid uint) error

创建星级信息

stat	星级信息
uid		用户ID

func UserCount

func UserCount(uid uint, bid, pid, sid uint) uint

获取用户距离保底的次数

uid	用户ID
bid	批次ID
pid	产品ID
sid	星级ID

func UserCreate

func UserCreate(u *User) error

创建用户中奖记录信息

u	中奖记录信息

Types

type Batch

type Batch struct {
	ID          uint   `gorm:"id;primaryKey;type:BIGINT UNSIGNED;not null;autoIncrement" form:"id" json:"id"`               // 批次ID
	Name        string `gorm:"column:name;type:VARCHAR(200);comment:批次名称" json:"name" form:"name"`                          // 名称
	UserId      uint   `gorm:"column:user_id;comment:发布人ID" json:"user_id" form:"user_id"`                                  // 发布人ID
	Icon        uint   `gorm:"column:icon;comment:icon图ID" json:"icon" form:"icon"`                                         // 批次图标ID【关联文件ID】
	Cover       uint   `gorm:"column:cover;comment:封面图ID" json:"cover" form:"cover"`                                        // 封面图ID【关联文件ID】
	IsDefault   uint8  `gorm:"column:is_default;type:TINYINT UNSIGNED;comment:是否为默认批次" json:"is_default" form:"is_default"` // 是否是默认批次
	StartTime   string `gorm:"column:start_time;type:DATETIME;comment:开始时间" json:"start_time" form:"start_time"`            // 开始时间
	EndTime     string `gorm:"column:end_time;type:DATETIME;comment:结束时间" json:"end_time" form:"end_time"`                  // 结束时间
	Guarantee   uint   `gorm:"column:guarantee;comment:保底次数" json:"guarantee" form:"guarantee"`                             // 保底次数
	GuaranteeId uint   `gorm:"column:guarantee_id;comment:保底产品ID" json:"guarantee_id" form:"guarantee_id"`                  // 保底产品ID
	Status      uint8  ``                                                                                                   // 状态 0-草稿 1-已发布【已发布禁止修改】 2-已归档
	/* 136-byte string literal not displayed */
	CreatedAt string `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at" form:"created_at"` // 创建时间
	UpdatedAt string `gorm:"column:updated_at;type:datetime;comment:修改时间" json:"updated_at" form:"updated_at"` // 修改时间
}

批次表结构

func BatchInfo

func BatchInfo(id uint) (*Batch, error)

批次详情信息

id	批次ID

func BatchList

func BatchList(user_id uint, status uint8, offset, limit int, start_time, end_time string) (int64, []Batch, error)

批次列表信息

user_id		用户ID 0-不过滤
status		状态 0-草稿 1-已发布(禁止修改) 2-已归档
offset		跳过条数
limit		查询条数
start_time	开始时间(含)
end_time	结束时间(不含)

func (*Batch) TableName

func (c *Batch) TableName() string

表名

type Config

type Config struct {
	DB          *gorm.DB // 数据库连接
	BatchName   string   // 批次表名,通过该表ID进行抽奖
	StartName   string   // 星级所属表名
	ProjectName string   // 奖品所属表名
	UserName    string   // 用户中奖表名
}

配置信息

type Project

type Project struct {
	ID        uint    `gorm:"id;primaryKey;type:BIGINT UNSIGNED;not null;autoIncrement" form:"id" json:"id"`    // 奖品ID
	UserId    uint    `gorm:"column:user_id;comment:发布人" json:"user_id" form:"user_id"`                         // 发布人ID
	Name      string  `gorm:"column:name;type:VARCHAR(200);comment:奖品名称" json:"name" form:"name"`               // 名称
	StartID   uint    `gorm:"column:start_id;index:start_id;comment:星级ID" json:"start_id" form:"start_id"`      // 星级ID
	BatchId   uint    `gorm:"column:batch_id;index:batch_id;comment:批次ID" json:"batch_id" form:"batch_id"`      // 批次ID
	Rate      float64 `gorm:"column:rate;type:DECIMAL(10,6);comment:中奖率" json:"rate" form:"rate"`               // 中奖率,公式为:星级中奖率 / 星级奖品数 * 奖品中奖率,100为标准中奖率,50为减半中奖率,200为双倍UP
	Inventory uint    `gorm:"column:inventory;comment:奖品总库存" json:"inventory" form:"inventory"`                 // 奖品库存
	Residue   int     `gorm:"column:residue;type:INT;comment:剩余库存" json:"residue" form:"residue"`               // 剩余库存
	CreatedAt string  `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at" form:"created_at"` // 创建时间
	UpdatedAt string  `gorm:"column:updated_at;type:datetime;comment:修改时间" json:"updated_at" form:"updated_at"` // 修改时间
}

奖品表结构

func ProjectInfo

func ProjectInfo(id uint) (*Project, error)

奖品详情信息

id	批次ID

func ProjectList

func ProjectList(batch_id, start_id uint, offset, limit int) (int64, []Project, error)

奖品信息列表

batch_id	批次ID
start_id	星级ID
offset		跳过条数
limit		查询条数[-1表示查询全部]

func RateBatchUser

func RateBatchUser(id, uid uint) (*Project, error)

获取批次奖品列表

id	批次ID
uid	用户ID

func (*Project) TableName

func (c *Project) TableName() string

表名

type RateWain

type RateWain struct {
	ID         uint    // 预留ID,用于中奖后的奖品识别
	Name       string  // 奖品名称
	Rate       float64 // 中奖率【因浮点数无法直接进行概率计算,所以此处使用%%%的形式,即最小支持0.000001,且因为需要经过乘数处理,此值不能超过10000】
	StartId    uint    // 星级ID
	StartCount uint    // 星级保底数量
	// contains filtered or unexported fields
}

func RateBatch

func RateBatch(id uint) ([]RateWain, error)

获取批次奖品列表

id	批次ID

type Start

type Start struct {
	ID        uint    `gorm:"id;primaryKey;type:BIGINT UNSIGNED;not null;autoIncrement" form:"id" json:"id"`    // 星级ID
	UserId    uint    `gorm:"column:user_id;comment:发布人" json:"user_id" form:"user_id"`                         // 发布人ID
	BatchId   uint    `gorm:"column:batch_id;index:batch_id;comment:批次ID" json:"batch_id" form:"batch_id"`      // 批次ID
	Name      string  `gorm:"column:name;type:VARCHAR(200);comment:星级名称" json:"name" form:"name"`               // 名称
	Rate      float64 `gorm:"column:rate;type:DECIMAL(10,6);comment:中奖率" json:"rate" form:"rate"`               // 中奖率
	Guarantee uint    `gorm:"column:guarantee;comment:保底次数" json:"guarantee" form:"guarantee"`                  // 保底次数
	CreatedAt string  `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at" form:"created_at"` // 创建时间
	UpdatedAt string  `gorm:"column:updated_at;type:datetime;comment:修改时间" json:"updated_at" form:"updated_at"` // 修改时间
}

星级表结构

func StartInfo

func StartInfo(id uint) (*Start, error)

星级详情信息

id	批次ID

func StartList

func StartList(batch_id uint) (int64, []Start, error)

星级列表信息

batch_id	批次ID

func (*Start) TableName

func (c *Start) TableName() string

表名

type User

type User struct {
	ID        uint   `gorm:"id;primaryKey;type:BIGINT UNSIGNED;not null;autoIncrement" form:"id" json:"id"`               // 中奖ID
	UserId    uint   `gorm:"column:user_id;not null;index:user_id;comment:用户ID" json:"user_id" form:"user_id"`            // 中奖人id
	StartID   uint   `gorm:"column:start_id;index:start_id;comment:星级ID" json:"start_id" form:"start_id"`                 // 星级ID
	ProjectID uint   `gorm:"column:project_id;index:project_id;comment:奖品ID" json:"project_id" form:"project_id"`         // 奖品ID
	BatchId   uint   `gorm:"column:batch_id;index:batch_id;comment:批次ID" json:"batch_id" form:"batch_id"`                 // 批次ID
	IsUsed    uint8  `gorm:"column:is_used;type:TINYINT UNSIGNED;comment:是否使用 0-未使用 1-已使用" json:"is_used" form:"is_used"` // 是否使用 0-未使用 1-已使用
	Msg       string `gorm:"column:msg;type:VARCHAR(200);comment:抽奖备注" json:"msg" form:"msg"`                             // 抽奖备注
	CreatedAt string `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at" form:"created_at"`            // 创建时间
	UpdatedAt string `gorm:"column:updated_at;type:datetime;comment:修改时间" json:"updated_at" form:"updated_at"`            // 修改时间
}

用户中奖记录表

func (*User) TableName

func (c *User) TableName() string

表名

type UserProject

type UserProject struct {
	ID          uint   `gorm:"id" form:"id" json:"id"`                                      // 中奖ID
	ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"` // 奖品名称
	ProjectId   uint   `gorm:"column:project_id" json:"project_id" form:"project_id"`       // 奖品ID
	StartName   string `gorm:"column:start_name" json:"start_name" form:"start_name"`       // 星级名称
	StartId     uint   `gorm:"column:start_id" json:"start_id" form:"start_id"`             // 星级ID
	BatchName   string `gorm:"column:batch_name" json:"batch_name" form:"batch_name"`       // 批次名称
	BatchId     uint   `gorm:"column:batch_id" json:"batch_id" form:"batch_id"`             // 批次ID
	IsUsed      uint8  `gorm:"column:is_used" json:"is_used" form:"is_used"`                // 是否使用 0-未使用 1-已使用
	Msg         string `gorm:"column:msg" json:"msg" form:"msg"`                            // 抽奖备注
	CreatedAt   string `gorm:"column:created_at" json:"created_at" form:"created_at"`       // 创建时间
}

用户抽奖返回列表

func UserList

func UserList(uid, bid uint, offset, limit int) (int64, []UserProject, error)

查询用户的抽奖记录

uid		用户ID
bid		批次ID
offset	跳过条数
limit	查询条数

Jump to

Keyboard shortcuts

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