package model import ( "time" "gorm.io/gorm" ) // MembershipRedeemCode 存储会员兑换码(只存 hash,不存明文 code)。 type MembershipRedeemCode struct { ID uint `gorm:"primarykey" json:"id"` CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"` UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"` // CodeHash 是 code 的 sha256(hex);避免 DB 泄漏导致所有兑换码被直接使用。 CodeHash string `gorm:"size:64;uniqueIndex;comment:兑换码哈希(sha256 hex)" json:"-"` // CodeSuffix 用于展示/审计(例如最后 6 位) CodeSuffix string `gorm:"size:16;index;comment:兑换码后缀(展示/审计)" json:"code_suffix"` Plan string `gorm:"size:30;comment:会员套餐" json:"plan"` DurationDays int `gorm:"comment:有效天数(用于延长会员)" json:"duration_days"` ExpiresAt *time.Time `gorm:"comment:兑换码过期时间" json:"expires_at,omitempty"` MaxUses int `gorm:"default:1;comment:最大可使用次数" json:"max_uses"` UsedUses int `gorm:"default:0;comment:已使用次数" json:"used_uses"` Status string `gorm:"size:20;default:active;comment:状态(active/disabled)" json:"status"` } func (MembershipRedeemCode) TableName() string { return "membership_redeem_codes" } func (MembershipRedeemCode) TableComment() string { return "会员兑换码" } type MembershipRedemption struct { ID uint `gorm:"primarykey" json:"id"` CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"` UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"` MiniProgramID uint `gorm:"index:idx_redeem_user_date,priority:1;comment:小程序ID" json:"mini_program_id"` UserID uint `gorm:"index:idx_redeem_user_date,priority:2;comment:用户ID" json:"user_id"` RedeemCodeID uint `gorm:"index;comment:兑换码ID" json:"redeem_code_id"` CodeSuffix string `gorm:"size:16;comment:兑换码后缀(展示/审计)" json:"code_suffix"` MembershipID uint `gorm:"index;comment:会员记录ID" json:"membership_id"` ClientIP string `gorm:"size:64;comment:客户端IP" json:"client_ip,omitempty"` UserAgent string `gorm:"size:255;comment:User-Agent" json:"user_agent,omitempty"` } func (MembershipRedemption) TableName() string { return "membership_redemptions" } func (MembershipRedemption) TableComment() string { return "会员兑换流水" }