fix(shop): 修复店铺概览页退款金额统计,getRefundStatusId改为getRefundStatusIds支持多退款状态

This commit is contained in:
小蟑螂
2026-04-25 16:58:32 +08:00
parent 443f4579ef
commit efa6341dd2
@@ -249,14 +249,14 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
/** /**
* 获取退款状态ID(根据 is_refund 字段查找) * 获取退款状态ID(根据 is_refund 字段查找)
*/ */
private Long getRefundStatusId() { private List<Long> getRefundStatusIds() {
Long companyId = currentUserContext.getCurrentCompanyId(); Long companyId = currentUserContext.getCurrentCompanyId();
LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrderStatusPO::getCompanyId, companyId) wrapper.eq(OrderStatusPO::getCompanyId, companyId)
.eq(OrderStatusPO::getIsRefund, 1) .eq(OrderStatusPO::getIsRefund, 1)
.last("LIMIT 1"); .select(OrderStatusPO::getId);
OrderStatusPO status = orderStatusService.getOne(wrapper); List<OrderStatusPO> statusList = orderStatusService.list(wrapper);
return status != null ? status.getId() : null; return statusList.stream().map(OrderStatusPO::getId).collect(Collectors.toList());
} }
/** /**
@@ -325,7 +325,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
List<PromotionFeePO> promotionFees = promotionFeeMapper.selectList(promotionWrapper); List<PromotionFeePO> promotionFees = promotionFeeMapper.selectList(promotionWrapper);
// 获取退款状态ID // 获取退款状态ID
Long refundStatusId = getRefundStatusId(); List<Long> refundStatusIds = getRefundStatusIds();
// 按日期分组订单数据 // 按日期分组订单数据
Map<LocalDate, List<OrderPO>> ordersByDate = orders.stream() Map<LocalDate, List<OrderPO>> ordersByDate = orders.stream()
@@ -368,7 +368,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
// 计算退款金额统计 // 计算退款金额统计
ShopOverviewVO.DailyStatistics refundAmountStats = calculateRefundAmountStatistics( ShopOverviewVO.DailyStatistics refundAmountStats = calculateRefundAmountStatistics(
ordersByDate, dateList, orders, refundStatusId); ordersByDate, dateList, orders, refundStatusIds);
overviewVO.setRefundAmount(refundAmountStats); overviewVO.setRefundAmount(refundAmountStats);
// 计算推广费统计 // 计算推广费统计
@@ -543,14 +543,14 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
*/ */
private ShopOverviewVO.DailyStatistics calculateRefundAmountStatistics( private ShopOverviewVO.DailyStatistics calculateRefundAmountStatistics(
Map<LocalDate, List<OrderPO>> ordersByDate, List<LocalDate> dateList, Map<LocalDate, List<OrderPO>> ordersByDate, List<LocalDate> dateList,
List<OrderPO> allOrders, Long refundStatusId) { List<OrderPO> allOrders, List<Long> refundStatusIds) {
ShopOverviewVO.DailyStatistics stats = new ShopOverviewVO.DailyStatistics(); ShopOverviewVO.DailyStatistics stats = new ShopOverviewVO.DailyStatistics();
// 计算总退款金额 // 计算总退款金额
BigDecimal total = BigDecimal.ZERO; BigDecimal total = BigDecimal.ZERO;
if (refundStatusId != null) { if (!refundStatusIds.isEmpty()) {
total = allOrders.stream() total = allOrders.stream()
.filter(order -> refundStatusId.equals(order.getStatusId())) .filter(order -> refundStatusIds.contains(order.getStatusId()))
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add); .reduce(BigDecimal.ZERO, BigDecimal::add);
} }
@@ -563,9 +563,9 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
dailyData.setDate(date); dailyData.setDate(date);
List<OrderPO> dayOrders = ordersByDate.getOrDefault(date, List.of()); List<OrderPO> dayOrders = ordersByDate.getOrDefault(date, List.of());
BigDecimal dayRefund = BigDecimal.ZERO; BigDecimal dayRefund = BigDecimal.ZERO;
if (refundStatusId != null) { if (!refundStatusIds.isEmpty()) {
dayRefund = dayOrders.stream() dayRefund = dayOrders.stream()
.filter(order -> refundStatusId.equals(order.getStatusId())) .filter(order -> refundStatusIds.contains(order.getStatusId()))
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add); .reduce(BigDecimal.ZERO, BigDecimal::add);
} }