From 70e1146ac6920a6607b51eaa2ef22555c0495161 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期二, 22 十月 2024 16:56:00 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java |   60 ++++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 38 insertions(+), 22 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 99dbb12..521ff24 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
@@ -812,21 +812,21 @@
 		chargingDetails.setId(one.getId().toString());
 		TChargingGun chargingGun = chargingGunClient.getChargingGunById(id).getData();
 		TChargingPile chargingPile = chargingPileClient.getChargingPileById(chargingGun.getChargingPileId()).getData();
-			Site site = siteClient.getSiteByIds(Arrays.asList(chargingPile.getSiteId())).getData().get(0);
-			chargingDetails.setName(site.getName() + "-" + chargingPile.getName());
-			chargingDetails.setCode(one.getCode());
-			chargingDetails.setStatus(one.getStatus());
-			chargingDetails.setChargingCost(one.getResidualAmount());
-			UploadRealTimeMonitoringData data = uploadRealTimeMonitoringDataClient.chargingOrderInfo(one.getCode()).getData();
-			if(null != data){
-				chargingDetails.setChargeCurrent(data.getOutput_current());
-				chargingDetails.setChargeVoltage(data.getOutput_voltage());
-				BigDecimal power = data.getOutput_current().multiply(data.getOutput_voltage()).divide(new BigDecimal(1000));
-				chargingDetails.setChargePower(power);
-				chargingDetails.setCompletionRatio(data.getSoc());
-				chargingDetails.setRemainingChargeTime(data.getTime_remaining());
-				chargingDetails.setChargedDegrees(data.getCharging_degree());
-				Integer h = Integer.valueOf(data.getCumulative_charging_time() / 60);
+		Site site = siteClient.getSiteByIds(Arrays.asList(chargingPile.getSiteId())).getData().get(0);
+		chargingDetails.setName(site.getName() + "-" + chargingPile.getName());
+		chargingDetails.setCode(one.getCode());
+		chargingDetails.setStatus(one.getStatus());
+		chargingDetails.setChargingCost(one.getResidualAmount());
+		UploadRealTimeMonitoringData data = uploadRealTimeMonitoringDataClient.chargingOrderInfo(one.getCode()).getData();
+		if(null != data){
+			chargingDetails.setChargeCurrent(data.getOutput_current());
+			chargingDetails.setChargeVoltage(data.getOutput_voltage());
+			BigDecimal power = data.getOutput_current().multiply(data.getOutput_voltage()).divide(new BigDecimal(1000), new MathContext(4, RoundingMode.HALF_EVEN));
+			chargingDetails.setChargePower(power);
+			chargingDetails.setCompletionRatio(data.getSoc());
+			chargingDetails.setRemainingChargeTime(data.getTime_remaining());
+			chargingDetails.setChargedDegrees(data.getCharging_degree());
+			Integer h = Integer.valueOf(data.getCumulative_charging_time() / 60);
 			Integer m = Integer.valueOf(data.getCumulative_charging_time() % 60);
 			chargingDetails.setChargedTime(String.format("%02d", h) + ":" + String.format("%02d", m));
 		}
@@ -1712,7 +1712,8 @@
 		if(null != chargingOrder.getVipDiscount()){
 			//服务费折扣
 			discountAmount = periodServicePrice_total.multiply((new BigDecimal(1).subtract(chargingOrder.getVipDiscount())));
-			
+			periodServicePrice_total = periodServicePrice_total.multiply(chargingOrder.getVipDiscount());
+
 			TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData();
 			if(null != appUser.getVipId()){
 				//判断会员是否还有充电优惠次数
@@ -1765,9 +1766,17 @@
 			if(1 == preferentialMode){
 				//满减
 				if(payAmount.compareTo(tCoupon.getMeetTheConditions()) >= 0){
-					refundAmount = refundAmount.add(tCoupon.getDiscountAmount());
-					order.setCouponDiscountAmount(tCoupon.getDiscountAmount());
-					payAmount = payAmount.subtract(tCoupon.getDiscountAmount());
+					BigDecimal couponDiscountAmount = tCoupon.getDiscountAmount();
+					//如果优惠金额大于服务费金额,以服务费作为最大限制
+					if(periodServicePrice_total.compareTo(couponDiscountAmount) < 0){
+						refundAmount = refundAmount.add(periodServicePrice_total);
+						order.setCouponDiscountAmount(periodServicePrice_total);
+						payAmount = payAmount.subtract(periodServicePrice_total);
+					}else{
+						refundAmount = refundAmount.add(couponDiscountAmount);
+						order.setCouponDiscountAmount(couponDiscountAmount);
+						payAmount = payAmount.subtract(couponDiscountAmount);
+					}
 				}else{
 					order.setAppCouponId(null);
 					order.setCouponDiscountAmount(BigDecimal.ZERO);
@@ -1780,9 +1789,16 @@
 					//折扣金额
 					BigDecimal divide = payAmount.multiply(new BigDecimal(10).subtract(tCoupon.getDiscount())).divide(new BigDecimal(10));
 					divide = divide.compareTo(tCoupon.getMaximumDiscountAmount()) > 0 ? tCoupon.getMaximumDiscountAmount() : divide;
-					refundAmount = refundAmount.add(divide);
-					order.setCouponDiscountAmount(divide);
-					payAmount = payAmount.subtract(divide);
+					//如果优惠金额大于服务费金额,以服务费作为最大限制
+					if(periodServicePrice_total.compareTo(divide) < 0){
+						refundAmount = refundAmount.add(periodServicePrice_total);
+						order.setCouponDiscountAmount(periodServicePrice_total);
+						payAmount = payAmount.subtract(periodServicePrice_total);
+					}else{
+						refundAmount = refundAmount.add(divide);
+						order.setCouponDiscountAmount(divide);
+						payAmount = payAmount.subtract(divide);
+					}
 				}else{
 					order.setAppCouponId(null);
 					order.setCouponDiscountAmount(BigDecimal.ZERO);

--
Gitblit v1.7.1