Files
GPT_Management/backend/internal/models/card_key.go
sar 8d60704eda feat: 实现前端卡密管理界面
- 卡密列表展示与分页功能

- 单个/批量创建卡密

- 卡密删除与批量删除

- 卡密导出功能 (file-saver)

- 启用/禁用状态切换

- 状态判断 (有效/已使用/已失效)

- Toast 通知系统 (vue-sonner)

- 登录页面错误提示优化

- 后端登录错误消息中文化
2026-01-13 21:34:56 +08:00

43 lines
1.0 KiB
Go

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
}