Files
Go-Web-Template/server/model/system/invite_code.go
2026-04-23 15:29:07 +08:00

33 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package system
import (
"time"
)
type InviteCodeStatus string
const (
InviteCodeStatusUnused InviteCodeStatus = "unused"
InviteCodeStatusUsed InviteCodeStatus = "used"
InviteCodeStatusRevoked InviteCodeStatus = "revoked"
InviteCodeStatusExpired InviteCodeStatus = "expired"
)
// InviteCode 邀请码(明文不落库,仅保存 hash
type InviteCode struct {
ID uint `json:"id" gorm:"primaryKey"`
CreatedByUserID uint `json:"createdByUserId" gorm:"index;not null;comment:邀请码生成者用户ID"`
CodeHash string `json:"-" gorm:"uniqueIndex;size:64;not null;comment:邀请码hash(sha256 hex)"`
CodeLast4 string `json:"codeLast4" gorm:"size:8;comment:邀请码末尾4位(展示)"`
Status InviteCodeStatus `json:"status" gorm:"type:varchar(16);index;not null;comment:状态"`
ExpiresAt *time.Time `json:"expiresAt" gorm:"index;comment:过期时间"`
UsedByUserID *uint `json:"usedByUserId" gorm:"index;comment:使用者用户ID"`
UsedAt *time.Time `json:"usedAt" gorm:"comment:使用时间"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (InviteCode) TableName() string {
return "invite_codes"
}