feat: C端订单支付拆分 — 创建订单与发起支付分离
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m10s

- CreateOrder 改造:普通下单只建单(无支付参数),强充场景保持原有微信支付一步完成
- 新增 POST /orders/:id/pay 统一支付入口,支持 wallet(钱包)和 wechat(微信 JSAPI)
- 移除 POST /orders/:id/wallet-pay,合并至统一支付接口
- app_type 改为可选字段(强充场景必传,普通下单无需传)
- CreateOrderResponse.pay_config 改为 omitempty(普通下单不返回支付参数)
This commit is contained in:
2026-03-31 12:43:34 +08:00
parent 121462c00f
commit dc4f3cb7ba
6 changed files with 276 additions and 62 deletions

View File

@@ -14,7 +14,7 @@ import (
)
// ClientOrderHandler C 端订单处理器
// 提供 D1~D3 下单、列表、详情接口。
// 提供 D1~D4 下单、列表、详情、支付接口。
type ClientOrderHandler struct {
clientOrderService *clientorder.Service
logger *zap.Logger
@@ -83,6 +83,32 @@ func (h *ClientOrderHandler) ListOrders(c *fiber.Ctx) error {
return response.SuccessWithPagination(c, list, total, req.Page, req.PageSize)
}
// PayOrder D4 订单支付。
// POST /api/c/v1/orders/:id/pay
func (h *ClientOrderHandler) PayOrder(c *fiber.Ctx) error {
customerID, ok := middleware.GetCustomerID(c)
if !ok || customerID == 0 {
return errors.New(errors.CodeUnauthorized)
}
orderID, err := strconv.ParseUint(c.Params("id"), 10, 64)
if err != nil || orderID == 0 {
return errors.New(errors.CodeInvalidParam)
}
var req dto.ClientPayOrderRequest
if err := c.BodyParser(&req); err != nil {
return errors.New(errors.CodeInvalidParam)
}
resp, err := h.clientOrderService.PayOrder(c.UserContext(), customerID, uint(orderID), &req)
if err != nil {
return err
}
return response.Success(c, resp)
}
// GetOrderDetail D3 订单详情。
// GET /api/c/v1/orders/:id
func (h *ClientOrderHandler) GetOrderDetail(c *fiber.Ctx) error {