|
|
@@ -589,8 +589,21 @@ public class WFTOrderService {
|
|
|
// pay_result: 0-成功
|
|
|
boolean isPaid = "SUCCESS".equals(tradeState) || "0".equals(payResult);
|
|
|
|
|
|
- // 8. 如果支付成功但本地订单状态未更新,同步更新订单状态
|
|
|
- if (isPaid && !SystemConstants.STATUS_TWO.equals(orderInfo.getOrderStatus())) {
|
|
|
+ // 8. 如果支付成功,重新查询订单状态进行幂等性检查,避免与支付回调并发导致重复处理
|
|
|
+ if (isPaid) {
|
|
|
+ // 重新查询订单状态,使用数据库行锁保证并发安全
|
|
|
+ UserOrderInfo latestOrderInfo = userOrderInfoMapper.selectOne(
|
|
|
+ Wrappers.lambdaQuery(UserOrderInfo.class)
|
|
|
+ .eq(UserOrderInfo::getOrderNo, orderNo)
|
|
|
+ .last("FOR UPDATE")
|
|
|
+ );
|
|
|
+
|
|
|
+ // 幂等性检查:如果订单已经被支付回调处理,直接返回成功
|
|
|
+ if (SystemConstants.STATUS_TWO.equals(latestOrderInfo.getOrderStatus())) {
|
|
|
+ log.info("订单已被支付回调处理,跳过重复处理: orderNo={}", orderNo);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
log.info("同步更新订单支付状态: orderNo={}", orderNo);
|
|
|
String transactionId = queryResult.get("transaction_id"); // 平台订单号
|
|
|
String totalFeeStr = queryResult.get("total_fee"); // 总金额(分)
|
|
|
@@ -599,7 +612,7 @@ public class WFTOrderService {
|
|
|
//转localDateTime
|
|
|
LocalDateTime payTime = LocalDateTime.parse(timeEnd, DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
|
|
//支付成功业务处理
|
|
|
- successPayOrder(orderInfo, transactionId, payTime, payMoney);
|
|
|
+ successPayOrder(latestOrderInfo, transactionId, payTime, payMoney);
|
|
|
}
|
|
|
return isPaid;
|
|
|
|
|
|
@@ -776,6 +789,7 @@ public class WFTOrderService {
|
|
|
//查询账户余额
|
|
|
UserAccount userAccount =
|
|
|
userAccountService.getOne(Wrappers.<UserAccount>lambdaQuery().eq(UserAccount::getUserId, userId).last("limit 1"));
|
|
|
+ log.info("用户:{},申请退款:{}", userId, userAccount.getBalance());
|
|
|
if (userAccount.getBalance().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
return "账户余额为 0";
|
|
|
}
|
|
|
@@ -786,7 +800,7 @@ public class WFTOrderService {
|
|
|
.eq(UserOrderInfo::getUserId, userId)
|
|
|
.in(UserOrderInfo::getOrderStatus, SystemConstants.STATUS_TWO, SystemConstants.STATUS_FIVE)
|
|
|
.between(UserOrderInfo::getCreateTime, LocalDateTime.now().minusYears(1), LocalDateTime.now())
|
|
|
- .orderByDesc(UserOrderInfo::getCreateTime) // 按创建时间升序,优先退早期订单
|
|
|
+ .orderByAsc(UserOrderInfo::getCreateTime) // 按创建时间升序,优先退早期订单
|
|
|
);
|
|
|
|
|
|
if (CollUtil.isEmpty(userOrderInfoList)) {
|
|
|
@@ -869,7 +883,7 @@ public class WFTOrderService {
|
|
|
}
|
|
|
|
|
|
public Long refundOrder(UserOrderInfo userOrderInfo, BigDecimal refundAmount, String reason, Integer type) throws Exception {
|
|
|
- log.info("进入退款接口------>");
|
|
|
+ log.info("进入退款接口------>退款金额:{}",refundAmount);
|
|
|
log.info("执行操作的 原支付交易对应的商户订单号:{}", userOrderInfo.getOrderNo());
|
|
|
|
|
|
//退款单号
|