Pu Zhibing
2025-03-06 1b81b84edaeea9b200c622e4a34c49b4b1aaac92
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
@@ -648,21 +648,19 @@
                  long times = rechargeAmount1.divide(s_total_amount, 0, RoundingMode.DOWN).longValue();
                  if(times > m){
                     //充电时间跨度两个计费策略,需要继续对下一个策略进行计算
                     serviceCharge = s_server_amount.multiply(new BigDecimal(m));
                     serviceCharge = serviceCharge.add(s_server_amount.multiply(new BigDecimal(m)));
                     rechargeAmount1 = rechargeAmount1.subtract(s_total_amount.multiply(new BigDecimal(m)));
                     if(null != discount){
                        discountAmount = discountAmount.add(serviceCharge.multiply(new BigDecimal(1).subtract(discount)));
                     }
                     nowTimeMillis = null;
                  }else{
                     serviceCharge = s_server_amount.multiply(new BigDecimal(times));
                     if(null != discount){
                        discountAmount = discountAmount.add(serviceCharge.multiply(new BigDecimal(1).subtract(discount)));
                     }
                     serviceCharge = serviceCharge.add(s_server_amount.multiply(new BigDecimal(times)));
                     break;
                  }
               }
            }
            if(null != discount){
               discountAmount = serviceCharge.multiply(new BigDecimal(1).subtract(discount));
            }
            if(discountAmount.compareTo(BigDecimal.ZERO) >= 0){
               //计算会员最大优惠金额
               TVip vip = vipClient.getInfo1(appUser.getVipId()).getData();
@@ -673,9 +671,12 @@
               }
            }
            discountAmount = discountAmount.setScale(4, RoundingMode.HALF_EVEN);
            if(discountAmount.compareTo(BigDecimal.ZERO) >= 0){
               data.setChargeNum(data.getChargeNum() - 1);
               appUserVipDetailClient.updateAppUserVipDetail(data);
         }
      }
      }
      
      //机子上显示的金额为用户充值的金额+会员折扣金额
      BigDecimal account_balance = chargingOrder.getRechargeAmount().add(discountAmount).setScale(4, RoundingMode.HALF_EVEN);
@@ -924,6 +925,18 @@
               BigDecimal refund_fee = new BigDecimal(null == refund_fee1 ? "0" : refund_fee1.toString()).divide(new BigDecimal(100));
               chargingOrderRefund.setRefundFee(refund_fee);
               chargingOrderRefundService.updateById(chargingOrderRefund);
               //回退会员折扣次数
               if(chargingOrder.getVipDiscountAmount().compareTo(BigDecimal.ZERO) > 0){
                  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.setChargeNum(data.getChargeNum() + 1);
                     appUserVipDetailClient.updateAppUserVipDetail(data);
                  }
               }
            }
         }
         if(2 == rechargePaymentType){
@@ -935,6 +948,19 @@
            RefundResp resp = aliPaymentClient.refund(dto).getData();
            if(null != resp){
               chargingOrderRefundService.save(chargingOrderRefund);
               //回退会员折扣次数
               if(chargingOrder.getVipDiscountAmount().compareTo(BigDecimal.ZERO) > 0){
                  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.setChargeNum(data.getChargeNum() + 1);
                     appUserVipDetailClient.updateAppUserVipDetail(data);
                  }
               }
               try {
                  Thread.sleep(1000);
               } catch (InterruptedException e) {
@@ -2075,10 +2101,10 @@
      if(null == chargingOrder){
         return R.ok();
      }
//      Integer status = chargingOrder.getStatus();
//      if(status == 5){
//         return R.ok();
//      }
      Integer status = chargingOrder.getStatus();
      if(status == 5){
         return R.ok();
      }
      
      //如果使用优惠券需要判断优惠券是否满足使用条件
      //根据实际的充电金额计算退款金额   退回费用=(原金额/总金额)*(总金额-实际充电金额)
@@ -3728,7 +3754,6 @@
      chargingOrder.setStatus(2);
      chargingOrder.setPayTime(LocalDateTime.now());
      chargingOrder.setChargeAmount(chargingOrder.getRechargeAmount());
      chargingOrder.setVipDiscountAmount(BigDecimal.ZERO);
      this.save(chargingOrder);
      
      Integer accountingStrategyId = tChargingGun.getAccountingStrategyId();