fadd
This commit is contained in:
@@ -294,8 +294,8 @@ func (s *XpayService) QueryOrder(ctx context.Context, openid, orderNo, sessionKe
|
||||
status.RawOrder = string(orderRaw)
|
||||
_ = json.Unmarshal(orderRaw, &status)
|
||||
}
|
||||
logx.WithContext(ctx).Infof("[xpay] query_order order_no=%s status=%d paid_fee=%d left_fee=%d wx_order_id=%s err_msg=%s raw=%s",
|
||||
orderNo, status.Status, status.PaidFee, status.LeftFee, status.WxOrderID, status.ErrMsg, status.RawOrder)
|
||||
logx.WithContext(ctx).Infof("[xpay] query_order order_no=%s status=%d paid_fee=%d left_fee=%d wx_order_id=%s err_msg=%s",
|
||||
orderNo, status.Status, status.PaidFee, status.LeftFee, status.WxOrderID, status.ErrMsg)
|
||||
return &status, nil
|
||||
}
|
||||
|
||||
@@ -309,6 +309,11 @@ func (s *XpayService) RefundOrder(ctx context.Context, openid, orderNo, refundOr
|
||||
if err != nil {
|
||||
return fmt.Errorf("退款前查单失败: %w", err)
|
||||
}
|
||||
if IsXpayAlreadyRefunded(status) {
|
||||
logx.WithContext(ctx).Infof("[xpay] refund_order skip already refunded order_no=%s wx_status=%d left_fee=%d paid_fee=%d",
|
||||
orderNo, status.Status, status.LeftFee, status.PaidFee)
|
||||
return nil
|
||||
}
|
||||
leftFee := status.LeftFee
|
||||
if leftFee <= 0 {
|
||||
leftFee = status.PaidFee
|
||||
@@ -339,7 +344,7 @@ func (s *XpayService) RefundOrder(ctx context.Context, openid, orderNo, refundOr
|
||||
apiResp, err := s.callAPI(ctx, "/xpay/refund_order", bodyJSON, "", false)
|
||||
if err != nil {
|
||||
if xpayErr, ok := err.(*XpayAPIError); ok {
|
||||
if xpayErr.ErrCode == 268490004 || xpayErr.ErrCode == 268490014 {
|
||||
if xpayErr.ErrCode == 268490004 || xpayErr.ErrCode == 268490005 || xpayErr.ErrCode == 268490014 {
|
||||
logx.WithContext(ctx).Infof("[xpay] refund_order idempotent order_no=%s errcode=%d", orderNo, xpayErr.ErrCode)
|
||||
return nil
|
||||
}
|
||||
@@ -384,14 +389,30 @@ func (s *XpayService) NotifyProvideGoods(ctx context.Context, openid, orderNo, w
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsPaidStatus 微信订单状态 2/3/4 视为支付成功
|
||||
// IsXpayPaidStatus 微信订单状态 2/3/4 视为支付成功
|
||||
func IsXpayPaidStatus(status int) bool {
|
||||
return status == 2 || status == 3 || status == 4
|
||||
}
|
||||
|
||||
// IsXpayClosedStatus 5~10 视为关闭
|
||||
// IsXpayRefundedStatus 微信侧已退款:5=订单已经退款,8=用户退款完成
|
||||
func IsXpayRefundedStatus(status int) bool {
|
||||
return status == 5 || status == 8
|
||||
}
|
||||
|
||||
// IsXpayAlreadyRefunded 查单结果表示微信侧已无可退金额(含在微信后台手动退款、本地未同步的情况)
|
||||
func IsXpayAlreadyRefunded(status *xpayOrderStatus) bool {
|
||||
if status == nil {
|
||||
return false
|
||||
}
|
||||
if IsXpayRefundedStatus(status.Status) {
|
||||
return true
|
||||
}
|
||||
return status.PaidFee > 0 && status.LeftFee == 0 && status.Status >= 2
|
||||
}
|
||||
|
||||
// IsXpayClosedStatus 6 视为关闭
|
||||
func IsXpayClosedStatus(status int) bool {
|
||||
return status >= 5 && status <= 10
|
||||
return status == 6
|
||||
}
|
||||
|
||||
// VerifyPushSignature GET 验签(消息推送配置)
|
||||
|
||||
Reference in New Issue
Block a user