feat: 初始化 ChatGPT Team 管理后端项目
- 添加用户认证模块 (JWT + 密码管理) - 添加 ChatGPT 账户管理功能 - 添加卡密管理功能 (创建、批量生成、查询) - 添加邀请功能 - 配置数据库迁移和路由系统
This commit is contained in:
42
internal/models/card_key.go
Normal file
42
internal/models/card_key.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// CardKey 卡密表
|
||||
type CardKey struct {
|
||||
ID int `json:"id"`
|
||||
Key string `json:"key"` // 格式: XXXX-XXXX-XXXX-XXXX
|
||||
MaxUses int `json:"max_uses"`
|
||||
UsedCount int `json:"used_count"`
|
||||
ValidityType string `json:"validity_type"` // month/quarter/year/custom
|
||||
ExpiresAt time.Time `json:"expires_at"`
|
||||
IsActive bool `json:"is_active"`
|
||||
CreatedByID int `json:"created_by_id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// TableName 返回表名
|
||||
func (CardKey) TableName() string {
|
||||
return "card_keys"
|
||||
}
|
||||
|
||||
// IsExpired 检查卡密是否过期
|
||||
func (c *CardKey) IsExpired() bool {
|
||||
return time.Now().After(c.ExpiresAt)
|
||||
}
|
||||
|
||||
// IsUsable 检查卡密是否可用
|
||||
func (c *CardKey) IsUsable() bool {
|
||||
return c.IsActive && !c.IsExpired() && c.UsedCount < c.MaxUses
|
||||
}
|
||||
|
||||
// RemainingUses 返回剩余使用次数
|
||||
func (c *CardKey) RemainingUses() int {
|
||||
remaining := c.MaxUses - c.UsedCount
|
||||
if remaining < 0 {
|
||||
return 0
|
||||
}
|
||||
return remaining
|
||||
}
|
||||
Reference in New Issue
Block a user