53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package handlers
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"gorm.io/gorm"
|
|
|
|
"soda-api/backend/internal/models"
|
|
"soda-api/backend/internal/utils"
|
|
)
|
|
|
|
type MallHandler struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewMallHandler(db *gorm.DB) *MallHandler {
|
|
return &MallHandler{db: db}
|
|
}
|
|
|
|
func (h *MallHandler) Home(c *gin.Context) {
|
|
var products []models.Product
|
|
h.db.Limit(6).Find(&products)
|
|
|
|
categories := []gin.H{
|
|
{"name": "全自动", "description": "旗舰咖啡解决方案"},
|
|
{"name": "胶囊", "description": "智能云胶囊"},
|
|
{"name": "半自动", "description": "专业咖啡师体验"},
|
|
}
|
|
utils.JSONSuccess(c, gin.H{
|
|
"hero": gin.H{
|
|
"title": "商用咖啡机一站式采购",
|
|
"subtitle": "覆盖全场景的智能咖啡解决方案",
|
|
},
|
|
"categories": categories,
|
|
"products": products,
|
|
})
|
|
}
|
|
|
|
func (h *MallHandler) PayDemo(c *gin.Context) {
|
|
var payload struct {
|
|
OrderID uint `json:"orderId"`
|
|
Amount float64 `json:"amount"`
|
|
Method string `json:"method"`
|
|
}
|
|
if err := c.ShouldBindJSON(&payload); err != nil {
|
|
utils.JSONError(c, 400, "支付信息不完整")
|
|
return
|
|
}
|
|
utils.JSONSuccess(c, gin.H{
|
|
"status": "success",
|
|
"message": "支付演示完成,系统已记录",
|
|
})
|
|
}
|