Files
opsx-licence/backend/internal/model/license.go
T
Logan.LiandCursor bac72e6945 fix: 按评审报告止血支付漏洞并加固授权链路
废除浏览器回跳自助结算,通用 webhook 强制密钥鉴权,Waffo 支持验签与未知事件忽略;重构订单状态机/激活占座/SQLite WAL,并补备份、readyz、限流与前端导出/登录页安全修复。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-12 21:26:58 +08:00

84 lines
3.4 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 model
import (
"time"
"gorm.io/gorm"
)
// License 期限常量(天数,0 表示永久) // Logan.Li
const (
Duration1Month = 30
Duration3Months = 90
Duration6Months = 180
Duration1Year = 365
Duration2Years = 730
Duration3Years = 1095
Duration5Years = 1825
DurationForever = 0
)
// License 状态常量 // Logan.Li
const (
LicenseStatusInactive = "inactive"
LicenseStatusActive = "active"
LicenseStatusExpired = "expired"
LicenseStatusRevoked = "revoked"
LicenseStatusSuspended = "suspended"
)
// PermanentEndDate 永久授权的到期时间(2099-12-31) // Logan.Li
var PermanentEndDate = time.Date(2099, 12, 31, 23, 59, 59, 0, time.UTC)
// License 许可证模型 // Logan.Li
type License struct {
ID uint `json:"id" gorm:"primaryKey"`
LicenseKey string `json:"license_key" gorm:"size:512;uniqueIndex;not null"` // 在线 LIC-… / 离线 LICOFF-…
CustomerID uint `json:"customer_id"`
Customer Customer `json:"customer,omitempty" gorm:"foreignKey:CustomerID"`
ProductID uint `json:"product_id"`
Product Product `json:"product,omitempty" gorm:"foreignKey:ProductID"`
Status string `json:"status" gorm:"size:20;default:'inactive'"`
StartDate time.Time `json:"start_date"`
EndDate time.Time `json:"end_date"`
Duration int `json:"duration" gorm:"default:365"` // 天数,0 表示永久
MaxActivations int `json:"max_activations" gorm:"default:1"`
CurrentActivations int `json:"current_activations" gorm:"default:0"`
IsTrial bool `json:"is_trial" gorm:"default:false"`
TrialDays int `json:"trial_days" gorm:"default:0"`
RevokeReason string `json:"revoke_reason" gorm:"type:text"`
Notes string `json:"notes" gorm:"type:text"`
Activations []Activation `json:"activations,omitempty" gorm:"foreignKey:LicenseID"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `json:"deleted_at,omitempty" gorm:"index"`
}
// TableName 指定表名 // Logan.Li
func (License) TableName() string {
return "licenses"
}
// Activation 激活记录模型(机器绑定) // Logan.Li
type Activation struct {
ID uint `json:"id" gorm:"primaryKey"`
LicenseID uint `json:"license_id" gorm:"uniqueIndex:idx_lic_device,priority:1"`
License License `json:"license,omitempty" gorm:"foreignKey:LicenseID"`
DeviceID string `json:"device_id" gorm:"size:100;uniqueIndex:idx_lic_device,priority:2"`
DeviceName string `json:"device_name" gorm:"size:200"`
DeviceInfo string `json:"device_info" gorm:"type:text"` // JSON 格式存储设备信息
IP string `json:"ip" gorm:"size:50"`
Status string `json:"status" gorm:"size:20;default:'active'"` // active / inactive
IsOnline bool `json:"is_online" gorm:"default:false"`
ActivatedAt time.Time `json:"activated_at"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
LastSeenAt time.Time `json:"last_seen_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// TableName 指定表名 // Logan.Li
func (Activation) TableName() string {
return "activations"
}