refund 优化

This commit is contained in:
lwl0608 2024-06-14 18:59:17 +08:00
commit 97393ca46c
3 changed files with 36 additions and 34 deletions

View File

@ -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)
}
// 金币订单退款

View File

@ -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) {

View File

@ -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 {