diff --git a/internal/handler/admin/order.go b/internal/handler/admin/order.go index eb27043..94ec143 100644 --- a/internal/handler/admin/order.go +++ b/internal/handler/admin/order.go @@ -107,3 +107,21 @@ func (h *OrderHandler) Cancel(c *fiber.Ctx) error { return response.Success(c, nil) } + +// PurchaseCheck 代购订单预检接口 +// 路由: POST /api/admin/orders/purchase-check +// 参数: order_type(订单类型), resource_id(资源ID), package_ids(套餐ID列表) +// 响应: 套餐总价、强充要求、实际支付金额等预检结果 +func (h *OrderHandler) PurchaseCheck(c *fiber.Ctx) error { + var req dto.PurchaseCheckRequest + if err := c.BodyParser(&req); err != nil { + return errors.New(errors.CodeInvalidParam, "请求参数解析失败") + } + + result, err := h.service.GetPurchaseCheck(c.UserContext(), &req) + if err != nil { + return err + } + + return response.Success(c, result) +} diff --git a/internal/handler/callback/payment.go b/internal/handler/callback/payment.go index e062055..9c801bb 100644 --- a/internal/handler/callback/payment.go +++ b/internal/handler/callback/payment.go @@ -3,26 +3,31 @@ package callback import ( "context" "net/http" + "strings" "github.com/gofiber/fiber/v2" "github.com/valyala/fasthttp/fasthttpadaptor" "github.com/break/junhong_cmp_fiber/internal/model" orderService "github.com/break/junhong_cmp_fiber/internal/service/order" + rechargeService "github.com/break/junhong_cmp_fiber/internal/service/recharge" + "github.com/break/junhong_cmp_fiber/pkg/constants" "github.com/break/junhong_cmp_fiber/pkg/errors" "github.com/break/junhong_cmp_fiber/pkg/response" "github.com/break/junhong_cmp_fiber/pkg/wechat" ) type PaymentHandler struct { - orderService *orderService.Service - wechatPayment wechat.PaymentServiceInterface + orderService *orderService.Service + rechargeService *rechargeService.Service + wechatPayment wechat.PaymentServiceInterface } -func NewPaymentHandler(orderService *orderService.Service, wechatPayment wechat.PaymentServiceInterface) *PaymentHandler { +func NewPaymentHandler(orderService *orderService.Service, rechargeService *rechargeService.Service, wechatPayment wechat.PaymentServiceInterface) *PaymentHandler { return &PaymentHandler{ - orderService: orderService, - wechatPayment: wechatPayment, + orderService: orderService, + rechargeService: rechargeService, + wechatPayment: wechatPayment, } } @@ -41,6 +46,14 @@ func (h *PaymentHandler) WechatPayCallback(c *fiber.Ctx) error { if result.TradeState != "SUCCESS" { return nil } + + // 根据订单号前缀判断订单类型 + if strings.HasPrefix(result.OutTradeNo, constants.RechargeOrderPrefix) { + // 充值订单回调 + return h.rechargeService.HandlePaymentCallback(ctx, result.OutTradeNo, model.PaymentMethodWechat, result.TransactionID) + } + + // 套餐订单回调 return h.orderService.HandlePaymentCallback(ctx, result.OutTradeNo, model.PaymentMethodWechat) }) @@ -65,8 +78,19 @@ func (h *PaymentHandler) AlipayCallback(c *fiber.Ctx) error { return errors.New(errors.CodeInvalidParam, "订单号不能为空") } - if err := h.orderService.HandlePaymentCallback(c.UserContext(), req.OrderNo, model.PaymentMethodAlipay); err != nil { - return err + ctx := c.UserContext() + + // 根据订单号前缀判断订单类型 + if strings.HasPrefix(req.OrderNo, constants.RechargeOrderPrefix) { + // 充值订单回调 + if err := h.rechargeService.HandlePaymentCallback(ctx, req.OrderNo, model.PaymentMethodAlipay, ""); err != nil { + return err + } + } else { + // 套餐订单回调 + if err := h.orderService.HandlePaymentCallback(ctx, req.OrderNo, model.PaymentMethodAlipay); err != nil { + return err + } } return c.SendString("success")