From 59f495b26689155d687eac1a5d18e05e34c64187 Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Fri, 14 Jun 2024 18:58:03 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/mix/controller/vas.go | 3 +- app/mix/controller/zone_vas_api.go | 2 +- app/mix/service/logic/vas.go | 65 ++++++++++++++++-------------- 3 files changed, 36 insertions(+), 34 deletions(-) diff --git a/app/mix/controller/vas.go b/app/mix/controller/vas.go index 29e7a32e..840ada60 100644 --- a/app/mix/controller/vas.go +++ b/app/mix/controller/vas.go @@ -334,8 +334,6 @@ func DealOneOrder(ctx *gin.Context) { // 订单退款 func RefundOrder(ctx *gin.Context) { req := ctx.MustGet("client_req").(*vasproto.RefundOrderReq) - ReplyOk(ctx, nil) - ec, err := service.DefaultService.RefundOrder(ctx, req) if ec != errcode.ErrCodeVasSrvOk { logger.Error("RefundOrder fail, req: %v, ec: %v", util.ToJson(req), ec) @@ -346,6 +344,7 @@ func RefundOrder(ctx *gin.Context) { ReplyErrCodeMsg(ctx, ec) return } + ReplyOk(ctx, nil) } // 金币订单退款 diff --git a/app/mix/controller/zone_vas_api.go b/app/mix/controller/zone_vas_api.go index 43310297..17d5bab5 100644 --- a/app/mix/controller/zone_vas_api.go +++ b/app/mix/controller/zone_vas_api.go @@ -80,7 +80,6 @@ func ZoneRefund(ctx *gin.Context) { ReplyErrCodeMsg(ctx, errcode.ErrCodeBadParam) return } - ReplyOk(ctx, nil) ec, err := service.DefaultService.ZoneRefund(ctx, req) if ec != errcode.ErrCodeVasSrvOk { @@ -92,6 +91,7 @@ func ZoneRefund(ctx *gin.Context) { ReplyErrCodeMsg(ctx, ec) return } + ReplyOk(ctx, nil) } func ZoneMemberList(ctx *gin.Context) { diff --git a/app/mix/service/logic/vas.go b/app/mix/service/logic/vas.go index ac8ffe50..477fb8ac 100644 --- a/app/mix/service/logic/vas.go +++ b/app/mix/service/logic/vas.go @@ -3647,41 +3647,44 @@ func (v *Vas) payRefund(ctx *gin.Context, order *dbstruct.Order) error { logger.Error("wxpayCli.RefundOne fail, orderId: %v, resp: %v, err: %v", orderId, util.ToJson(resp), err) return err } + logger.Info("wxpayCli.RefundOne apply success, orderId: %v", orderId) // 轮询退款结果,达到同步退款效果 - var ( - loop = 0 - isRefundSuccess = false - ) - for range time.Tick(time.Second * 1) { - if loop >= 10 { - break + go func() { + var ( + loop = 0 + isRefundSuccess = false + ) + for range time.Tick(time.Second * 1) { + if loop >= 10 { + break + } + qRefundResp, _err := yeepayCli.QueryRefund(ctx, &yeepaycli.QueryRefundParam{ + OutTradeNo: orderId, + RefundRequestId: refundRequestId, + }) + if _err != nil { + logger.Error("loop: %v, yeepayCli.QueryRefund fail, orderId: %v, resp: %v, err: %v", loop, orderId, util.ToJson(qRefundResp), _err) + continue + } + if qRefundResp.Code != "OPR00000" { + logger.Error("loop: %v, yeepayCli.QueryRefund fail, invalid code, orderId: %v, resp: %v", loop, orderId, util.ToJson(qRefundResp)) + continue + } + if qRefundResp.Status == "SUCCESS" { + logger.Info("loop: %v, yeepayCli.QueryRefund ok, orderId: %v, resp: %v", loop, orderId, util.ToJson(qRefundResp)) + isRefundSuccess = true + break + } + loop++ } - qRefundResp, _err := yeepayCli.QueryRefund(ctx, &yeepaycli.QueryRefundParam{ - OutTradeNo: orderId, - RefundRequestId: refundRequestId, - }) - if _err != nil { - logger.Error("loop: %v, yeepayCli.QueryRefund fail, orderId: %v, resp: %v, err: %v", loop, orderId, util.ToJson(qRefundResp), _err) - continue + if !isRefundSuccess { + err = fmt.Errorf("退款失败,请稍后再试") + logger.Error("wxpayCli.RefundOne fail, orderId: %v", orderId) + return } - if qRefundResp.Code != "OPR00000" { - logger.Error("loop: %v, yeepayCli.QueryRefund fail, invalid code, orderId: %v, resp: %v", loop, orderId, util.ToJson(qRefundResp)) - continue - } - if qRefundResp.Status == "SUCCESS" { - logger.Info("loop: %v, yeepayCli.QueryRefund ok, orderId: %v, resp: %v", loop, orderId, util.ToJson(qRefundResp)) - isRefundSuccess = true - break - } - loop++ - } - if !isRefundSuccess { - err = fmt.Errorf("退款失败,请稍后再试") - logger.Error("wxpayCli.RefundOne fail, orderId: %v", orderId) - return err - } - logger.Info("wxpayCli.RefundOne success, orderId: %v", orderId) + logger.Info("wxpayCli.RefundOne success, orderId: %v", orderId) + }() } return nil }