feat: 完成 opsx-licence 许可证管理平台全栈实现
基于 opsx-web-lite 框架(Go+Gin+Vue3+Element Plus)构建许可证管理服务器,
业务域参考 Licence 服务器 Web 版。
【后端 - 4层架构】
- 认证:单 Admin 表 + JWT(HS256)
- 核心授权域:Product / Customer / License / Activation
· License 生成/验证/激活/机器绑定/心跳/续期/吊销
· 客户端契约接口:/api/v1/license/{verify,activate,deactivate,heartbeat}
- 定价订单:Plan / Order / 支付网关配置
- 防重复购买:CustomerEntitlement + 幂等支付 webhook + 手动发放
- 分析审计:Dashboard 统计 / Analytics / AuditLog / Setting 管理
【前端】
- Dashboard(ECharts 图表)、产品、客户、License、计划、订单、权益、日志、设置
- 9 个完整 CRUD 业务页面 + 登录/布局
【部署】
- SQLite + 单二进制(//go:embed 嵌入前端)
- 开发:./run.sh start(前端5181/后端9001)
- 生产:./run.sh build && ./run.sh binary start
- 默认账号:admin/admin
Author: Logan.Li
This commit is contained in:
commit
4ae318335c
88 files changed
+10562
No files matched your search
@@ -0,0 +1,76 @@
|
||||
package dto
|
||||
|
||||
// DashboardStats 仪表板统计响应 // Logan.Li
|
||||
type DashboardStats struct {
|
||||
TotalLicenses int64 `json:"total_licenses"`
|
||||
ActiveLicenses int64 `json:"active_licenses"`
|
||||
NewThisMonth int64 `json:"new_this_month"`
|
||||
ExpiringSoon int64 `json:"expiring_soon"`
|
||||
TotalCustomers int64 `json:"total_customers"`
|
||||
TotalProducts int64 `json:"total_products"`
|
||||
OnlineDevices int64 `json:"online_devices"`
|
||||
MonthlyRevenue float64 `json:"monthly_revenue"`
|
||||
}
|
||||
|
||||
// ExpiringLicenseItem 即将到期 License // Logan.Li
|
||||
type ExpiringLicenseItem struct {
|
||||
ID uint `json:"id"`
|
||||
LicenseKey string `json:"license_key"`
|
||||
CustomerName string `json:"customer_name"`
|
||||
ProductName string `json:"product_name"`
|
||||
EndDate string `json:"end_date"`
|
||||
DaysLeft int `json:"days_left"`
|
||||
}
|
||||
|
||||
// RecentActivityItem 最近活动 // Logan.Li
|
||||
type RecentActivityItem struct {
|
||||
ID uint `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Action string `json:"action"`
|
||||
TargetType string `json:"target_type"`
|
||||
TargetName string `json:"target_name"`
|
||||
Detail string `json:"detail"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
|
||||
// LicenseGrowthPoint License 增长趋势点 // Logan.Li
|
||||
type LicenseGrowthPoint struct {
|
||||
Date string `json:"date"`
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
|
||||
// RevenuePoint 收入趋势点 // Logan.Li
|
||||
type RevenuePoint struct {
|
||||
Period string `json:"period"`
|
||||
Amount float64 `json:"amount"`
|
||||
}
|
||||
|
||||
// ProductDistribution 产品分布 // Logan.Li
|
||||
type ProductDistribution struct {
|
||||
ProductName string `json:"product_name"`
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
|
||||
// SettingUpdate 更新系统设置请求 // Logan.Li
|
||||
type SettingUpdate struct {
|
||||
SystemName *string `json:"system_name"`
|
||||
DefaultDuration *int `json:"default_duration"`
|
||||
DefaultMaxActivations *int `json:"default_max_activations"`
|
||||
ExpireReminderDays *int `json:"expire_reminder_days"`
|
||||
APIRateLimit *int `json:"api_rate_limit"`
|
||||
LogRetentionDays *int `json:"log_retention_days"`
|
||||
}
|
||||
|
||||
// AuditLogResponse 操作日志响应 // Logan.Li
|
||||
type AuditLogResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Action string `json:"action"`
|
||||
TargetType string `json:"target_type"`
|
||||
TargetID uint `json:"target_id"`
|
||||
TargetName string `json:"target_name"`
|
||||
Detail string `json:"detail"`
|
||||
Result string `json:"result"`
|
||||
IP string `json:"ip"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package dto
|
||||
|
||||
// LoginRequest 登录请求 // Logan.Li
|
||||
type LoginRequest struct {
|
||||
Username string `json:"username" binding:"required"`
|
||||
Password string `json:"password" binding:"required"`
|
||||
}
|
||||
|
||||
// LoginResponse 登录响应 // Logan.Li
|
||||
type LoginResponse struct {
|
||||
Token string `json:"token"`
|
||||
UserInfo UserInfoResponse `json:"user_info"`
|
||||
}
|
||||
|
||||
// UserInfoResponse 用户信息响应 // Logan.Li
|
||||
type UserInfoResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
Avatar string `json:"avatar"`
|
||||
Role string `json:"role"`
|
||||
}
|
||||
|
||||
// ChangePasswordRequest 修改密码请求 // Logan.Li
|
||||
type ChangePasswordRequest struct {
|
||||
OldPassword string `json:"old_password" binding:"required"`
|
||||
NewPassword string `json:"new_password" binding:"required,min=6"`
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
package dto
|
||||
|
||||
// PlanCreate 创建定价计划请求 // Logan.Li
|
||||
type PlanCreate struct {
|
||||
ProductID uint `json:"product_id" binding:"required"`
|
||||
Name string `json:"name" binding:"required"`
|
||||
PlanType string `json:"plan_type" binding:"required"` // perpetual / monthly / yearly / lifetime
|
||||
Price float64 `json:"price" binding:"required"`
|
||||
Currency string `json:"currency"`
|
||||
Duration int `json:"duration"`
|
||||
MaxDevices int `json:"max_devices"`
|
||||
Features []string `json:"features"`
|
||||
SortOrder int `json:"sort_order"`
|
||||
Status *int `json:"status"`
|
||||
}
|
||||
|
||||
// PlanUpdate 更新定价计划请求 // Logan.Li
|
||||
type PlanUpdate struct {
|
||||
Name string `json:"name"`
|
||||
Price *float64 `json:"price"`
|
||||
Currency string `json:"currency"`
|
||||
Duration *int `json:"duration"`
|
||||
MaxDevices *int `json:"max_devices"`
|
||||
Features []string `json:"features"`
|
||||
SortOrder *int `json:"sort_order"`
|
||||
Status *int `json:"status"`
|
||||
}
|
||||
|
||||
// PlanResponse 定价计划响应 // Logan.Li
|
||||
type PlanResponse struct {
|
||||
ID uint `json:"id"`
|
||||
ProductID uint `json:"product_id"`
|
||||
Name string `json:"name"`
|
||||
PlanType string `json:"plan_type"`
|
||||
Price float64 `json:"price"`
|
||||
Currency string `json:"currency"`
|
||||
Duration int `json:"duration"`
|
||||
MaxDevices int `json:"max_devices"`
|
||||
Features []string `json:"features"`
|
||||
SortOrder int `json:"sort_order"`
|
||||
Status int `json:"status"`
|
||||
}
|
||||
|
||||
// OrderResponse 订单响应 // Logan.Li
|
||||
type OrderResponse struct {
|
||||
ID uint `json:"id"`
|
||||
OrderNo string `json:"order_no"`
|
||||
CustomerID uint `json:"customer_id"`
|
||||
CustomerName string `json:"customer_name"`
|
||||
ProductID uint `json:"product_id"`
|
||||
ProductName string `json:"product_name"`
|
||||
PlanID uint `json:"plan_id"`
|
||||
PlanName string `json:"plan_name"`
|
||||
LicenseID uint `json:"license_id"`
|
||||
Amount float64 `json:"amount"`
|
||||
Currency string `json:"currency"`
|
||||
Status string `json:"status"`
|
||||
PaymentGateway string `json:"payment_gateway"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
PaidAt string `json:"paid_at,omitempty"`
|
||||
}
|
||||
|
||||
// CreateOrderRequest 创建订单请求(客户端购买入口) // Logan.Li
|
||||
type CreateOrderRequest struct {
|
||||
CustomerEmail string `json:"customer_email" binding:"required,email"`
|
||||
CustomerName string `json:"customer_name"`
|
||||
ProductID uint `json:"product_id" binding:"required"`
|
||||
PlanID uint `json:"plan_id" binding:"required"`
|
||||
DeviceID string `json:"device_id"`
|
||||
ReturnURL string `json:"return_url"`
|
||||
CancelURL string `json:"cancel_url"`
|
||||
}
|
||||
|
||||
// CreateOrderResponse 创建订单响应 // Logan.Li
|
||||
type CreateOrderResponse struct {
|
||||
OrderNo string `json:"order_no"`
|
||||
CheckoutURL string `json:"checkout_url"`
|
||||
Amount float64 `json:"amount"`
|
||||
Currency string `json:"currency"`
|
||||
Status string `json:"status"`
|
||||
Gateway string `json:"gateway"`
|
||||
ExpiresAt string `json:"expires_at"`
|
||||
}
|
||||
|
||||
// PaymentWebhookRequest 支付回调请求 // Logan.Li
|
||||
type PaymentWebhookRequest struct {
|
||||
EventType string `json:"event_type" binding:"required"`
|
||||
OrderNo string `json:"order_no" binding:"required"`
|
||||
GatewayOrderNo string `json:"gateway_order_no"`
|
||||
Status string `json:"status" binding:"required"` // paid / failed / refunded
|
||||
Amount float64 `json:"amount"`
|
||||
Currency string `json:"currency"`
|
||||
CustomerEmail string `json:"customer_email"`
|
||||
Gateway string `json:"gateway" binding:"required"`
|
||||
Signature string `json:"signature"`
|
||||
Payload string `json:"payload"`
|
||||
}
|
||||
|
||||
// ManualGrantRequest 手动发放 License 请求(管理后台) // Logan.Li
|
||||
type ManualGrantRequest struct {
|
||||
CustomerEmail string `json:"customer_email" binding:"required,email"`
|
||||
CustomerName string `json:"customer_name"`
|
||||
ProductID uint `json:"product_id" binding:"required"`
|
||||
PlanID uint `json:"plan_id" binding:"required"`
|
||||
DeviceID string `json:"device_id"`
|
||||
Notes string `json:"notes"`
|
||||
}
|
||||
|
||||
// EntitlementResponse 客户权益响应 // Logan.Li
|
||||
type EntitlementResponse struct {
|
||||
ID uint `json:"id"`
|
||||
CustomerID uint `json:"customer_id"`
|
||||
CustomerName string `json:"customer_name"`
|
||||
ProductID uint `json:"product_id"`
|
||||
ProductName string `json:"product_name"`
|
||||
PlanID uint `json:"plan_id"`
|
||||
PlanName string `json:"plan_name"`
|
||||
PlanType string `json:"plan_type"`
|
||||
LicenseKey string `json:"license_key"`
|
||||
Status string `json:"status"`
|
||||
ValidFrom string `json:"valid_from"`
|
||||
ValidUntil *string `json:"valid_until,omitempty"`
|
||||
DaysLeft int `json:"days_left"`
|
||||
Renewable bool `json:"renewable"`
|
||||
MaxDevices int `json:"max_devices"`
|
||||
CurrentDevices int `json:"current_devices"`
|
||||
}
|
||||
|
||||
// DuplicatePurchaseCheckRequest 防重复购买检测请求 // Logan.Li
|
||||
type DuplicatePurchaseCheckRequest struct {
|
||||
CustomerEmail string `json:"customer_email" binding:"required,email"`
|
||||
ProductID uint `json:"product_id" binding:"required"`
|
||||
}
|
||||
|
||||
// DuplicatePurchaseCheckResponse 防重复购买检测响应 // Logan.Li
|
||||
type DuplicatePurchaseCheckResponse struct {
|
||||
AllowPurchase bool `json:"allow_purchase"`
|
||||
Reason string `json:"reason,omitempty"`
|
||||
ExistingEntitlementID uint `json:"existing_entitlement_id,omitempty"`
|
||||
ExistingLicenseKey string `json:"existing_license_key,omitempty"`
|
||||
ExistingPlanType string `json:"existing_plan_type,omitempty"`
|
||||
CanUpgrade bool `json:"can_upgrade"`
|
||||
UpgradeOptions []PlanResponse `json:"upgrade_options,omitempty"`
|
||||
}
|
||||
|
||||
// CheckPurchaseStatusRequest 购买状态查询请求 // Logan.Li
|
||||
type CheckPurchaseStatusRequest struct {
|
||||
CustomerEmail string `json:"customer_email" binding:"required,email"`
|
||||
ProductID uint `json:"product_id" binding:"required"`
|
||||
}
|
||||
|
||||
// CheckPurchaseStatusResponse 购买状态查询响应 // Logan.Li
|
||||
type CheckPurchaseStatusResponse struct {
|
||||
Purchased bool `json:"purchased"`
|
||||
HasActiveLicense bool `json:"has_active_license"`
|
||||
LicenseKey string `json:"license_key,omitempty"`
|
||||
LicenseStatus string `json:"license_status,omitempty"`
|
||||
PlanType string `json:"plan_type,omitempty"`
|
||||
ValidUntil *string `json:"valid_until,omitempty"`
|
||||
DaysLeft int `json:"days_left,omitempty"`
|
||||
Renewable bool `json:"renewable"`
|
||||
MaxDevices int `json:"max_devices,omitempty"`
|
||||
CurrentDevices int `json:"current_devices,omitempty"`
|
||||
EntitlementID uint `json:"entitlement_id,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package dto
|
||||
|
||||
// Response 统一响应结构 // Logan.Li
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
// PaginatedResponse 分页响应结构 // Logan.Li
|
||||
type PaginatedResponse struct {
|
||||
Count int `json:"count"`
|
||||
TotalPages int `json:"total_pages"`
|
||||
CurrentPage int `json:"current_page"`
|
||||
PageSize int `json:"page_size"`
|
||||
Next *string `json:"next"`
|
||||
Previous *string `json:"previous"`
|
||||
Results interface{} `json:"results"`
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package dto
|
||||
|
||||
// LicenseCreate 创建 License 请求 // Logan.Li
|
||||
type LicenseCreate struct {
|
||||
CustomerID uint `json:"customer_id" binding:"required"`
|
||||
ProductID uint `json:"product_id" binding:"required"`
|
||||
Duration int `json:"duration" binding:"required"` // 30/90/180/365/730/1095/1825/0(永久)
|
||||
MaxActivations int `json:"max_activations"`
|
||||
IsTrial bool `json:"is_trial"`
|
||||
TrialDays int `json:"trial_days"`
|
||||
Notes string `json:"notes"`
|
||||
Count int `json:"count"` // 批量生成数量
|
||||
}
|
||||
|
||||
// LicenseRenew 续期请求 // Logan.Li
|
||||
type LicenseRenew struct {
|
||||
Duration int `json:"duration" binding:"required"`
|
||||
}
|
||||
|
||||
// LicenseRevoke 吊销请求 // Logan.Li
|
||||
type LicenseRevoke struct {
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
|
||||
// LicenseResponse License 响应 // Logan.Li
|
||||
type LicenseResponse struct {
|
||||
ID uint `json:"id"`
|
||||
LicenseKey string `json:"license_key"`
|
||||
CustomerID uint `json:"customer_id"`
|
||||
CustomerName string `json:"customer_name"`
|
||||
ProductID uint `json:"product_id"`
|
||||
ProductName string `json:"product_name"`
|
||||
Status string `json:"status"`
|
||||
StartDate string `json:"start_date"`
|
||||
EndDate string `json:"end_date"`
|
||||
Duration int `json:"duration"`
|
||||
MaxActivations int `json:"max_activations"`
|
||||
CurrentActivations int `json:"current_activations"`
|
||||
IsTrial bool `json:"is_trial"`
|
||||
DaysLeft int `json:"days_left"`
|
||||
Notes string `json:"notes"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
|
||||
// ============ 客户端授权契约(无需认证) ============
|
||||
|
||||
// LicenseVerifyRequest 验证请求(客户端调用) // Logan.Li
|
||||
type LicenseVerifyRequest struct {
|
||||
LicenseKey string `json:"license_key" binding:"required"`
|
||||
DeviceID string `json:"device_id"`
|
||||
DeviceName string `json:"device_name"`
|
||||
DeviceInfo string `json:"device_info"`
|
||||
ProductID uint `json:"product_id"`
|
||||
}
|
||||
|
||||
// LicenseVerifyResponse 验证响应 // Logan.Li
|
||||
type LicenseVerifyResponse struct {
|
||||
Valid bool `json:"valid"`
|
||||
LicenseKey string `json:"license_key,omitempty"`
|
||||
ProductID uint `json:"product_id,omitempty"`
|
||||
ProductName string `json:"product_name,omitempty"`
|
||||
ProductCode string `json:"product_code,omitempty"`
|
||||
Features []string `json:"features,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
ExpiresAt string `json:"expires_at,omitempty"`
|
||||
DaysLeft int `json:"days_left,omitempty"`
|
||||
MaxDevices int `json:"max_devices,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
// LicenseActivateRequest 激活请求(客户端调用) // Logan.Li
|
||||
type LicenseActivateRequest struct {
|
||||
LicenseKey string `json:"license_key" binding:"required"`
|
||||
DeviceID string `json:"device_id" binding:"required"`
|
||||
DeviceName string `json:"device_name"`
|
||||
DeviceInfo string `json:"device_info"`
|
||||
}
|
||||
|
||||
// LicenseDeactivateRequest 停用请求(客户端调用) // Logan.Li
|
||||
type LicenseDeactivateRequest struct {
|
||||
LicenseKey string `json:"license_key" binding:"required"`
|
||||
DeviceID string `json:"device_id" binding:"required"`
|
||||
}
|
||||
|
||||
// LicenseHeartbeatRequest 心跳请求(客户端调用) // Logan.Li
|
||||
type LicenseHeartbeatRequest struct {
|
||||
LicenseKey string `json:"license_key" binding:"required"`
|
||||
DeviceID string `json:"device_id" binding:"required"`
|
||||
}
|
||||
|
||||
// ActivationResponse 激活记录响应 // Logan.Li
|
||||
type ActivationResponse struct {
|
||||
ID uint `json:"id"`
|
||||
LicenseID uint `json:"license_id"`
|
||||
DeviceID string `json:"device_id"`
|
||||
DeviceName string `json:"device_name"`
|
||||
DeviceInfo string `json:"device_info"`
|
||||
IP string `json:"ip"`
|
||||
Status string `json:"status"`
|
||||
IsOnline bool `json:"is_online"`
|
||||
ActivatedAt string `json:"activated_at"`
|
||||
LastSeenAt string `json:"last_seen_at"`
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package dto
|
||||
|
||||
// ProductCreate 创建产品请求 // Logan.Li
|
||||
type ProductCreate struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Code string `json:"code" binding:"required"`
|
||||
Version string `json:"version"`
|
||||
Description string `json:"description"`
|
||||
Features []string `json:"features"`
|
||||
Price float64 `json:"price"`
|
||||
PriceModel string `json:"price_model"`
|
||||
Status *int `json:"status"`
|
||||
}
|
||||
|
||||
// ProductUpdate 更新产品请求 // Logan.Li
|
||||
type ProductUpdate struct {
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
Description string `json:"description"`
|
||||
Features []string `json:"features"`
|
||||
Price *float64 `json:"price"`
|
||||
PriceModel string `json:"price_model"`
|
||||
Status *int `json:"status"`
|
||||
}
|
||||
|
||||
// ProductResponse 产品响应 // Logan.Li
|
||||
type ProductResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Code string `json:"code"`
|
||||
Version string `json:"version"`
|
||||
Description string `json:"description"`
|
||||
Features []string `json:"features"`
|
||||
Price float64 `json:"price"`
|
||||
PriceModel string `json:"price_model"`
|
||||
Status int `json:"status"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
|
||||
// CustomerCreate 创建客户请求 // Logan.Li
|
||||
type CustomerCreate struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Company string `json:"company"`
|
||||
Email string `json:"email" binding:"omitempty,email"`
|
||||
Phone string `json:"phone"`
|
||||
Address string `json:"address"`
|
||||
Notes string `json:"notes"`
|
||||
Status *int `json:"status"`
|
||||
}
|
||||
|
||||
// CustomerUpdate 更新客户请求 // Logan.Li
|
||||
type CustomerUpdate struct {
|
||||
Name string `json:"name"`
|
||||
Company string `json:"company"`
|
||||
Email string `json:"email" binding:"omitempty,email"`
|
||||
Phone string `json:"phone"`
|
||||
Address string `json:"address"`
|
||||
Notes string `json:"notes"`
|
||||
Status *int `json:"status"`
|
||||
}
|
||||
|
||||
// CustomerResponse 客户响应 // Logan.Li
|
||||
type CustomerResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Company string `json:"company"`
|
||||
Email string `json:"email"`
|
||||
Phone string `json:"phone"`
|
||||
Address string `json:"address"`
|
||||
Notes string `json:"notes"`
|
||||
Status int `json:"status"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
Reference in new issue
Block a user