update校验未支付订单

This commit is contained in:
2023-11-03 16:43:33 +08:00
parent c3d3c9eb9b
commit 3fbb39474e
3 changed files with 58 additions and 7 deletions

View File

@@ -6,6 +6,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.jsowell.adapay.common.AdaPayment;
import com.jsowell.adapay.dto.QueryPaymentConfirmDTO;
import com.jsowell.adapay.operation.PaymentReverseOperation;
import com.jsowell.adapay.response.PaymentConfirmResponse;
@@ -25,6 +26,7 @@ import com.jsowell.common.enums.AcquirerEnum;
import com.jsowell.common.enums.DelFlagEnum;
import com.jsowell.common.enums.MemberWalletEnum;
import com.jsowell.common.enums.adapay.AdapayStatusEnum;
import com.jsowell.common.enums.adapay.MerchantDelayModeEnum;
import com.jsowell.common.enums.ykc.*;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.DateUtils;
@@ -2014,12 +2016,53 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
this.cleanCacheByOrderCode(orderBasicInfo.getOrderCode(), orderBasicInfo.getTransactionCode());
// 通过订单号查询汇付有没有支付单
checkUnpaidOrder(orderBasicInfo);
}
}
return orderList.size();
}
/**
* 校验未支付订单
* 如果存在因为未收到支付回调导致超时关闭的订单,在修改订单状态后,检查一下是否支付过,把支付的金额退款
* @param orderBasicInfo
*/
private void checkUnpaidOrder(OrderBasicInfo orderBasicInfo) {
String orderCode = orderBasicInfo.getOrderCode();
List<AdaPayment> adaPayments = null;
String memberId = orderBasicInfo.getMemberId();
String merchantId = orderBasicInfo.getMerchantId();
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(merchantId);
String delayMode = pileMerchantInfoService.getDelayModeByWechatAppId(wechatAppId);
try {
adaPayments = adapayService.queryPaymentByOrderNo(orderCode, wechatAppId);
} catch (BaseAdaPayException e) {
throw new RuntimeException(e);
}
if (CollectionUtils.isEmpty(adaPayments)) {
return;
}
// 退款
for (AdaPayment adaPayment : adaPayments) {
String status = adaPayment.getStatus();
if (!AdapayStatusEnum.SUCCEEDED.getValue().equals(status)) {
// 不是交易完成状态,就跳过
continue;
}
String paymentId = adaPayment.getId();
BigDecimal payAmt = new BigDecimal(adaPayment.getPay_amt());
if (MerchantDelayModeEnum.DELAY.getMode().equals(delayMode)) {
// 延时分账商户,创建交易撤销请求
adapayService.createPaymentReverseRequest(paymentId, payAmt, wechatAppId, memberId, ScenarioEnum.ORDER.getValue(), orderCode);
} else {
// 实时分账商户,创建交易退款请求
adapayService.createRefundRequest(paymentId, payAmt, wechatAppId, memberId, ScenarioEnum.ORDER.getValue(), orderCode);
}
}
}
/**
* 微信支付-订单退款处理逻辑
*/