🎨 新增管理后台订单接口
This commit is contained in:
@@ -32,6 +32,7 @@ func (o *OrderApi) CreateOrder(c *gin.Context) {
|
|||||||
r.OkWithData(order, c)
|
r.OkWithData(order, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PayOrder APP支付订单
|
||||||
func (o *OrderApi) PayOrder(context *gin.Context) {
|
func (o *OrderApi) PayOrder(context *gin.Context) {
|
||||||
var p request.PayReq
|
var p request.PayReq
|
||||||
if err := context.ShouldBind(&p); err != nil {
|
if err := context.ShouldBind(&p); err != nil {
|
||||||
@@ -61,6 +62,7 @@ func (o *OrderApi) NotifyOrder(context *gin.Context) {
|
|||||||
r.OkWithMessage("微信支付回调处理成功", context)
|
r.OkWithMessage("微信支付回调处理成功", context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetOrderDetail 获取订单详情
|
||||||
func (o *OrderApi) GetOrderDetail(context *gin.Context) {
|
func (o *OrderApi) GetOrderDetail(context *gin.Context) {
|
||||||
id := context.Param("id")
|
id := context.Param("id")
|
||||||
if id == "" {
|
if id == "" {
|
||||||
@@ -79,7 +81,8 @@ func (o *OrderApi) GetOrderDetail(context *gin.Context) {
|
|||||||
r.OkWithData(order, context)
|
r.OkWithData(order, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OrderApi) GetOrderList(context *gin.Context) {
|
// AppGetOrderList App获取订单列表
|
||||||
|
func (o *OrderApi) AppGetOrderList(context *gin.Context) {
|
||||||
var p request.GetOrderList
|
var p request.GetOrderList
|
||||||
if err := context.ShouldBind(&p); err != nil {
|
if err := context.ShouldBind(&p); err != nil {
|
||||||
global.GVA_LOG.Error("获取订单列表参数错误", zap.Error(err))
|
global.GVA_LOG.Error("获取订单列表参数错误", zap.Error(err))
|
||||||
@@ -96,7 +99,7 @@ func (o *OrderApi) GetOrderList(context *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取订单列表
|
// 获取订单列表
|
||||||
orders, total, err := orderService.GetOrderList(p, userId)
|
orders, total, err := orderService.AppGetOrderList(p, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
global.GVA_LOG.Error("获取订单列表失败", zap.Error(err))
|
global.GVA_LOG.Error("获取订单列表失败", zap.Error(err))
|
||||||
r.FailWithMessage("获取订单列表失败:"+err.Error(), context)
|
r.FailWithMessage("获取订单列表失败:"+err.Error(), context)
|
||||||
@@ -112,6 +115,7 @@ func (o *OrderApi) GetOrderList(context *gin.Context) {
|
|||||||
}, "获取订单列表成功", context)
|
}, "获取订单列表成功", context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BalancePay 余额支付
|
||||||
func (o *OrderApi) BalancePay(context *gin.Context) {
|
func (o *OrderApi) BalancePay(context *gin.Context) {
|
||||||
var p request.BalancePay
|
var p request.BalancePay
|
||||||
if err := context.ShouldBind(&p); err != nil {
|
if err := context.ShouldBind(&p); err != nil {
|
||||||
@@ -129,3 +133,31 @@ func (o *OrderApi) BalancePay(context *gin.Context) {
|
|||||||
|
|
||||||
r.OkWithMessage("余额支付成功", context)
|
r.OkWithMessage("余额支付成功", context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ======================== 后台管理接口 ========================
|
||||||
|
|
||||||
|
// GetOrderList 获取订单列表
|
||||||
|
func (o *OrderApi) GetOrderList(context *gin.Context) {
|
||||||
|
var p request.GetOrderList
|
||||||
|
if err := context.ShouldBind(&p); err != nil {
|
||||||
|
global.GVA_LOG.Error("获取订单列表参数错误", zap.Error(err))
|
||||||
|
r.FailWithMessage("获取订单列表参数错误", context)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取订单列表
|
||||||
|
orders, total, err := orderService.GetOrderList(p)
|
||||||
|
if err != nil {
|
||||||
|
global.GVA_LOG.Error("获取订单列表失败", zap.Error(err))
|
||||||
|
r.FailWithMessage("获取订单列表失败:"+err.Error(), context)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
r.OkWithDetailed(
|
||||||
|
r.PageResult{
|
||||||
|
List: orders,
|
||||||
|
Total: total,
|
||||||
|
Page: p.Page,
|
||||||
|
PageSize: p.PageSize,
|
||||||
|
}, "获取订单列表成功", context)
|
||||||
|
}
|
||||||
|
@@ -118,8 +118,8 @@ func Routers() *gin.Engine {
|
|||||||
//APP相关路由
|
//APP相关路由
|
||||||
{
|
{
|
||||||
appRouter.InitAppUserRouter(AppAuthGroup, PublicGroup)
|
appRouter.InitAppUserRouter(AppAuthGroup, PublicGroup)
|
||||||
appRouter.InitBannerRouter(PrivateGroup, PublicGroup) // Banner相关路由
|
appRouter.InitBannerRouter(PrivateGroup, PublicGroup) // Banner相关路由
|
||||||
appRouter.InitOrderRouter(AppAuthGroup, PublicGroup) // 订单相关路由
|
appRouter.InitOrderRouter(AppAuthGroup, PrivateGroup, PublicGroup) // 订单相关路由
|
||||||
}
|
}
|
||||||
|
|
||||||
//插件路由安装
|
//插件路由安装
|
||||||
|
@@ -10,7 +10,13 @@ type BalancePay struct {
|
|||||||
|
|
||||||
type GetOrderList struct {
|
type GetOrderList struct {
|
||||||
common.PageInfo
|
common.PageInfo
|
||||||
Status int `json:"status" form:"status"` // 订单状态
|
Status int `json:"status" form:"status"` // 订单状态
|
||||||
|
Title string `json:"title" form:"title"` // 订单标题
|
||||||
|
Name string `json:"name" form:"name"` // 订单名称
|
||||||
|
PayType int `json:"pay_type" form:"pay_type"`
|
||||||
|
OrderType int `json:"order_type" form:"order_type"`
|
||||||
|
StartTime string `json:"start_time" form:"start_time"`
|
||||||
|
EndTime string `json:"end_time" form:"end_time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PayReq struct {
|
type PayReq struct {
|
||||||
|
@@ -5,17 +5,22 @@ import "github.com/gin-gonic/gin"
|
|||||||
type OrderRouter struct{}
|
type OrderRouter struct{}
|
||||||
|
|
||||||
// InitOrderRouter 初始化订单路由
|
// InitOrderRouter 初始化订单路由
|
||||||
func (r *OrderRouter) InitOrderRouter(AppRouter, PublicRouter *gin.RouterGroup) {
|
func (r *OrderRouter) InitOrderRouter(AppRouter, SysteamRouter, PublicRouter *gin.RouterGroup) {
|
||||||
appRouter := AppRouter.Group("app_order")
|
appRouter := AppRouter.Group("app_order")
|
||||||
publicRouter := PublicRouter.Group("app_order")
|
publicRouter := PublicRouter.Group("app_order")
|
||||||
|
systeamRouter := SysteamRouter.Group("order")
|
||||||
{
|
{
|
||||||
appRouter.POST("", orderApi.CreateOrder) // 创建订单
|
appRouter.POST("", orderApi.CreateOrder) // 创建订单
|
||||||
appRouter.POST("/wechat/pay", orderApi.PayOrder) // 微信支付订单
|
appRouter.POST("/wechat/pay", orderApi.PayOrder) // 微信支付订单
|
||||||
appRouter.GET("/list", orderApi.GetOrderList) // 获取订单列表
|
appRouter.GET("/list", orderApi.AppGetOrderList) // 获取订单列表
|
||||||
appRouter.GET(":id", orderApi.GetOrderDetail) // 获取订单详情
|
appRouter.GET(":id", orderApi.GetOrderDetail) // 获取订单详情
|
||||||
appRouter.POST("/balance/pay", orderApi.BalancePay) // 余额支付
|
appRouter.POST("/balance/pay", orderApi.BalancePay) // 余额支付
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
publicRouter.POST("/notify", orderApi.NotifyOrder) // 微信支付回调通知
|
publicRouter.POST("/notify", orderApi.NotifyOrder) // 微信支付回调通知
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
systeamRouter.GET("/list", orderApi.GetOrderList) // 获取订单列表
|
||||||
|
systeamRouter.GET(":id", orderApi.GetOrderDetail) // 获取订单详情
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -145,7 +145,8 @@ func (s *OrderService) BalancePay(p request.BalancePay) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OrderService) GetOrderList(p request.GetOrderList, id uint) (orders []app.Order, total int64, err error) {
|
// AppGetOrderList APP端获取订单列表
|
||||||
|
func (s *OrderService) AppGetOrderList(p request.GetOrderList, id uint) (orders []app.Order, total int64, err error) {
|
||||||
limit := p.PageSize
|
limit := p.PageSize
|
||||||
offset := p.PageSize * (p.Page - 1)
|
offset := p.PageSize * (p.Page - 1)
|
||||||
|
|
||||||
@@ -165,3 +166,38 @@ func (s *OrderService) GetOrderList(p request.GetOrderList, id uint) (orders []a
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetOrderList APP端获取订单列表
|
||||||
|
func (s *OrderService) GetOrderList(p request.GetOrderList) (orders []app.Order, total int64, err error) {
|
||||||
|
limit := p.PageSize
|
||||||
|
offset := p.PageSize * (p.Page - 1)
|
||||||
|
|
||||||
|
db := global.GVA_DB.Model(&app.Order{})
|
||||||
|
if p.Title != "" {
|
||||||
|
db = db.Where("title LIKE ? ", "%"+p.Title+"%")
|
||||||
|
}
|
||||||
|
if p.Status != 0 {
|
||||||
|
db = db.Where("status = ?", p.Status)
|
||||||
|
}
|
||||||
|
if p.PayType != 0 {
|
||||||
|
db = db.Where("pay_type = ?", p.PayType)
|
||||||
|
}
|
||||||
|
if p.OrderType != 0 {
|
||||||
|
db = db.Where("order_type = ?", p.OrderType)
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.StartTime != "" && p.EndTime != "" {
|
||||||
|
db = db.Where("created_at BETWEEN ? AND ?", p.StartTime, p.EndTime)
|
||||||
|
}
|
||||||
|
if p.Name != "" {
|
||||||
|
db = db.Where("name LIKE ? ", "%"+p.Name+"%")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = db.Count(&total).Error
|
||||||
|
err = db.Limit(limit).Offset(offset).Order("created_at desc").Find(&orders).Error
|
||||||
|
if err != nil {
|
||||||
|
global.GVA_LOG.Error("获取订单列表失败", zap.Error(err))
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user