优化交易取消逻辑并更新相关数据结构;修复套餐用量统计接口问题
This commit is contained in:
@@ -6,10 +6,12 @@ import (
|
||||
"github.com/valyala/fasthttp/fasthttpadaptor"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"platform/web/auth"
|
||||
trade2 "platform/web/domains/trade"
|
||||
g "platform/web/globals"
|
||||
q "platform/web/queries"
|
||||
s "platform/web/services"
|
||||
"platform/web/tasks"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
@@ -17,8 +19,6 @@ import (
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/services/payments"
|
||||
)
|
||||
|
||||
// region TradeCheckSSE
|
||||
|
||||
func TradeCheckSSE(c *fiber.Ctx) error {
|
||||
// 设置响应头
|
||||
c.Set("Content-Type", "text/event-stream")
|
||||
@@ -28,9 +28,31 @@ func TradeCheckSSE(c *fiber.Ctx) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// endregion
|
||||
type TradeCheckReq struct {
|
||||
tasks.CancelTradeData
|
||||
}
|
||||
|
||||
// region AlipayCallback
|
||||
func TradeCancelByTask(c *fiber.Ctx) error {
|
||||
// 检查权限
|
||||
_, err := auth.Protect(c, []auth.PayloadType{auth.PayloadInternalServer}, []string{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 解析请求参数
|
||||
req := new(TradeCheckReq)
|
||||
if err := c.BodyParser(req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 取消支付
|
||||
err = s.Trade.CancelTrade(req.TradeNo, req.Method)
|
||||
if err != nil {
|
||||
slog.Warn("取消交易失败", "trade_no", req.TradeNo, "method", req.Method, "error", err)
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusNoContent)
|
||||
}
|
||||
|
||||
func AlipayCallback(c *fiber.Ctx) (err error) {
|
||||
|
||||
@@ -121,14 +143,6 @@ func AlipayCallback(c *fiber.Ctx) (err error) {
|
||||
return c.SendString("success")
|
||||
}
|
||||
|
||||
func isRefund(notification *alipay.Notification) bool {
|
||||
return notification.OutBizNo != "" || notification.RefundFee != "" || notification.GmtRefund != ""
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
// region WechatPayCallback
|
||||
|
||||
func WechatPayCallback(c *fiber.Ctx) error {
|
||||
|
||||
// 解析请求参数
|
||||
@@ -188,5 +202,3 @@ func WechatPayCallback(c *fiber.Ctx) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
Reference in New Issue
Block a user