mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-26 05:55:03 +08:00
超时关闭的订单,检查一下汇付是否存在支付单,一起退款
This commit is contained in:
@@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
||||
import com.jsowell.adapay.dto.QueryConfirmReverseDTO;
|
||||
import com.jsowell.adapay.dto.QueryPaymentConfirmDTO;
|
||||
@@ -2029,7 +2030,8 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
||||
public List<OrderBasicInfo> getUnpaidOrderListOver15Min() {
|
||||
Date now = DateUtils.addMinute(new Date(), -15);
|
||||
String nowString = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, now);
|
||||
return orderBasicInfoMapper.getUnpaidOrderListOver15Min(nowString);
|
||||
List<OrderBasicInfo> list = orderBasicInfoMapper.getUnpaidOrderListOver15Min(nowString);
|
||||
return CollectionUtils.isNotEmpty(list) ? list : Lists.newArrayList();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2047,18 +2049,19 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
||||
public int close15MinutesOfUnpaidOrders() {
|
||||
List<OrderBasicInfo> orderList = getUnpaidOrderListOver15Min();
|
||||
if (CollectionUtils.isNotEmpty(orderList)) {
|
||||
List<String> orderIdList = orderList.stream()
|
||||
.map(x -> String.valueOf(x.getId()))
|
||||
.collect(Collectors.toList());
|
||||
// 修改订单状态
|
||||
updateOrderStatusById(orderIdList, OrderStatusEnum.ORDER_CLOSE_TIMEOUT.getValue());
|
||||
|
||||
for (OrderBasicInfo orderBasicInfo : orderList) {
|
||||
this.cleanCacheByOrderCode(orderBasicInfo.getOrderCode(), orderBasicInfo.getTransactionCode());
|
||||
|
||||
// 通过订单号查询汇付有没有支付单
|
||||
checkUnpaidOrder(orderBasicInfo);
|
||||
}
|
||||
|
||||
// 订单id集合
|
||||
List<String> orderIdList = orderList.stream()
|
||||
.map(x -> String.valueOf(x.getId()))
|
||||
.collect(Collectors.toList());
|
||||
// 根据orderIdList修改订单状态
|
||||
updateOrderStatusById(orderIdList, OrderStatusEnum.ORDER_CLOSE_TIMEOUT.getValue());
|
||||
}
|
||||
return orderList.size();
|
||||
}
|
||||
@@ -2075,59 +2078,40 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
||||
String merchantId = orderBasicInfo.getMerchantId();
|
||||
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(merchantId);
|
||||
String delayMode = pileMerchantInfoService.getDelayModeByWechatAppId(wechatAppId);
|
||||
// List<AdaPayment> adaPayments = null;
|
||||
// try {
|
||||
// adaPayments = adapayService.queryPaymentByOrderNo(orderCode, wechatAppId);
|
||||
// } catch (BaseAdaPayException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
|
||||
// if (CollectionUtils.isEmpty(adaPayments)) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 订单总金额
|
||||
BigDecimal orderAmount = orderBasicInfo.getOrderAmount() == null ? BigDecimal.ZERO : orderBasicInfo.getOrderAmount();
|
||||
if (orderAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果超时关闭的订单,存在支付信息,都退款处理
|
||||
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);
|
||||
}
|
||||
Set<PaymentInfo> paymentInfoSet = Sets.newHashSet();
|
||||
List<PaymentInfo> paymentInfos1 = orderPayRecordService.queryPaymentInfosByOrderCode(orderCode);
|
||||
paymentInfoSet.addAll(paymentInfos1);
|
||||
try {
|
||||
String redisKey = CacheConstants.ORDER_WECHAT_PAY_PARAMETERS + orderCode;
|
||||
String orderNo = redisCache.getCacheObject(redisKey);
|
||||
if (StringUtils.isNotBlank(orderNo)) {
|
||||
List<PaymentInfo> paymentInfos2 = adapayService.queryPaymentInfosByOrderNo(orderNo, wechatAppId);
|
||||
paymentInfoSet.addAll(paymentInfos2);
|
||||
}
|
||||
} catch (BaseAdaPayException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(paymentInfoSet)) {
|
||||
for (PaymentInfo paymentInfo : paymentInfoSet) {
|
||||
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);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -78,6 +78,19 @@ public class OrderPayRecordServiceImpl implements OrderPayRecordService {
|
||||
return orderPayRecordMapper.getOrderPayRecordList(orderCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PaymentInfo> queryPaymentInfosByOrderCode(String orderCode) {
|
||||
List<PaymentInfo> resultList = Lists.newArrayList();
|
||||
List<OrderPayRecord> orderPayRecordList = getOrderPayRecordList(orderCode);
|
||||
if (CollectionUtils.isNotEmpty(orderPayRecordList)) {
|
||||
for (OrderPayRecord orderPayRecord : orderPayRecordList) {
|
||||
List<PaymentInfo> paymentInfos = this.parseDeductionRecord(orderPayRecord.getDeductionRecord());
|
||||
resultList.addAll(paymentInfos);
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单支付信息
|
||||
* 加缓存
|
||||
|
||||
Reference in New Issue
Block a user