diff --git a/src/main/java/com/sczx/order/service/impl/OrderDistribServiceImpl.java b/src/main/java/com/sczx/order/service/impl/OrderDistribServiceImpl.java index b1cc92d..3a9ae79 100644 --- a/src/main/java/com/sczx/order/service/impl/OrderDistribServiceImpl.java +++ b/src/main/java/com/sczx/order/service/impl/OrderDistribServiceImpl.java @@ -103,7 +103,7 @@ public class OrderDistribServiceImpl implements OrderDistribService { addOrderDistribPOList.add(referralDistribPO); } } - BigDecimal alreadyShareRate = addOrderDistribPOList.stream().map(OrderDistribPO::getDistribRate).reduce(BigDecimal::add).orElse(BigDecimal.ZERO); + BigDecimal alreadyShareRate = addOrderDistribPOList.stream().map(OrderDistribPO::getDistribRate).reduce(BigDecimal.ZERO,BigDecimal::add); //运营商分润 String companyRate = String.valueOf(BigDecimal.ONE.subtract(alreadyShareRate).multiply(BigDecimal.valueOf(100))); OrderDistribPO companyDistribPO = getOrderDistribPO(orderMainPO.getOrderId(),orderMainPO.getOrderNo(),DistribTypeEnum.COMPANY.getCode(),companyRate,orderMainPO.getOrderAmount(),Integer.valueOf(orderMainPO.getOperatorId().toString()),Integer.valueOf(orderMainPO.getStoreId().toString()),null); diff --git a/src/main/java/com/sczx/order/service/impl/OrderServiceImpl.java b/src/main/java/com/sczx/order/service/impl/OrderServiceImpl.java index 55ac555..4e25874 100644 --- a/src/main/java/com/sczx/order/service/impl/OrderServiceImpl.java +++ b/src/main/java/com/sczx/order/service/impl/OrderServiceImpl.java @@ -255,6 +255,18 @@ public class OrderServiceImpl implements OrderService { if(orderMainPO == null){ throw new BizException("订单不存在"); } + if(OrderStatusEnum.RERENT_WAIT_PAY.getCode().equals(orderMainPO.getOrderStatus())){ + //已经是待支付状态的,直接拉起支付 + PayOrderReq payOrderReq = new PayOrderReq(); + payOrderReq.setOrderNo(rentCarOrderReq.getOrderNo()); + UnifiedPaymentInfoDTO unifiedPaymentInfoDTO = payOrder(payOrderReq); + + OrderDTO orderDTO = getOrderInfoByOrderNo(rentCarOrderReq.getOrderNo()); + RentCarOrderResultDTO rentCarOrderResultDTO = new RentCarOrderResultDTO(); + rentCarOrderResultDTO.setOrderMainInfo(orderDTO); + rentCarOrderResultDTO.setUnifiedPaymentInfo(unifiedPaymentInfoDTO); + return rentCarOrderResultDTO; + } if(!OrderStatusEnum.RENT_ING.getCode().equals(orderMainPO.getOrderStatus()) && !OrderStatusEnum.RENT_OVERDUE.getCode().equals(orderMainPO.getOrderStatus())){ throw new BizException("订单非租赁或逾期状态,不能续租"); } @@ -445,6 +457,18 @@ public class OrderServiceImpl implements OrderService { if(orderMainPO == null){ throw new BizException("订单不存在"); } + if(OrderStatusEnum.RERENT_WAIT_PAY.getCode().equals(orderMainPO.getOrderStatus())){ + //已经是待支付状态的,直接拉起支付 + PayOrderReq payOrderReq = new PayOrderReq(); + payOrderReq.setOrderNo(rentCarOrderReq.getOrderNo()); + UnifiedPaymentInfoDTO unifiedPaymentInfoDTO = payOrder(payOrderReq); + + OrderDTO orderDTO = getOrderInfoByOrderNo(rentCarOrderReq.getOrderNo()); + RentCarOrderResultDTO rentCarOrderResultDTO = new RentCarOrderResultDTO(); + rentCarOrderResultDTO.setOrderMainInfo(orderDTO); + rentCarOrderResultDTO.setUnifiedPaymentInfo(unifiedPaymentInfoDTO); + return rentCarOrderResultDTO; + } if(!OrderStatusEnum.RENT_OVERDUE.getCode().equals(orderMainPO.getOrderStatus())){ throw new BizException("订单非逾期状态,不能逾期处理"); } @@ -673,7 +697,7 @@ public class OrderServiceImpl implements OrderService { if(OrderStatusEnum.WAIT_PAY.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())){ orderDetailDTO.setWaitPayAmount(orderMainPO.getOrderAmount()); }else { - orderDetailDTO.setWaitPayAmount(orderSubList.stream().map(OrderSubPO::getAmount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO)); + orderDetailDTO.setWaitPayAmount(orderSubList.stream().map(OrderSubPO::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add)); } if(!CollectionUtils.isEmpty(orderSubList)){ //如果是微信支付,则去微信查询支付状态,如果支付成功,则修改订单状态为支付成功 @@ -1115,7 +1139,7 @@ public class OrderServiceImpl implements OrderService { updateWrapper2.set(OrderMainPO::getOrderStatus, OrderStatusEnum.WAIT_PICK.getCode()); orderStatus = OrderStatusEnum.WAIT_PICK.getCode(); } else if(OrderStatusEnum.RERENT_WAIT_PAY.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())){ - BigDecimal rentCarOrderAmount = orderSubList.stream().map(OrderSubPO::getAmount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO); + BigDecimal rentCarOrderAmount = orderSubList.stream().map(OrderSubPO::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add); updateWrapper2.set(OrderMainPO::getOrderAmount, orderMainPO.getOrderAmount().add(rentCarOrderAmount)); if(rentSubPO!=null){ updateWrapper2.set(OrderMainPO::getEndRentTime, rentSubPO.getReturnTime()); @@ -1143,15 +1167,15 @@ public class OrderServiceImpl implements OrderService { * @return */ private static BigDecimal getRentCarAmount(String rentalType, BigDecimal rentalPrice, Integer rentalDays) { - BigDecimal rentCarOrderAmount = new BigDecimal(0); - if(RentCarTypeEnum.HOUR_RENTAL.getCode().equalsIgnoreCase(rentalType)||RentCarTypeEnum.DAILY_RENTAL.getCode().equalsIgnoreCase(rentalType)){ - rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice); - } else if(RentCarTypeEnum.DAYS_RENTAL.getCode().equalsIgnoreCase(rentalType)){ - rentCarOrderAmount = rentalPrice.multiply(new BigDecimal(rentalDays)); - } else { - rentCarOrderAmount = rentalPrice.multiply(new BigDecimal(30)); - } - return rentCarOrderAmount; +// BigDecimal rentCarOrderAmount = new BigDecimal(0); +// if(RentCarTypeEnum.HOUR_RENTAL.getCode().equalsIgnoreCase(rentalType)||RentCarTypeEnum.DAILY_RENTAL.getCode().equalsIgnoreCase(rentalType)){ +// rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice); +// } else if(RentCarTypeEnum.DAYS_RENTAL.getCode().equalsIgnoreCase(rentalType)){ +// rentCarOrderAmount = rentalPrice.multiply(new BigDecimal(rentalDays)); +// } else { +// rentCarOrderAmount = rentalPrice.multiply(new BigDecimal(30)); +// } + return rentalPrice; } /** @@ -1164,21 +1188,21 @@ public class OrderServiceImpl implements OrderService { */ private static BigDecimal getReRentCarAmount(LocalDateTime endRentTime,String rentalType, BigDecimal rentalPrice, Integer ruleRentalDays) { //计算续租金额 - BigDecimal rentCarOrderAmount = new BigDecimal(0); - if(RentCarTypeEnum.HOUR_RENTAL.getCode().equalsIgnoreCase(rentalType)){ - Integer overdueHours = OrderUtil.getOrderOverdueHours(endRentTime); - rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(overdueHours+1))); - } else if(RentCarTypeEnum.DAILY_RENTAL.getCode().equalsIgnoreCase(rentalType)){ - Integer rentalDays = OrderUtil.getOrderOverdueDays(endRentTime); - rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(rentalDays+1))); - } else if(RentCarTypeEnum.DAYS_RENTAL.getCode().equalsIgnoreCase(rentalType)){ - Integer rentalDays = OrderUtil.getOrderOverdueDays(endRentTime); - rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(rentalDays+ruleRentalDays))); - } else { - Integer rentalDays = OrderUtil.getOrderOverdueDays(endRentTime); - rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(rentalDays+30))); - } - return rentCarOrderAmount; +// BigDecimal rentCarOrderAmount = new BigDecimal(0); +// if(RentCarTypeEnum.HOUR_RENTAL.getCode().equalsIgnoreCase(rentalType)){ +// Integer overdueHours = OrderUtil.getOrderOverdueHours(endRentTime); +// rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(overdueHours+1))); +// } else if(RentCarTypeEnum.DAILY_RENTAL.getCode().equalsIgnoreCase(rentalType)){ +// Integer rentalDays = OrderUtil.getOrderOverdueDays(endRentTime); +// rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(rentalDays+1))); +// } else if(RentCarTypeEnum.DAYS_RENTAL.getCode().equalsIgnoreCase(rentalType)){ +// Integer rentalDays = OrderUtil.getOrderOverdueDays(endRentTime); +// rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(rentalDays+ruleRentalDays))); +// } else { +// Integer rentalDays = OrderUtil.getOrderOverdueDays(endRentTime); +// rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(rentalDays+30))); +// } + return rentalPrice; } } diff --git a/src/main/java/com/sczx/order/task/NoPayOrderProcessTask.java b/src/main/java/com/sczx/order/task/NoPayOrderProcessTask.java index e6abf3e..f1c1d4e 100644 --- a/src/main/java/com/sczx/order/task/NoPayOrderProcessTask.java +++ b/src/main/java/com/sczx/order/task/NoPayOrderProcessTask.java @@ -36,7 +36,7 @@ public class NoPayOrderProcessTask { private PayInteg payInteg; /** - * 每30分钟检查一次逾期订单 + * 每6分钟检查一次逾期订单 * 使用ShedLock确保在分布式环境下只有一个实例执行 * 分布式锁机制:ShedLock使用Redis作为锁存储,确保同一时间只有一个服务实例执行定时任务 * 任务名称:@SchedulerLock 注解中的 name 属性标识任务名称,相同名称的任务在分布式环境下互斥执行 @@ -45,7 +45,7 @@ public class NoPayOrderProcessTask { * lockAtLeastFor:锁最少持有时间,防止任务执行过快导致频繁执行 */ @Transactional(rollbackFor = Exception.class) - @Scheduled(cron = "0 */15 * * * ?") + @Scheduled(cron = "0 */6 * * * ?") @SchedulerLock(name = "checkNoPayOrders", lockAtMostFor = "9m", lockAtLeastFor = "1m") public void checkNoPayOrders() { log.info("开始执行未支付订单检查任务"); @@ -66,7 +66,7 @@ public class NoPayOrderProcessTask { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(OrderMainPO::getDelFlag, "0").in(OrderMainPO::getOrderStatus, Arrays.asList(OrderStatusEnum.WAIT_PAY.getCode(), OrderStatusEnum.RERENT_WAIT_PAY.getCode())) - .lt(OrderMainPO::getUpdateTime, LocalDateTime.now().minusHours(1)); + .lt(OrderMainPO::getUpdateTime, LocalDateTime.now().minusMinutes(5)); List orders = orderMainRepo.list(queryWrapper);