33 lines
1.3 KiB
Go
33 lines
1.3 KiB
Go
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"
|
||
}
|