Pu Zhibing
2024-11-05 0d80fb942bdfdd25a224abf5c9d465f0fad1846c
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
@@ -1977,6 +1977,8 @@
            }
         }
      }
      //会员折扣金额
      discountAmount = discountAmount.setScale(2, RoundingMode.DOWN);
      payAmount = payAmount.subtract(discountAmount);
      
      TChargingOrder order = new TChargingOrder();
@@ -1994,12 +1996,13 @@
      order.setEndTime(LocalDateTime.parse(vo.getEnd_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SS")));
      order.setStatus(5);
      order.setOrderAmount(orderAmount.setScale(2, RoundingMode.DOWN));
      order.setVipDiscountAmount(discountAmount.setScale(2, RoundingMode.DOWN));
      order.setVipDiscountAmount(discountAmount);
      order.setElectrovalence(periodElectricPrice_total.setScale(2, RoundingMode.DOWN));
      order.setChargingCapacity(vo.getTotal_electricity());
      order.setElectricity(vo.getTotal_electricity());
      
      //计算优惠券
      BigDecimal couponDiscount = BigDecimal.ZERO;
      if(null != chargingOrder.getAppCouponId()){
         //判断实际充电金额是否满足优惠券使用条件,如果不满足则不适用优惠券。
         TAppCoupon appCoupon = appCouponClient.getAppCouponById(chargingOrder.getAppCouponId()).getData();
@@ -2012,17 +2015,12 @@
               BigDecimal couponDiscountAmount = tCoupon.getDiscountAmount();
               //如果优惠金额大于服务费金额,以服务费作为最大限制
               if(periodServicePrice_total.compareTo(couponDiscountAmount) < 0){
                  refundAmount = refundAmount.add(periodServicePrice_total);
                  order.setCouponDiscountAmount(periodServicePrice_total);
                  payAmount = payAmount.subtract(periodServicePrice_total);
                  couponDiscount = periodServicePrice_total;
                  periodServicePrice_total = BigDecimal.ZERO;
               }else{
                  refundAmount = refundAmount.add(couponDiscountAmount);
                  order.setCouponDiscountAmount(couponDiscountAmount);
                  payAmount = payAmount.subtract(couponDiscountAmount);
                  couponDiscount = couponDiscountAmount;
                  periodServicePrice_total = periodServicePrice_total.subtract(couponDiscountAmount);
               }
               appCoupon.setStatus(2);
               appCouponClient.updateAppCoupon(appCoupon);
            }else{
@@ -2039,14 +2037,10 @@
               divide = divide.compareTo(tCoupon.getMaximumDiscountAmount()) > 0 ? tCoupon.getMaximumDiscountAmount() : divide;
               //如果优惠金额大于服务费金额,以服务费作为最大限制
               if(periodServicePrice_total.compareTo(divide) < 0){
                  refundAmount = refundAmount.add(periodServicePrice_total);
                  order.setCouponDiscountAmount(periodServicePrice_total);
                  payAmount = payAmount.subtract(periodServicePrice_total);
                  couponDiscount = periodServicePrice_total;
                  periodServicePrice_total = BigDecimal.ZERO;
               }else{
                  refundAmount = refundAmount.add(divide);
                  order.setCouponDiscountAmount(divide);
                  payAmount = payAmount.subtract(divide);
                  couponDiscount = divide;
                  periodServicePrice_total = periodServicePrice_total.subtract(divide);
               }
               
@@ -2059,7 +2053,11 @@
            }
         }
      }
      //优惠券优惠金额
      couponDiscount = couponDiscount.setScale(2, RoundingMode.DOWN);
      refundAmount = refundAmount.add(couponDiscount);
      payAmount = payAmount.subtract(couponDiscount);
      order.setCouponDiscountAmount(couponDiscount);
      order.setServiceCharge(periodServicePrice_total.setScale(2, RoundingMode.DOWN));
      order.setPaymentAmount(payAmount.setScale(2, RoundingMode.DOWN));
      order.setRefundAmount(refundAmount.setScale(2, RoundingMode.DOWN));
@@ -2076,8 +2074,8 @@
            BigDecimal periodServicePrice = chargingOrderAccountingStrategy.getPeriodServicePrice();
            BigDecimal multiply = couponDiscountAmount.multiply(periodServicePrice.divide(reduce, new MathContext(4, RoundingMode.HALF_EVEN)));
            periodServicePrice = periodServicePrice.subtract(multiply);
            chargingOrderAccountingStrategy.setPeriodServicePrice(periodServicePrice.setScale(2, RoundingMode.DOWN));
            chargingOrderAccountingStrategy.setCouponDiscountAmount(multiply.setScale(2, RoundingMode.DOWN));
            chargingOrderAccountingStrategy.setPeriodServicePrice(periodServicePrice.setScale(2, RoundingMode.HALF_EVEN));
            chargingOrderAccountingStrategy.setCouponDiscountAmount(multiply.setScale(2, RoundingMode.HALF_EVEN));
         }
         chargingOrderAccountingStrategyService.updateBatchById(list);
      }