| | |
| | | total = total.add(electrovalenc.add(originalServicePrice)); |
| | | } |
| | | |
| | | BigDecimal orderAmount = BigDecimal.valueOf(total.doubleValue()); |
| | | //折扣金额 |
| | | BigDecimal discountAmount = chargingOrder.getVipDiscountAmount(); |
| | | //原金额 |
| | | BigDecimal rechargeAmount = chargingOrder.getRechargeAmount(); |
| | | BigDecimal vipDiscountAmount = chargingOrder.getVipDiscountAmount(); |
| | | //总金额(充值金额+会员折扣金额) |
| | | BigDecimal decimal = rechargeAmount.add(vipDiscountAmount); |
| | | BigDecimal decimal = rechargeAmount.add(discountAmount); |
| | | //退款金额(已经计算了折扣优惠部分) |
| | | //如果充电总金额未使用完,则需要退回费用=(原金额/总金额)*(总金额-实际充电金额) |
| | | 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()); |
| | | //折扣金额 |
| | | BigDecimal discountAmount = BigDecimal.ZERO; |
| | | if(null != chargingOrder.getVipDiscount()){ |
| | | TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData(); |
| | | //判断会员是否还有充电优惠次数 |
| | | GetAppUserVipDetail getAppUserVipDetail = new GetAppUserVipDetail(); |
| | | getAppUserVipDetail.setAppUserId(chargingOrder.getAppUserId()); |
| | | getAppUserVipDetail.setVipId(appUser.getVipId()); |
| | | TAppUserVipDetail data = appUserVipDetailClient.getAppUserVipDetail(getAppUserVipDetail).getData(); |
| | | if(null != data && data.getChargeNum() > 0){ |
| | | data.setChargeNum(data.getChargeNum() - 1); |
| | | appUserVipDetailClient.updateAppUserVipDetail(data); |
| | | |
| | | //服务费折扣 |
| | | discountAmount = periodServicePrice_total.multiply((new BigDecimal(1).subtract(chargingOrder.getVipDiscount()))); |
| | | TVip vip = vipClient.getInfo1(appUser.getVipId()).getData(); |
| | | BigDecimal maximumDeduction = vip.getMaximumDeduction(); |
| | | //普通会员有最高优惠限制 |
| | | if(vip.getType() == 1 && discountAmount.compareTo(maximumDeduction) > 0){ |
| | | discountAmount = maximumDeduction; |
| | | } |
| | | } |
| | | } |
| | | //会员折扣金额 |
| | | discountAmount = discountAmount.setScale(4, RoundingMode.HALF_EVEN); |
| | | payAmount = payAmount.subtract(discountAmount); |
| | | //支付金额 |
| | | BigDecimal payAmount = rechargeAmount.subtract(refundAmount); |
| | | //实际充值服务费-会员折扣 |
| | | periodServicePrice_total = periodServicePrice_total.subtract(discountAmount); |
| | | |
| | | TChargingOrder order = new TChargingOrder(); |
| | |
| | | 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.HALF_EVEN)); |
| | | order.setVipDiscountAmount(discountAmount.setScale(2, RoundingMode.HALF_EVEN)); |
| | | 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.setVipDiscount(BigDecimal.valueOf(1)); |
| | | } |
| | | |
| | | //计算优惠券 |
| | | BigDecimal couponDiscount = BigDecimal.ZERO; |
| | |
| | | } |
| | | //优惠券优惠金额 |
| | | couponDiscount = couponDiscount.setScale(4, RoundingMode.HALF_EVEN); |
| | | //退款金额+优惠券 |
| | | refundAmount = refundAmount.add(couponDiscount); |
| | | //实际支付金额-优惠券 |
| | | payAmount = payAmount.subtract(couponDiscount); |
| | | if(periodServicePrice_total.compareTo(BigDecimal.ZERO) > 0){ |
| | | periodServicePrice_total = periodServicePrice_total.subtract(couponDiscount); |
| | |
| | | |
| | | @Test |
| | | public void test(){ |
| | | MyChargingOrderInfo myChargingOrderInfo = chargingOrderService.getMyChargingOrderInfo("1852288949187297282"); |
| | | // TransactionRecordMessageVO vo = JSON.parseObject("{\n" + |
| | | // "\t\"charging_gun_code\": \"02\",\n" + |
| | | // "\t\"charging_pile_code\": \"2024123100001003\",\n" + |
| | | // "\t\"end_time\": \"2025-02-12 00:32:18.00\",\n" + |
| | | // "\t\"flat_amount2\": 0.000000,\n" + |
| | | // "\t\"flat_amount4\": 0.000000,\n" + |
| | | // "\t\"flat_amount6\": 0.000000,\n" + |
| | | // "\t\"flat_charge2\": 0.000000,\n" + |
| | | // "\t\"flat_charge4\": 0.000000,\n" + |
| | | // "\t\"flat_charge6\": 0.000000,\n" + |
| | | // "\t\"loss_peak_charge3\": 0,\n" + |
| | | // "\t\"loss_peak_charge5\": 0,\n" + |
| | | // "\t\"loss_total_electricity\": 0,\n" + |
| | | // "\t\"loss_valley_charge1\": 0,\n" + |
| | | // "\t\"loss_valley_charge7\": 0,\n" + |
| | | // "\t\"payment_amount\": 41.650000,\n" + |
| | | // "\t\"peak_amount3\": 0.000000,\n" + |
| | | // "\t\"peak_amount5\": 0.000000,\n" + |
| | | // "\t\"peak_charge3\": 0.000000,\n" + |
| | | // "\t\"peak_charge5\": 0.000000,\n" + |
| | | // "\t\"physical_card_number\": \"1234567812345678\",\n" + |
| | | // "\t\"result\": \"{\\\"service_id\\\":\\\"transaction_record\\\",\\\"transaction_serial_number\\\":\\\"CD69120250211231439794\\\",\\\"charging_pile_code\\\":\\\"2024123100001003\\\",\\\"charging_gun_code\\\":\\\"02\\\",\\\"start_time\\\":\\\"2025-02-11 23:14:46.00\\\",\\\"end_time\\\":\\\"2025-02-12 00:32:18.00\\\",\\\"valley_charge1\\\":\\\"16.516000\\\",\\\"loss_valley_charge1\\\":\\\"0\\\",\\\"valley_amount1\\\":\\\"12.380000\\\",\\\"flat_charge2\\\":\\\"0.000000\\\",\\\"loss_flat_charg2\\\":\\\"0\\\",\\\"flat_amount2\\\":\\\"0.000000\\\",\\\"peak_charge3\\\":\\\"0.000000\\\",\\\"loss_peak_charge3\\\":\\\"0\\\",\\\"peak_amount3\\\":\\\"0.000000\\\",\\\"flat_charge4\\\":\\\"0.000000\\\",\\\"loss_flat_charg4\\\":\\\"0\\\",\\\"flat_amount4\\\":\\\"0.000000\\\",\\\"peak_charge5\\\":\\\"0.000000\\\",\\\"loss_peak_charge5\\\":\\\"0\\\",\\\"peak_amount5\\\":\\\"0.000000\\\",\\\"flat_charge6\\\":\\\"0.000000\\\",\\\"loss_flat_charg6\\\":\\\"0\\\",\\\"flat_amount6\\\":\\\"0.000000\\\",\\\"valley_charge7\\\":\\\"39.045000\\\",\\\"loss_valley_charge7\\\":\\\"0\\\",\\\"valley_amount7\\\":\\\"29.270000\\\",\\\"total_electricity\\\":\\\"55.561001\\\",\\\"loss_total_electricity\\\":\\\"0\\\",\\\"payment_amount\\\":\\\"41.650000\\\",\\\"trade_date\\\":\\\"0\\\",\\\"stop_reason\\\":\\\"1\\\",\\\"physical_card_number\\\":\\\"1234567812345678\\\"}\",\n" + |
| | | // "\t\"retryTimes\": 0,\n" + |
| | | // "\t\"sendTime\": 1739291543546,\n" + |
| | | // "\t\"serviceId\": \"transaction_record\",\n" + |
| | | // "\t\"source\": \"\",\n" + |
| | | // "\t\"start_time\": \"2025-02-11 23:14:46.00\",\n" + |
| | | // "\t\"stop_reason\": 1,\n" + |
| | | // "\t\"total_electricity\": 55.561001,\n" + |
| | | // "\t\"trade_date\": \"0\",\n" + |
| | | // "\t\"transaction_serial_number\": \"CD69120250211231439794\",\n" + |
| | | // "\t\"valley_amount1\": 12.380000,\n" + |
| | | // "\t\"valley_amount7\": 29.270000,\n" + |
| | | // "\t\"valley_charge1\": 16.516000,\n" + |
| | | // "\t\"valley_charge7\": 39.045000\n" + |
| | | // "}", TransactionRecordMessageVO.class); |
| | | // chargingOrderService.endChargeBillingCharge(vo); |
| | | } |
| | | } |