feat: 对齐 Waffo 包年/永久结账与客户端席位 API
同步 OpsXShell 档位定价与 Waffo 商品映射,补齐 checkout/webhook/设备列表契约,便于桌面端购买与满席释放。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
4ae318335c
commit
95405de119
14 files changed
+958
-155
No files matched your search
@@ -1,6 +1,8 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"backend/internal/dto"
|
||||
planservice "backend/internal/service/plan"
|
||||
productservice "backend/internal/service/product"
|
||||
"backend/utils"
|
||||
"fmt"
|
||||
@@ -13,13 +15,18 @@ import (
|
||||
|
||||
// ProductController 产品控制器 // Logan.Li
|
||||
type ProductController struct {
|
||||
svc *productservice.ProductService
|
||||
db *gorm.DB
|
||||
svc *productservice.ProductService
|
||||
planSvc *planservice.PlanService
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// NewProductController 创建控制器实例 // Logan.Li
|
||||
func NewProductController(db *gorm.DB) *ProductController {
|
||||
return &ProductController{svc: productservice.NewProductService(db), db: db}
|
||||
return &ProductController{
|
||||
svc: productservice.NewProductService(db),
|
||||
planSvc: planservice.NewPlanService(db),
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
// List 产品列表 // Logan.Li
|
||||
@@ -60,18 +67,28 @@ func (ctrl *ProductController) Get(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"code": 0, "data": product})
|
||||
}
|
||||
|
||||
// GetByCode 按产品编码返回产品及上架计划(公开接口) // Logan.Li
|
||||
func (ctrl *ProductController) GetByCode(c *gin.Context) {
|
||||
code := c.Param("code")
|
||||
product, err := ctrl.svc.GetByCode(code)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"code": 404, "message": err.Error()})
|
||||
return
|
||||
}
|
||||
plans, err := ctrl.planSvc.GetByProduct(product.ID)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"code": 1, "message": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"code": 0, "data": dto.ProductWithPlansResponse{
|
||||
Product: *product,
|
||||
Plans: plans,
|
||||
}})
|
||||
}
|
||||
|
||||
// Create 创建产品 // Logan.Li
|
||||
func (ctrl *ProductController) Create(c *gin.Context) {
|
||||
var req 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"`
|
||||
}
|
||||
var req dto.ProductCreate
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": "参数错误: " + err.Error()})
|
||||
return
|
||||
@@ -88,15 +105,7 @@ func (ctrl *ProductController) Create(c *gin.Context) {
|
||||
// Update 更新产品 // Logan.Li
|
||||
func (ctrl *ProductController) Update(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 32)
|
||||
var req 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"`
|
||||
}
|
||||
var req dto.ProductUpdate
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": "参数错误"})
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user