Files
opsx-licence/backend/internal/model/license.go
T
Logan.LiandCursor 8cc2c83f9d feat: 通用授权后台、离线证、Waffo 支付页与仪表盘加强
支持多产品计划展示、LICOFF 离线签发、支付独立配置与调试,以及分析看板;同步更新 README 与集成文档。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-12 20:25:46 +08:00

84 lines
3.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 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"`
License License `json:"license,omitempty" gorm:"foreignKey:LicenseID"`
DeviceID string `json:"device_id" gorm:"size:100"`
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"
}