97 lines
2.3 KiB
Go
97 lines
2.3 KiB
Go
package super
|
||
|
||
import (
|
||
"time"
|
||
|
||
"quyun/v2/app/errorx"
|
||
"quyun/v2/app/http/super/dto"
|
||
"quyun/v2/app/requests"
|
||
"quyun/v2/app/services"
|
||
"quyun/v2/database/models"
|
||
"quyun/v2/pkg/consts"
|
||
"quyun/v2/providers/jwt"
|
||
|
||
"github.com/gofiber/fiber/v3"
|
||
)
|
||
|
||
// @provider
|
||
type order struct{}
|
||
|
||
// list
|
||
//
|
||
// @Summary 订单列表
|
||
// @Tags Super
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param filter query dto.OrderPageFilter true "Filter"
|
||
// @Success 200 {object} requests.Pager{items=dto.SuperOrderItem}
|
||
//
|
||
// @Router /super/v1/orders [get]
|
||
// @Bind filter query
|
||
func (*order) list(ctx fiber.Ctx, filter *dto.OrderPageFilter) (*requests.Pager, error) {
|
||
return services.Order.SuperOrderPage(ctx, filter)
|
||
}
|
||
|
||
// detail
|
||
//
|
||
// @Summary 订单详情
|
||
// @Tags Super
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param orderID path int64 true "OrderID"
|
||
// @Success 200 {object} dto.SuperOrderDetail
|
||
//
|
||
// @Router /super/v1/orders/:orderID [get]
|
||
// @Bind orderID path
|
||
func (*order) detail(ctx fiber.Ctx, orderID int64) (*dto.SuperOrderDetail, error) {
|
||
return services.Order.SuperOrderDetail(ctx, orderID)
|
||
}
|
||
|
||
// refund
|
||
//
|
||
// @Summary 订单退款(平台)
|
||
// @Description 该接口只负责将订单从 paid 推进到 refunding,并提交异步退款任务;退款入账与权益回收由 worker 异步完成。
|
||
// @Tags Super
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param orderID path int64 true "OrderID"
|
||
// @Param form body dto.SuperOrderRefundForm true "Form"
|
||
// @Success 200 {object} models.Order
|
||
//
|
||
// @Router /super/v1/orders/:orderID/refund [post]
|
||
// @Bind orderID path
|
||
// @Bind form body
|
||
func (*order) refund(ctx fiber.Ctx, orderID int64, form *dto.SuperOrderRefundForm) (*models.Order, error) {
|
||
if form == nil {
|
||
return nil, errorx.ErrInvalidParameter
|
||
}
|
||
|
||
claims, ok := ctx.Locals(consts.CtxKeyClaims).(*jwt.Claims)
|
||
if !ok || claims == nil || claims.UserID <= 0 {
|
||
return nil, errorx.ErrTokenInvalid
|
||
}
|
||
|
||
return services.Order.SuperRefundOrder(
|
||
ctx,
|
||
claims.UserID,
|
||
orderID,
|
||
form.Force,
|
||
form.Reason,
|
||
form.IdempotencyKey,
|
||
time.Now(),
|
||
)
|
||
}
|
||
|
||
// statistics
|
||
//
|
||
// @Summary 订单统计信息
|
||
// @Tags Super
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Success 200 {object} dto.OrderStatisticsResponse
|
||
//
|
||
// @Router /super/v1/orders/statistics [get]
|
||
func (*order) statistics(ctx fiber.Ctx) (*dto.OrderStatisticsResponse, error) {
|
||
return services.Order.SuperStatistics(ctx)
|
||
}
|