This commit is contained in:
Lemon
2024-01-19 11:01:50 +08:00

View File

@@ -6,7 +6,6 @@ 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.QueryConfirmReverseDTO;
import com.jsowell.adapay.dto.QueryPaymentConfirmDTO;
import com.jsowell.adapay.operation.PaymentReverseOperation;
@@ -2070,38 +2069,63 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
*/
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);
}
// List<AdaPayment> adaPayments = null;
// try {
// adaPayments = adapayService.queryPaymentByOrderNo(orderCode, wechatAppId);
// } catch (BaseAdaPayException e) {
// throw new RuntimeException(e);
// }
if (CollectionUtils.isEmpty(adaPayments)) {
// if (CollectionUtils.isEmpty(adaPayments)) {
// return;
// }
BigDecimal orderAmount = orderBasicInfo.getOrderAmount() == null ? BigDecimal.ZERO : orderBasicInfo.getOrderAmount();
if (orderAmount.compareTo(BigDecimal.ZERO) > 0) {
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);
// 如果超时关闭的订单,存在支付信息,都退款处理
List<OrderPayRecord> orderPayRecordList = orderPayRecordService.getOrderPayRecordList(orderCode);
logger.info("校验未支付订单orderCode:{}, 支付信息:{}", orderCode, JSON.toJSONString(orderPayRecordList));
if (CollectionUtils.isNotEmpty(orderPayRecordList)) {
for (OrderPayRecord orderPayRecord : orderPayRecordList) {
List<PaymentInfo> paymentInfos = orderPayRecordService.parseDeductionRecord(orderPayRecord.getDeductionRecord());
for (PaymentInfo paymentInfo : paymentInfos) {
String paymentId = paymentInfo.getPaymentId();
BigDecimal payAmt = new BigDecimal(paymentInfo.getAmount());
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);
}
}
}
}
// 退款
// 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);
// }
// }
}
/**