Files
sale/backend/internal/models/lottery.go
T

81 lines
2.6 KiB
Go

package models
import (
"time"
"gorm.io/gorm"
)
type Lottery struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:100;not null" json:"name"`
Description string `json:"description"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Cycle string `gorm:"size:20" json:"cycle"`
DailyQuota *int `json:"daily_quota"`
TotalQuota *int `json:"total_quota"`
RegistrationValidity *int `json:"registration_validity"`
IsActive bool `gorm:"default:true" json:"is_active"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
Prizes []LotteryPrize `json:"prizes,omitempty"`
}
func (Lottery) TableName() string {
return "lotteries"
}
type LotteryPrize struct {
ID uint `gorm:"primaryKey" json:"id"`
LotteryID uint `gorm:"index;not null" json:"lottery_id"`
Name string `gorm:"size:100;not null" json:"name"`
Type string `gorm:"size:20;not null" json:"type"`
Quantity int `gorm:"not null" json:"quantity"`
Weight int `gorm:"default:1" json:"weight"`
CreditReward *int `json:"credit_reward"`
DrawMode string `gorm:"size:20;default:'random'" json:"draw_mode"`
}
func (LotteryPrize) TableName() string {
return "lottery_prizes"
}
type LotteryParticipant struct {
ID uint `gorm:"primaryKey" json:"id"`
LotteryID uint `gorm:"index;not null" json:"lottery_id"`
UserID uint `gorm:"index;not null" json:"user_id"`
PurchaseWeight int `gorm:"default:0" json:"purchase_weight"`
RegisteredAt time.Time `json:"registered_at"`
}
func (LotteryParticipant) TableName() string {
return "lottery_participants"
}
type LotteryWinner struct {
ID uint `gorm:"primaryKey" json:"id"`
LotteryID uint `gorm:"index;not null" json:"lottery_id"`
PrizeID uint `gorm:"index;not null" json:"prize_id"`
UserID uint `gorm:"index;not null" json:"user_id"`
DrawnAt time.Time `json:"drawn_at"`
}
func (LotteryWinner) TableName() string {
return "lottery_winners"
}
const (
PrizeTypePhysical = "physical"
PrizeTypeVirtual = "virtual"
PrizeTypeCredit = "credit"
DrawModeRandom = "random"
DrawModeWeight = "weight"
CycleDaily = "daily"
CycleWeekly = "weekly"
CycleMonthly = "monthly"
)