feat: 实现后端业务逻辑和Inertia.js管理后台
- 实现数据库连接和自动迁移 - 实现用户服务(登录、资料、JWT认证) - 实现许愿服务(创建、列表、机器人许愿) - 实现订单服务(创建、支付、状态管理) - 实现JWT认证中间件 - 实现管理后台API(仪表盘、用户、订单、许愿、设置) - 创建Inertia.js前端页面(Vue3 + Tailwind CSS) - 修复Go模块依赖问题
This commit is contained in:
@@ -2,18 +2,43 @@ package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gouki/lunar-server/internal/service"
|
||||
)
|
||||
|
||||
// GetOrderList 获取订单列表
|
||||
func GetOrderList(c *gin.Context) {
|
||||
userID, exists := c.Get("userID")
|
||||
if !exists {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"code": 401,
|
||||
"msg": "未授权",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||
pageSize, _ := strconv.Atoi(c.DefaultQuery("pageSize", "10"))
|
||||
|
||||
orderService := service.NewOrderService()
|
||||
orders, total, err := orderService.GetOrderList(userID.(uint), page, pageSize)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"code": 500,
|
||||
"msg": "获取订单列表失败",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"msg": "success",
|
||||
"data": gin.H{
|
||||
"list": []interface{}{},
|
||||
"total": 0,
|
||||
"list": orders,
|
||||
"total": total,
|
||||
"page": page,
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -21,23 +46,41 @@ func GetOrderList(c *gin.Context) {
|
||||
// GetOrderDetail 获取订单详情
|
||||
func GetOrderDetail(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
orderID, _ := strconv.Atoi(id)
|
||||
|
||||
orderService := service.NewOrderService()
|
||||
order, err := orderService.GetOrderByID(uint(orderID))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"code": 404,
|
||||
"msg": "订单不存在",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"msg": "success",
|
||||
"data": gin.H{
|
||||
"id": id,
|
||||
},
|
||||
"data": order,
|
||||
})
|
||||
}
|
||||
|
||||
// CancelOrder 取消订单
|
||||
func CancelOrder(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
orderID, _ := strconv.Atoi(id)
|
||||
|
||||
orderService := service.NewOrderService()
|
||||
if err := orderService.CancelOrder(uint(orderID)); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"code": 500,
|
||||
"msg": "取消订单失败",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"msg": "success",
|
||||
"data": gin.H{
|
||||
"id": id,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user