简化异步任务的交易取消逻辑
This commit is contained in:
2
go.mod
2
go.mod
@@ -19,7 +19,6 @@ require (
|
|||||||
github.com/redis/go-redis/v9 v9.8.0
|
github.com/redis/go-redis/v9 v9.8.0
|
||||||
github.com/shopspring/decimal v1.4.0
|
github.com/shopspring/decimal v1.4.0
|
||||||
github.com/smartwalle/alipay/v3 v3.2.25
|
github.com/smartwalle/alipay/v3 v3.2.25
|
||||||
github.com/valyala/fasthttp v1.59.0
|
|
||||||
github.com/wechatpay-apiv3/wechatpay-go v0.2.20
|
github.com/wechatpay-apiv3/wechatpay-go v0.2.20
|
||||||
golang.org/x/crypto v0.36.0
|
golang.org/x/crypto v0.36.0
|
||||||
gorm.io/driver/postgres v1.5.11
|
gorm.io/driver/postgres v1.5.11
|
||||||
@@ -71,6 +70,7 @@ require (
|
|||||||
github.com/spf13/cast v1.7.0 // indirect
|
github.com/spf13/cast v1.7.0 // indirect
|
||||||
github.com/tjfoc/gmsm v1.4.1 // indirect
|
github.com/tjfoc/gmsm v1.4.1 // indirect
|
||||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||||
|
github.com/valyala/fasthttp v1.59.0 // indirect
|
||||||
golang.org/x/mod v0.24.0 // indirect
|
golang.org/x/mod v0.24.0 // indirect
|
||||||
golang.org/x/net v0.37.0 // indirect
|
golang.org/x/net v0.37.0 // indirect
|
||||||
golang.org/x/sync v0.12.0 // indirect
|
golang.org/x/sync v0.12.0 // indirect
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"platform/web/auth"
|
"platform/web/auth"
|
||||||
"platform/web/core"
|
"platform/web/core"
|
||||||
@@ -121,25 +120,17 @@ func TradeCancelByTask(c *fiber.Ctx) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析请求参数
|
// 取消交易
|
||||||
req := new(TradeCheckReq)
|
req := new(TradeCheckReq)
|
||||||
if err := c.BodyParser(req); err != nil {
|
if err := c.BodyParser(req); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查订单状态
|
// 检查订单状态
|
||||||
err = s.Trade.ConfirmTradeCanceled(&s.CheckTradeData{
|
err = s.Trade.CancelTrade(req.TradeNo, req.Method, time.Now())
|
||||||
TradeNo: req.TradeNo,
|
|
||||||
Method: req.Method,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Debug(fmt.Sprintf("订单无需取消:%s", err.Error()))
|
return err
|
||||||
} else {
|
|
||||||
err = s.Trade.CancelTrade(req.TradeNo, req.Method, time.Now())
|
|
||||||
if err != nil {
|
|
||||||
slog.Warn("取消交易失败", "trade_no", req.TradeNo, "method", req.Method, "error", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.SendStatus(fiber.StatusNoContent)
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -378,15 +378,12 @@ func (s *tradeService) CancelTrade(tradeNo string, method trade2.Method, now tim
|
|||||||
}
|
}
|
||||||
|
|
||||||
case trade2.MethodSft, trade2.MethodSftAlipay, trade2.MethodSftWeChat:
|
case trade2.MethodSft, trade2.MethodSftAlipay, trade2.MethodSftWeChat:
|
||||||
resp, err := g.SFTPay.OrderClose(&g.OrderCloseReq{
|
_, err := g.SFTPay.OrderClose(&g.OrderCloseReq{
|
||||||
MchOrderNo: &tradeNo,
|
MchOrderNo: &tradeNo,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
slog.Debug(fmt.Sprintf("订单无需关闭:%s", err.Error()))
|
||||||
}
|
return nil
|
||||||
if resp.State != "TRADE_CLOSE" {
|
|
||||||
slog.Warn("商福通交易取消失败", "state", resp.State)
|
|
||||||
return errors.New("交易取消失败")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user