From 45109a672b4946a059bac111d3a61a87e1886274 Mon Sep 17 00:00:00 2001
From: longz <longzhaoz@qq.com>
Date: 星期三, 29 七月 2026 11:12:52 +0800
Subject: [PATCH] 各类修复

---
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java |   46 ++++++++++++++++++++++++++++++++++++----------
 1 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
index 2e00b15..851d458 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
@@ -3219,7 +3219,11 @@
 			if (settlementIncome != null) {
 				result.addAll(settlementIncome);
 			}
-			List<SixChargingDto> currentMonthIncome = this.baseMapper.chargeCurrentMonth(siteIds);
+				String siteIdsCsv = siteIds == null ? null : siteIds.stream()
+						.filter(Objects::nonNull)
+						.map(String::valueOf)
+						.collect(Collectors.joining(","));
+				List<SixChargingDto> currentMonthIncome = this.baseMapper.chargeCurrentMonth(siteIdsCsv);
 			if (currentMonthIncome != null) {
 				result.addAll(currentMonthIncome);
 			}
@@ -4955,21 +4959,23 @@
 		}
 		mergeSuccessfulRefundAmounts(order);
 		PayOrderInfoDto dto = new PayOrderInfoDto();
+		BigDecimal thirdPayAmount = getRefundableThirdPayAmount(order);
+		BigDecimal thirdRefundAmount = money(order.getThirdRefundAmount());
 		dto.setOrderId(order.getId().toString());
 		dto.setCode(order.getCode());
 		dto.setTradeNo(order.getRechargeSerialNumber());
 		dto.setPayType(order.getRechargePaymentType());
-		dto.setPayAmount(money(order.getPaymentAmount()));
+		dto.setPayAmount(thirdPayAmount);
 		dto.setPayTime(order.getPayTime());
-		dto.setRefundAmount(money(order.getRefundAmount()));
+		dto.setRefundAmount(thirdRefundAmount);
 		dto.setRechargeAmount(money(order.getRechargeAmount()));
-		dto.setFinalAmount(money(order.getPaymentAmount()).subtract(money(order.getRefundAmount())).setScale(2, RoundingMode.HALF_UP));
+		dto.setFinalAmount(thirdPayAmount.subtract(thirdRefundAmount).max(BigDecimal.ZERO).setScale(2, RoundingMode.HALF_UP));
 		dto.setPayMethod(order.getPayMethod());
-		dto.setBalancePayAmount(order.getBalancePayAmount());
-		dto.setThirdPayAmount(order.getThirdPayAmount());
-		dto.setBalanceRefundAmount(order.getBalanceRefundAmount());
-		dto.setThirdRefundAmount(order.getThirdRefundAmount());
-		dto.setRefundableAmount(getManualRefundableAmount(order));
+		dto.setBalancePayAmount(money(order.getBalancePayAmount()));
+		dto.setThirdPayAmount(thirdPayAmount);
+		dto.setBalanceRefundAmount(money(order.getBalanceRefundAmount()));
+		dto.setThirdRefundAmount(thirdRefundAmount);
+		dto.setRefundableAmount(getSpecialRefundableAmount(order));
 		return R.ok(dto);
 	}
 
@@ -5007,6 +5013,26 @@
 				.setScale(2, RoundingMode.HALF_UP);
 	}
 
+	private BigDecimal getSpecialRefundableAmount(TChargingOrder order) {
+		return calculateSpecialRefundableAmount(
+				getManualRefundableAmount(order),
+				getRefundableThirdPayAmount(order),
+				money(order == null ? null : order.getThirdRefundAmount()));
+	}
+
+	static BigDecimal calculateSpecialRefundableAmount(BigDecimal manualRefundableAmount,
+			BigDecimal thirdPayAmount, BigDecimal thirdRefundAmount) {
+		BigDecimal normalizedManualAmount = manualRefundableAmount == null ? BigDecimal.ZERO : manualRefundableAmount;
+		BigDecimal normalizedThirdPayAmount = thirdPayAmount == null ? BigDecimal.ZERO : thirdPayAmount;
+		BigDecimal normalizedThirdRefundAmount = thirdRefundAmount == null ? BigDecimal.ZERO : thirdRefundAmount;
+		BigDecimal remainingThirdAmount = normalizedThirdPayAmount
+				.subtract(normalizedThirdRefundAmount)
+				.max(BigDecimal.ZERO);
+		return normalizedManualAmount
+				.min(remainingThirdAmount)
+				.setScale(2, RoundingMode.HALF_UP);
+	}
+
 	@Override
 	@Transactional
 	public R specialRefund(PayOrderRefundDto payOrderQueryDto) {
@@ -5032,7 +5058,7 @@
 			}
 			mergeSuccessfulRefundAmounts(order);
 			BigDecimal refundAmount = money(payOrderQueryDto.getRefundAmount());
-			BigDecimal refundableAmount = getManualRefundableAmount(order);
+			BigDecimal refundableAmount = getSpecialRefundableAmount(order);
 			if (refundAmount.compareTo(refundableAmount) > 0) {
 				return R.fail("退款金额不能超过剩余可退金额");
 			}

--
Gitblit v1.7.1