diff --git a/app/mix/controller/vas.go b/app/mix/controller/vas.go index b13d0591..7261b82e 100644 --- a/app/mix/controller/vas.go +++ b/app/mix/controller/vas.go @@ -341,8 +341,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) @@ -353,6 +351,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 a78bc0dc..f45fd89b 100644 --- a/app/mix/controller/zone_vas_api.go +++ b/app/mix/controller/zone_vas_api.go @@ -91,7 +91,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 { @@ -103,6 +102,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 96773fd7..ead92dc8 100644 --- a/app/mix/service/logic/vas.go +++ b/app/mix/service/logic/vas.go @@ -3765,41 +3765,44 @@ func (v *Vas) payRefund(ctx *gin.Context, tx *sqlx.Tx, order *dbstruct.Order) er 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) + }() case vasproto.PayTypeCoin: err := v.store.IncCoins(ctx, tx, order.GetMid(), order.GetPayAmount()) if err != nil {