feat: 通用授权后台、离线证、Waffo 支付页与仪表盘加强

支持多产品计划展示、LICOFF 离线签发、支付独立配置与调试,以及分析看板;同步更新 README 与集成文档。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Logan.LiandCursor committed 2026-08-12 20:25:46 +08:00
1 parent 0966375076
commit 8cc2c83f9d
41 files changed
+3177 -332

No files matched your search

@@ -1,6 +1,8 @@
package license
import (
"backend/config"
"backend/internal/dto"
licenseservice "backend/internal/service/license"
"backend/utils"
"net/http"
@@ -12,13 +14,18 @@ import (
// LicenseController License 控制器 // Logan.Li
type LicenseController struct {
svc *licenseservice.LicenseService
db *gorm.DB
svc *licenseservice.LicenseService
offline *licenseservice.OfflineIssuer
db *gorm.DB
}
// NewLicenseController 创建控制器实例 // Logan.Li
func NewLicenseController(db *gorm.DB) *LicenseController {
return &LicenseController{svc: licenseservice.NewLicenseService(db), db: db}
func NewLicenseController(db *gorm.DB, cfg *config.Config) *LicenseController {
return &LicenseController{
svc: licenseservice.NewLicenseService(db),
offline: licenseservice.NewOfflineIssuer(db, cfg),
db: db,
}
}
// parseListQuery 从请求解析筛选参数 // Logan.Li
@@ -26,6 +33,7 @@ func parseListQuery(c *gin.Context) licenseservice.ListQuery {
q := licenseservice.ListQuery{
Keyword: c.Query("keyword"),
Status: c.Query("status"),
Channel: c.Query("channel"),
}
if v, err := strconv.ParseUint(c.Query("customer_id"), 10, 32); err == nil {
q.CustomerID = uint(v)
@@ -65,16 +73,7 @@ func (ctrl *LicenseController) Get(c *gin.Context) {
// Create 创建 License // Logan.Li
func (ctrl *LicenseController) Create(c *gin.Context) {
var req struct {
CustomerID uint `json:"customer_id" binding:"required"`
ProductID uint `json:"product_id" binding:"required"`
Duration int `json:"duration" binding:"required"`
MaxActivations int `json:"max_activations"`
IsTrial bool `json:"is_trial"`
TrialDays int `json:"trial_days"`
Notes string `json:"notes"`
Count int `json:"count"`
}
var req dto.LicenseCreate
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": "参数错误: " + err.Error()})
return
@@ -89,6 +88,36 @@ func (ctrl *LicenseController) Create(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"code": 0, "message": "创建成功", "data": licenses})
}
// IssueOffline 签发离线许可证序列号(最长 365 天,绑定 device_id) // Logan.Li
func (ctrl *LicenseController) IssueOffline(c *gin.Context) {
var req dto.OfflineLicenseCreate
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": "参数错误: " + err.Error()})
return
}
result, err := ctrl.offline.Issue(req)
if err != nil {
c.JSON(http.StatusOK, gin.H{"code": 1, "message": err.Error()})
return
}
utils.LogAction(ctrl.db, c, "create_offline", "license", result.LicenseID, result.Serial, "", "",
"签发离线证 device="+result.DeviceID)
c.JSON(http.StatusOK, gin.H{"code": 0, "message": "离线许可证已生成", "data": result})
}
// OfflinePublicKey 返回当前离线验签公钥(供运维核对桌面嵌入值) // Logan.Li
func (ctrl *LicenseController) OfflinePublicKey(c *gin.Context) {
pub := ""
if ctrl.offline != nil {
pub = ctrl.offline.PublicKeyHex()
}
if pub == "" {
c.JSON(http.StatusOK, gin.H{"code": 1, "message": "未配置 OFFLINE_LICENSE_SEED"})
return
}
c.JSON(http.StatusOK, gin.H{"code": 0, "data": gin.H{"public_key_hex": pub}})
}
// Update 更新 License // Logan.Li
func (ctrl *LicenseController) Update(c *gin.Context) {
id, _ := strconv.ParseUint(c.Param("id"), 10, 32)