基于 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
93 lines
2.9 KiB
Go
93 lines
2.9 KiB
Go
package analytics
|
|
|
|
import (
|
|
analyticsservice "backend/internal/service/analytics"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// AnalyticsController 数据分析控制器 // Logan.Li
|
|
type AnalyticsController struct {
|
|
svc *analyticsservice.AnalyticsService
|
|
}
|
|
|
|
// NewAnalyticsController 创建控制器实例 // Logan.Li
|
|
func NewAnalyticsController(db *gorm.DB) *AnalyticsController {
|
|
return &AnalyticsController{svc: analyticsservice.NewAnalyticsService(db)}
|
|
}
|
|
|
|
// GetDashboardStats 仪表板统计 // Logan.Li
|
|
func (ctrl *AnalyticsController) GetDashboardStats(c *gin.Context) {
|
|
stats, err := ctrl.svc.GetDashboardStats()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "message": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"code": 0, "data": stats})
|
|
}
|
|
|
|
// GetExpiringLicenses 即将到期 License // Logan.Li
|
|
func (ctrl *AnalyticsController) GetExpiringLicenses(c *gin.Context) {
|
|
days, _ := strconv.Atoi(c.DefaultQuery("days", "30"))
|
|
licenses, err := ctrl.svc.GetExpiringLicenses(days)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "message": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"code": 0, "data": licenses})
|
|
}
|
|
|
|
// GetRecentActivities 最近活动 // Logan.Li
|
|
func (ctrl *AnalyticsController) GetRecentActivities(c *gin.Context) {
|
|
limit, _ := strconv.Atoi(c.DefaultQuery("limit", "10"))
|
|
activities, err := ctrl.svc.GetRecentActivities(limit)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "message": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"code": 0, "data": activities})
|
|
}
|
|
|
|
// GetOnlineStats 在线统计 // Logan.Li
|
|
func (ctrl *AnalyticsController) GetOnlineStats(c *gin.Context) {
|
|
stats, err := ctrl.svc.GetOnlineStats()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "message": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"code": 0, "data": stats})
|
|
}
|
|
|
|
// GetRevenueStats 收入统计 // Logan.Li
|
|
func (ctrl *AnalyticsController) GetRevenueStats(c *gin.Context) {
|
|
stats, err := ctrl.svc.GetRevenueStats()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "message": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"code": 0, "data": stats})
|
|
}
|
|
|
|
// GetLicenseGrowth License 增长趋势 // Logan.Li
|
|
func (ctrl *AnalyticsController) GetLicenseGrowth(c *gin.Context) {
|
|
stats, err := ctrl.svc.GetLicenseGrowth()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "message": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"code": 0, "data": stats})
|
|
}
|
|
|
|
// GetProductDistribution 产品分布 // Logan.Li
|
|
func (ctrl *AnalyticsController) GetProductDistribution(c *gin.Context) {
|
|
stats, err := ctrl.svc.GetProductDistribution()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "message": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"code": 0, "data": stats})
|
|
}
|