Pu Zhibing
2024-11-05 0d80fb942bdfdd25a224abf5c9d465f0fad1846c
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
@@ -524,7 +524,7 @@
      if(2 == addChargingOrder.getPaymentType()){
         AliPaymentReq req = new AliPaymentReq();
         req.setOutTradeNo(chargingOrder.getCode());
         req.setTotalAmount(chargingOrder.getPaymentAmount().toString());
         req.setTotalAmount(addChargingOrder.getPaymentAmount().toString());
         req.setSubject("充电充值");
         req.setBuyerOpenId(appUser.getAliOpenid());
         req.setBody("充电充值");
@@ -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);
      }
@@ -2591,12 +2589,12 @@
      // 三方交易手续费 三方收费*0.6%
      commissionAmount = sharingAmount.multiply(new BigDecimal("0.006"));
      // 订单手续费 订单支付金额 - 退款金额*0.6%
      orderCommission = paymentAmount.multiply(new BigDecimal("0.006").setScale(2,RoundingMode.HALF_DOWN));
      orderCommission = paymentAmount.multiply(new BigDecimal("0.006"));
      tSettlementConfirm.setSharingAmount(sharingAmount.setScale(2, RoundingMode.HALF_DOWN));
      tSettlementConfirm.setCommissionAmount(commissionAmount.setScale(2, RoundingMode.HALF_DOWN));
      tSettlementConfirm.setElectrovalence(electrovalence.setScale(2, RoundingMode.HALF_DOWN));
      tSettlementConfirm.setServiceCharge(serviceCharge.subtract(orderCommission).setScale(2, RoundingMode.HALF_DOWN));
      tSettlementConfirm.setOrderCommission(orderCommission);
      tSettlementConfirm.setOrderCommission(orderCommission.setScale(2,BigDecimal.ROUND_DOWN));
      tSettlementConfirm.setVipDiscount(vipDiscount);
      tSettlementConfirm.setCouponDiscount(couponDiscount);
      tSettlementConfirm.setSiteId(dto.getSiteId());
@@ -2734,7 +2732,7 @@
      BigDecimal beforeCost= new BigDecimal("0");
      // 上月利润合计
      BigDecimal beforeIncome= new BigDecimal("0");
      int i = 0;
      int i = 1;
      for (TSettlementConfirm tSettlementConfirm : list1) {
         tSettlementConfirm.setXuhao(i);
         tSettlementConfirm.setMetering(tSettlementConfirm.getSupplyElectronic());
@@ -2863,12 +2861,11 @@
               tSettlementConfirm.setTotalPercentage(bigDecimal1+"%");            }
            beforeCost = beforeCost.add(settlementConfirm.getCost());
            beforeIncome = beforeIncome.add(settlementConfirm.getIncome());
         }
         i++;
      }
      TSettlementConfirm tSettlementConfirm = new TSettlementConfirm();
      tSettlementConfirm.setMonth(parse.getMonthValue());
      tSettlementConfirm.setMeteringElectronic(meteringElectronic);
      tSettlementConfirm.setChargingElectronic(chargingElectronic);
      tSettlementConfirm.setLossElectronic(lossElectronic);