基于 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
55 lines
2.6 KiB
Go
55 lines
2.6 KiB
Go
package model
|
|
|
|
import "time"
|
|
|
|
// Order 订单模型 // Logan.Li
|
|
type Order struct {
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
|
OrderNo string `json:"order_no" gorm:"size:100;uniqueIndex;not null"` // 系统唯一订单号(幂等键)
|
|
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"`
|
|
PlanID uint `json:"plan_id"`
|
|
Plan Plan `json:"plan,omitempty" gorm:"foreignKey:PlanID"`
|
|
LicenseID uint `json:"license_id"` // 关联的 License ID
|
|
Amount float64 `json:"amount" gorm:"type:decimal(10,2);not null"`
|
|
Currency string `json:"currency" gorm:"size:3;default:'USD'"`
|
|
Status string `json:"status" gorm:"size:20;default:'pending'"` // pending / paid / failed / refunded / cancelled
|
|
PaymentMethod string `json:"payment_method" gorm:"size:50"` // paddle / stripe / creem / waffo / alipay / wechat
|
|
PaymentGateway string `json:"payment_gateway" gorm:"size:50"`
|
|
GatewayOrderNo string `json:"gateway_order_no" gorm:"size:200"`
|
|
PaidAt *time.Time `json:"paid_at,omitempty"`
|
|
RefundAt *time.Time `json:"refund_at,omitempty"`
|
|
ClientIP string `json:"client_ip" gorm:"size:50"`
|
|
UserAgent string `json:"user_agent" gorm:"size:500"`
|
|
Notes string `json:"notes" gorm:"type:text"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// TableName 指定表名 // Logan.Li
|
|
func (Order) TableName() string {
|
|
return "orders"
|
|
}
|
|
|
|
// PaymentGatewayConfig 支付网关配置 // Logan.Li
|
|
type PaymentGatewayConfig struct {
|
|
Gateway string `json:"gateway" gorm:"size:50;primaryKey"` // paddle / stripe / creem / waffo
|
|
Enabled bool `json:"enabled" gorm:"default:false"`
|
|
PublicKey string `json:"public_key" gorm:"type:text"`
|
|
SecretKey string `json:"secret_key" gorm:"type:text"` // 加密存储
|
|
WebhookSecret string `json:"webhook_secret" gorm:"type:text"` // Webhook 验签密钥
|
|
SandboxMode bool `json:"sandbox_mode" gorm:"default:true"`
|
|
Currency string `json:"currency" gorm:"size:3;default:'USD'"`
|
|
Region string `json:"region" gorm:"size:50"`
|
|
Priority int `json:"priority" gorm:"default:0"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// TableName 指定表名 // Logan.Li
|
|
func (PaymentGatewayConfig) TableName() string {
|
|
return "payment_gateway_configs"
|
|
}
|