| | |
| | | |
| | | for (ChargingOrderVO chargingOrderVO : list1) { |
| | | List<TChargingOrderAccountingStrategy> list4 = list3.stream().filter(e -> e.getChargingOrderId().equals(chargingOrderVO.getId())).collect(Collectors.toList()); |
| | | BigDecimal electronic_reduce = list4.stream().map(TChargingOrderAccountingStrategy::getPeriodElectricPrice).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal service_reduce = list4.stream().map(TChargingOrderAccountingStrategy::getPeriodServicePrice).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | if (!chargingOrderVO.getOrderSource().equals(2)) { |
| | | paymentMoney = paymentMoney.add(chargingOrderVO.getPaymentAmount() != null ? chargingOrderVO.getPaymentAmount() : new BigDecimal("0")); |
| | | }else{ |
| | | paymentMoney = paymentMoney.add(service_reduce.multiply(new BigDecimal("0.8")).setScale(2, BigDecimal.ROUND_DOWN)); |
| | | paymentMoney = paymentMoney.add(electronic_reduce).add(service_reduce.multiply(new BigDecimal("0.8")).setScale(2, BigDecimal.ROUND_DOWN)); |
| | | } |
| | | if (chargingOrderVO.getRechargeAmount()!=null){ |
| | | commissionMoney = commissionMoney.add(chargingOrderVO.getRechargeAmount().multiply(new BigDecimal("0.006")).setScale(2,BigDecimal.ROUND_DOWN)); |
| | | } |
| | | // if (chargingOrderVO.getRechargeAmount()!=null){ |
| | | // commissionMoney = commissionMoney.add(chargingOrderVO.getRechargeAmount().multiply(new BigDecimal("0.006")).setScale(2,BigDecimal.ROUND_DOWN)); |
| | | // } |
| | | if (chargingOrderVO.getChargingCapacity()!=null){ |
| | | total = total.add(chargingOrderVO.getElectricity()!=null?chargingOrderVO.getElectricity():new BigDecimal("0")); |
| | | } |
| | |
| | | List<TChargingOrderRefund> list2 = chargingOrderRefunds.stream().filter(e -> e.getChargingOrderId() != null && e.getChargingOrderId().equals(chargingOrderVO.getId())) |
| | | .collect(Collectors.toList()); |
| | | for (TChargingOrderRefund tChargingOrderRefund : list2) { |
| | | refundMoney = refundMoney.add(tChargingOrderRefund.getRefundTotalAmount()); |
| | | refundMoney = refundMoney.add(tChargingOrderRefund.getRefundTotalAmount()); |
| | | } |
| | | |
| | | //充电明细 |
| | | BigDecimal electronic_reduce = list4.stream().map(TChargingOrderAccountingStrategy::getPeriodElectricPrice).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | electronicMoney = electronicMoney.add(electronic_reduce); |
| | | if (!chargingOrderVO.getOrderSource().equals(2)){ |
| | | serviceMoney = serviceMoney.add(service_reduce); |
| | |
| | | } |
| | | |
| | | //如果使用优惠券需要判断优惠券是否满足使用条件 |
| | | //根据实际的充电金额计算退款金额 退回费用=(原金额/总金额)*(总金额-实际充电金额) |
| | | //退款金额=优惠券金额+剩余充电金额 |
| | | BigDecimal periodElectricPrice_total = BigDecimal.ZERO; |
| | | BigDecimal periodServicePrice_total = BigDecimal.ZERO; |
| | | BigDecimal vipDiscountAmount_total = BigDecimal.ZERO; |
| | | BigDecimal serviceCharge_total = BigDecimal.ZERO; |
| | | BigDecimal total = BigDecimal.ZERO; |
| | | |
| | | //获取订单的计费策略 |
| | |
| | | chargingOrderAccountingStrategy.setVipDiscountAmount(vipDiscountAmount.setScale(4, RoundingMode.HALF_EVEN)); |
| | | chargingOrderAccountingStrategy.setCreateTime(LocalDateTime.now()); |
| | | chargingOrderAccountingStrategyService.save(chargingOrderAccountingStrategy); |
| | | |
| | | //电费 |
| | | periodElectricPrice_total = periodElectricPrice_total.add(electrovalenc); |
| | | //服务费(含折扣) |
| | | serviceCharge_total = serviceCharge_total.add(serviceCharge); |
| | | //服务费(不含折扣) |
| | | periodServicePrice_total = periodServicePrice_total.add(originalServicePrice); |
| | | //会员折扣优惠金额 |
| | | vipDiscountAmount_total = vipDiscountAmount_total.add(vipDiscountAmount); |
| | | //原始总金额(不含折扣) |
| | | total = total.add(electrovalenc.add(originalServicePrice)); |
| | | } |
| | | |
| | | BigDecimal orderAmount = BigDecimal.valueOf(total.doubleValue()); |
| | | //折扣金额 |
| | | BigDecimal discountAmount = chargingOrder.getVipDiscountAmount(); |
| | | //原金额 |
| | | BigDecimal rechargeAmount = chargingOrder.getRechargeAmount(); |
| | | //总金额(充值金额+会员折扣金额) |
| | | BigDecimal decimal = rechargeAmount.add(discountAmount); |
| | | //退款金额(已经计算了折扣优惠部分) |
| | | //如果充电总金额未使用完,则需要退回费用=(原金额/总金额)*(总金额-实际充电金额) |
| | | BigDecimal refundAmount = rechargeAmount.divide(decimal, new MathContext(4, RoundingMode.HALF_EVEN)).multiply(decimal.subtract(total)); |
| | | //支付金额 |
| | | BigDecimal payAmount = rechargeAmount.subtract(refundAmount); |
| | | //实际充值服务费-会员折扣 |
| | | periodServicePrice_total = periodServicePrice_total.subtract(discountAmount); |
| | | BigDecimal payAmount = periodElectricPrice_total.add(serviceCharge_total); |
| | | //退款金额=充值金额-实际支付金额 |
| | | BigDecimal refundAmount = rechargeAmount.subtract(payAmount); |
| | | |
| | | TChargingOrder order = new TChargingOrder(); |
| | | order.setId(chargingOrder.getId()); |
| | |
| | | order.setElectrovalence(periodElectricPrice_total.setScale(2, RoundingMode.HALF_EVEN)); |
| | | order.setChargingCapacity(vo.getTotal_electricity()); |
| | | order.setElectricity(vo.getTotal_electricity()); |
| | | if(discountAmount.compareTo(BigDecimal.ZERO) == 0){ |
| | | order.setVipDiscountAmount(vipDiscountAmount_total); |
| | | if(vipDiscountAmount_total.compareTo(BigDecimal.ZERO) == 0){ |
| | | order.setVipDiscount(BigDecimal.valueOf(1)); |
| | | } |
| | | |
| | |
| | | if(payAmount.compareTo(tCoupon.getMeetTheConditions()) >= 0){ |
| | | BigDecimal couponDiscountAmount = tCoupon.getDiscountAmount(); |
| | | //如果优惠金额大于服务费金额,以服务费作为最大限制 |
| | | if(periodServicePrice_total.compareTo(couponDiscountAmount) < 0){ |
| | | couponDiscount = periodServicePrice_total; |
| | | periodServicePrice_total = BigDecimal.ZERO; |
| | | if(serviceCharge_total.compareTo(couponDiscountAmount) < 0){ |
| | | couponDiscount = serviceCharge_total; |
| | | serviceCharge_total = BigDecimal.ZERO; |
| | | }else{ |
| | | couponDiscount = couponDiscountAmount; |
| | | } |
| | |
| | | BigDecimal divide = payAmount.multiply(new BigDecimal(10).subtract(tCoupon.getDiscount())).divide(new BigDecimal(10)); |
| | | divide = divide.compareTo(tCoupon.getMaximumDiscountAmount()) > 0 ? tCoupon.getMaximumDiscountAmount() : divide; |
| | | //如果优惠金额大于服务费金额,以服务费作为最大限制 |
| | | if(periodServicePrice_total.compareTo(divide) < 0){ |
| | | couponDiscount = periodServicePrice_total; |
| | | periodServicePrice_total = BigDecimal.ZERO; |
| | | if(serviceCharge_total.compareTo(divide) < 0){ |
| | | couponDiscount = serviceCharge_total; |
| | | serviceCharge_total = BigDecimal.ZERO; |
| | | }else{ |
| | | couponDiscount = divide; |
| | | } |
| | |
| | | refundAmount = refundAmount.add(couponDiscount); |
| | | //实际支付金额-优惠券 |
| | | payAmount = payAmount.subtract(couponDiscount); |
| | | if(periodServicePrice_total.compareTo(BigDecimal.ZERO) > 0){ |
| | | periodServicePrice_total = periodServicePrice_total.subtract(couponDiscount); |
| | | if(serviceCharge_total.compareTo(BigDecimal.ZERO) > 0){ |
| | | serviceCharge_total = serviceCharge_total.subtract(couponDiscount); |
| | | } |
| | | order.setCouponDiscountAmount(couponDiscount.setScale(2, RoundingMode.HALF_EVEN)); |
| | | order.setServiceCharge(periodServicePrice_total.setScale(2, RoundingMode.HALF_EVEN)); |
| | | order.setServiceCharge(serviceCharge_total.setScale(2, RoundingMode.HALF_EVEN)); |
| | | order.setPaymentAmount(payAmount.setScale(2, RoundingMode.HALF_EVEN)); |
| | | order.setRefundAmount(refundAmount.setScale(2, RoundingMode.HALF_EVEN)); |
| | | order.setRefundStatus(1); |