解决金额计算问题
This commit is contained in:
@ -103,7 +103,7 @@ public class OrderDistribServiceImpl implements OrderDistribService {
|
|||||||
addOrderDistribPOList.add(referralDistribPO);
|
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)));
|
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);
|
OrderDistribPO companyDistribPO = getOrderDistribPO(orderMainPO.getOrderId(),orderMainPO.getOrderNo(),DistribTypeEnum.COMPANY.getCode(),companyRate,orderMainPO.getOrderAmount(),Integer.valueOf(orderMainPO.getOperatorId().toString()),Integer.valueOf(orderMainPO.getStoreId().toString()),null);
|
||||||
|
|||||||
@ -255,6 +255,18 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
if(orderMainPO == null){
|
if(orderMainPO == null){
|
||||||
throw new BizException("订单不存在");
|
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())){
|
if(!OrderStatusEnum.RENT_ING.getCode().equals(orderMainPO.getOrderStatus()) && !OrderStatusEnum.RENT_OVERDUE.getCode().equals(orderMainPO.getOrderStatus())){
|
||||||
throw new BizException("订单非租赁或逾期状态,不能续租");
|
throw new BizException("订单非租赁或逾期状态,不能续租");
|
||||||
}
|
}
|
||||||
@ -445,6 +457,18 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
if(orderMainPO == null){
|
if(orderMainPO == null){
|
||||||
throw new BizException("订单不存在");
|
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())){
|
if(!OrderStatusEnum.RENT_OVERDUE.getCode().equals(orderMainPO.getOrderStatus())){
|
||||||
throw new BizException("订单非逾期状态,不能逾期处理");
|
throw new BizException("订单非逾期状态,不能逾期处理");
|
||||||
}
|
}
|
||||||
@ -673,7 +697,7 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
if(OrderStatusEnum.WAIT_PAY.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())){
|
if(OrderStatusEnum.WAIT_PAY.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())){
|
||||||
orderDetailDTO.setWaitPayAmount(orderMainPO.getOrderAmount());
|
orderDetailDTO.setWaitPayAmount(orderMainPO.getOrderAmount());
|
||||||
}else {
|
}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)){
|
if(!CollectionUtils.isEmpty(orderSubList)){
|
||||||
//如果是微信支付,则去微信查询支付状态,如果支付成功,则修改订单状态为支付成功
|
//如果是微信支付,则去微信查询支付状态,如果支付成功,则修改订单状态为支付成功
|
||||||
@ -1115,7 +1139,7 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
updateWrapper2.set(OrderMainPO::getOrderStatus, OrderStatusEnum.WAIT_PICK.getCode());
|
updateWrapper2.set(OrderMainPO::getOrderStatus, OrderStatusEnum.WAIT_PICK.getCode());
|
||||||
orderStatus = OrderStatusEnum.WAIT_PICK.getCode();
|
orderStatus = OrderStatusEnum.WAIT_PICK.getCode();
|
||||||
} else if(OrderStatusEnum.RERENT_WAIT_PAY.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())){
|
} 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));
|
updateWrapper2.set(OrderMainPO::getOrderAmount, orderMainPO.getOrderAmount().add(rentCarOrderAmount));
|
||||||
if(rentSubPO!=null){
|
if(rentSubPO!=null){
|
||||||
updateWrapper2.set(OrderMainPO::getEndRentTime, rentSubPO.getReturnTime());
|
updateWrapper2.set(OrderMainPO::getEndRentTime, rentSubPO.getReturnTime());
|
||||||
@ -1143,15 +1167,15 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static BigDecimal getRentCarAmount(String rentalType, BigDecimal rentalPrice, Integer rentalDays) {
|
private static BigDecimal getRentCarAmount(String rentalType, BigDecimal rentalPrice, Integer rentalDays) {
|
||||||
BigDecimal rentCarOrderAmount = new BigDecimal(0);
|
// BigDecimal rentCarOrderAmount = new BigDecimal(0);
|
||||||
if(RentCarTypeEnum.HOUR_RENTAL.getCode().equalsIgnoreCase(rentalType)||RentCarTypeEnum.DAILY_RENTAL.getCode().equalsIgnoreCase(rentalType)){
|
// if(RentCarTypeEnum.HOUR_RENTAL.getCode().equalsIgnoreCase(rentalType)||RentCarTypeEnum.DAILY_RENTAL.getCode().equalsIgnoreCase(rentalType)){
|
||||||
rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice);
|
// rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice);
|
||||||
} else if(RentCarTypeEnum.DAYS_RENTAL.getCode().equalsIgnoreCase(rentalType)){
|
// } else if(RentCarTypeEnum.DAYS_RENTAL.getCode().equalsIgnoreCase(rentalType)){
|
||||||
rentCarOrderAmount = rentalPrice.multiply(new BigDecimal(rentalDays));
|
// rentCarOrderAmount = rentalPrice.multiply(new BigDecimal(rentalDays));
|
||||||
} else {
|
// } else {
|
||||||
rentCarOrderAmount = rentalPrice.multiply(new BigDecimal(30));
|
// rentCarOrderAmount = rentalPrice.multiply(new BigDecimal(30));
|
||||||
}
|
// }
|
||||||
return rentCarOrderAmount;
|
return rentalPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1164,21 +1188,21 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
*/
|
*/
|
||||||
private static BigDecimal getReRentCarAmount(LocalDateTime endRentTime,String rentalType, BigDecimal rentalPrice, Integer ruleRentalDays) {
|
private static BigDecimal getReRentCarAmount(LocalDateTime endRentTime,String rentalType, BigDecimal rentalPrice, Integer ruleRentalDays) {
|
||||||
//计算续租金额
|
//计算续租金额
|
||||||
BigDecimal rentCarOrderAmount = new BigDecimal(0);
|
// BigDecimal rentCarOrderAmount = new BigDecimal(0);
|
||||||
if(RentCarTypeEnum.HOUR_RENTAL.getCode().equalsIgnoreCase(rentalType)){
|
// if(RentCarTypeEnum.HOUR_RENTAL.getCode().equalsIgnoreCase(rentalType)){
|
||||||
Integer overdueHours = OrderUtil.getOrderOverdueHours(endRentTime);
|
// Integer overdueHours = OrderUtil.getOrderOverdueHours(endRentTime);
|
||||||
rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(overdueHours+1)));
|
// rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(overdueHours+1)));
|
||||||
} else if(RentCarTypeEnum.DAILY_RENTAL.getCode().equalsIgnoreCase(rentalType)){
|
// } else if(RentCarTypeEnum.DAILY_RENTAL.getCode().equalsIgnoreCase(rentalType)){
|
||||||
Integer rentalDays = OrderUtil.getOrderOverdueDays(endRentTime);
|
// Integer rentalDays = OrderUtil.getOrderOverdueDays(endRentTime);
|
||||||
rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(rentalDays+1)));
|
// rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(rentalDays+1)));
|
||||||
} else if(RentCarTypeEnum.DAYS_RENTAL.getCode().equalsIgnoreCase(rentalType)){
|
// } else if(RentCarTypeEnum.DAYS_RENTAL.getCode().equalsIgnoreCase(rentalType)){
|
||||||
Integer rentalDays = OrderUtil.getOrderOverdueDays(endRentTime);
|
// Integer rentalDays = OrderUtil.getOrderOverdueDays(endRentTime);
|
||||||
rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(rentalDays+ruleRentalDays)));
|
// rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(rentalDays+ruleRentalDays)));
|
||||||
} else {
|
// } else {
|
||||||
Integer rentalDays = OrderUtil.getOrderOverdueDays(endRentTime);
|
// Integer rentalDays = OrderUtil.getOrderOverdueDays(endRentTime);
|
||||||
rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(rentalDays+30)));
|
// rentCarOrderAmount = rentCarOrderAmount.add(rentalPrice.multiply(new BigDecimal(rentalDays+30)));
|
||||||
}
|
// }
|
||||||
return rentCarOrderAmount;
|
return rentalPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,7 +36,7 @@ public class NoPayOrderProcessTask {
|
|||||||
private PayInteg payInteg;
|
private PayInteg payInteg;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 每30分钟检查一次逾期订单
|
* 每6分钟检查一次逾期订单
|
||||||
* 使用ShedLock确保在分布式环境下只有一个实例执行
|
* 使用ShedLock确保在分布式环境下只有一个实例执行
|
||||||
* 分布式锁机制:ShedLock使用Redis作为锁存储,确保同一时间只有一个服务实例执行定时任务
|
* 分布式锁机制:ShedLock使用Redis作为锁存储,确保同一时间只有一个服务实例执行定时任务
|
||||||
* 任务名称:@SchedulerLock 注解中的 name 属性标识任务名称,相同名称的任务在分布式环境下互斥执行
|
* 任务名称:@SchedulerLock 注解中的 name 属性标识任务名称,相同名称的任务在分布式环境下互斥执行
|
||||||
@ -45,7 +45,7 @@ public class NoPayOrderProcessTask {
|
|||||||
* lockAtLeastFor:锁最少持有时间,防止任务执行过快导致频繁执行
|
* lockAtLeastFor:锁最少持有时间,防止任务执行过快导致频繁执行
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@Scheduled(cron = "0 */15 * * * ?")
|
@Scheduled(cron = "0 */6 * * * ?")
|
||||||
@SchedulerLock(name = "checkNoPayOrders", lockAtMostFor = "9m", lockAtLeastFor = "1m")
|
@SchedulerLock(name = "checkNoPayOrders", lockAtMostFor = "9m", lockAtLeastFor = "1m")
|
||||||
public void checkNoPayOrders() {
|
public void checkNoPayOrders() {
|
||||||
log.info("开始执行未支付订单检查任务");
|
log.info("开始执行未支付订单检查任务");
|
||||||
@ -66,7 +66,7 @@ public class NoPayOrderProcessTask {
|
|||||||
LambdaQueryWrapper<OrderMainPO> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<OrderMainPO> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(OrderMainPO::getDelFlag, "0").in(OrderMainPO::getOrderStatus,
|
queryWrapper.eq(OrderMainPO::getDelFlag, "0").in(OrderMainPO::getOrderStatus,
|
||||||
Arrays.asList(OrderStatusEnum.WAIT_PAY.getCode(), OrderStatusEnum.RERENT_WAIT_PAY.getCode()))
|
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<OrderMainPO> orders = orderMainRepo.list(queryWrapper);
|
List<OrderMainPO> orders = orderMainRepo.list(queryWrapper);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user