From 0132ff3faf4d27f6b99af37f8ea8cb9520b1622f Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期二, 05 十一月 2024 19:07:11 +0800 Subject: [PATCH] 合并代码 --- ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java | 77 +++++++++++++++++++------------------- 1 files changed, 38 insertions(+), 39 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 be08b4b..14bf85d 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 @@ -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("充电充值"); @@ -1919,26 +1919,26 @@ } //已充电总度数 - BigDecimal electrovalenc = strategyDetail.getElectrovalence().multiply(sharp_peak_charge).setScale(2, RoundingMode.DOWN); - BigDecimal originalServicePrice = strategyDetail.getServiceCharge().multiply(sharp_peak_charge).setScale(2, RoundingMode.DOWN); + BigDecimal electrovalenc = strategyDetail.getElectrovalence().multiply(sharp_peak_charge).setScale(2, RoundingMode.HALF_EVEN); + BigDecimal originalServicePrice = strategyDetail.getServiceCharge().multiply(sharp_peak_charge).setScale(2, RoundingMode.HALF_EVEN); BigDecimal serviceCharge = originalServicePrice; BigDecimal vipDiscountAmount = BigDecimal.ZERO; //计算优惠金额 if(null != chargingOrder.getVipDiscount()){ - vipDiscountAmount = serviceCharge.multiply(new BigDecimal(1).subtract(chargingOrder.getVipDiscount())).setScale(2, RoundingMode.DOWN); - serviceCharge = serviceCharge.multiply(chargingOrder.getVipDiscount()).setScale(2, RoundingMode.DOWN); + vipDiscountAmount = serviceCharge.multiply(new BigDecimal(1).subtract(chargingOrder.getVipDiscount())).setScale(2, RoundingMode.HALF_EVEN); + serviceCharge = serviceCharge.multiply(chargingOrder.getVipDiscount()).setScale(2, RoundingMode.HALF_EVEN); } chargingOrderAccountingStrategy.setChargingCapacity(sharp_peak_charge); - chargingOrderAccountingStrategy.setPeriodElectricPrice(electrovalenc.setScale(2, RoundingMode.DOWN)); - chargingOrderAccountingStrategy.setPeriodServicePrice(serviceCharge.setScale(2, RoundingMode.DOWN)); - chargingOrderAccountingStrategy.setPeriodOriginalServicePrice(originalServicePrice.setScale(2, RoundingMode.DOWN)); - chargingOrderAccountingStrategy.setVipDiscountAmount(vipDiscountAmount.setScale(2, RoundingMode.DOWN)); + chargingOrderAccountingStrategy.setPeriodElectricPrice(electrovalenc); + chargingOrderAccountingStrategy.setPeriodServicePrice(serviceCharge); + chargingOrderAccountingStrategy.setPeriodOriginalServicePrice(originalServicePrice); + chargingOrderAccountingStrategy.setVipDiscountAmount(vipDiscountAmount); chargingOrderAccountingStrategy.setCreateTime(LocalDateTime.now()); chargingOrderAccountingStrategyService.save(chargingOrderAccountingStrategy); - periodElectricPrice_total = periodElectricPrice_total.add(electrovalenc.setScale(2, RoundingMode.DOWN)); - periodServicePrice_total = periodServicePrice_total.add(originalServicePrice.setScale(2, RoundingMode.DOWN)); - total = total.add(electrovalenc.add(originalServicePrice.setScale(2, RoundingMode.DOWN))); + periodElectricPrice_total = periodElectricPrice_total.add(electrovalenc); + periodServicePrice_total = periodServicePrice_total.add(originalServicePrice); + total = total.add(electrovalenc.add(originalServicePrice)); } @@ -1949,6 +1949,7 @@ //总金额(充值金额+会员折扣金额) BigDecimal decimal = rechargeAmount.add(vipDiscountAmount); //退款金额(已经计算了折扣优惠部分) + //如果充电总金额未使用完,则需要退回费用=(原金额/总金额)*(总金额-实际充电金额) BigDecimal refundAmount = rechargeAmount.divide(decimal, new MathContext(4, RoundingMode.HALF_EVEN)).multiply(decimal.subtract(total)); BigDecimal orderAmount = BigDecimal.valueOf(total.doubleValue()); BigDecimal payAmount = BigDecimal.valueOf(total.doubleValue()); @@ -1967,8 +1968,6 @@ //服务费折扣 discountAmount = periodServicePrice_total.multiply((new BigDecimal(1).subtract(chargingOrder.getVipDiscount()))); - periodServicePrice_total = periodServicePrice_total.multiply(chargingOrder.getVipDiscount()); - TVip vip = vipClient.getInfo1(appUser.getVipId()).getData(); BigDecimal maximumDeduction = vip.getMaximumDeduction(); //普通会员有最高优惠限制 @@ -1977,7 +1976,10 @@ } } } + //会员折扣金额 + discountAmount = discountAmount.setScale(2, RoundingMode.HALF_EVEN); payAmount = payAmount.subtract(discountAmount); + periodServicePrice_total = periodServicePrice_total.subtract(discountAmount); TChargingOrder order = new TChargingOrder(); order.setId(chargingOrder.getId()); @@ -1989,17 +1991,18 @@ }else{ order.setEndMode(1); } - order.setResidualAmount(rechargeAmount.subtract(total).setScale(2, RoundingMode.DOWN)); + order.setResidualAmount(rechargeAmount.subtract(total).setScale(2, RoundingMode.HALF_EVEN)); order.setStartTime(LocalDateTime.parse(vo.getStart_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SS"))); 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.setElectrovalence(periodElectricPrice_total.setScale(2, RoundingMode.DOWN)); + order.setOrderAmount(orderAmount.setScale(2, RoundingMode.HALF_EVEN)); + order.setVipDiscountAmount(discountAmount); + order.setElectrovalence(periodElectricPrice_total.setScale(2, RoundingMode.HALF_EVEN)); 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,11 @@ 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); - periodServicePrice_total = periodServicePrice_total.subtract(couponDiscountAmount); + couponDiscount = couponDiscountAmount; } - appCoupon.setStatus(2); appCouponClient.updateAppCoupon(appCoupon); }else{ @@ -2039,15 +2036,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); - periodServicePrice_total = periodServicePrice_total.subtract(divide); + couponDiscount = divide; } appCoupon.setStatus(2); @@ -2059,10 +2051,17 @@ } } } - - order.setServiceCharge(periodServicePrice_total.setScale(2, RoundingMode.DOWN)); - order.setPaymentAmount(payAmount.setScale(2, RoundingMode.DOWN)); - order.setRefundAmount(refundAmount.setScale(2, RoundingMode.DOWN)); + //优惠券优惠金额 + couponDiscount = couponDiscount.setScale(2, RoundingMode.HALF_EVEN); + refundAmount = refundAmount.add(couponDiscount); + payAmount = payAmount.subtract(couponDiscount); + if(periodServicePrice_total.compareTo(BigDecimal.ZERO) > 0){ + periodServicePrice_total = periodServicePrice_total.subtract(couponDiscount); + } + order.setCouponDiscountAmount(couponDiscount); + order.setServiceCharge(periodServicePrice_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); this.updateById(order); chargingOrder = this.getById(order.getId()); @@ -2076,8 +2075,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); } -- Gitblit v1.7.1