mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 02:39:19 +08:00
refactor(ecom-dmb): 平台维度概览改为对象结构(含合计行)并优化订单排序配置
This commit is contained in:
+14
-1
@@ -79,11 +79,24 @@ public class CompanyOverviewVO {
|
||||
@Schema(description = "多品类数据横向对比")
|
||||
private List<CategoryComparison> categoryComparisons;
|
||||
|
||||
/**
|
||||
* 平台维度概览(包含合计行和平台列表)
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "平台维度概览")
|
||||
public static class PlatformOverview {
|
||||
@Schema(description = "合计行")
|
||||
private PlatformSummary total;
|
||||
|
||||
@Schema(description = "各平台汇总列表")
|
||||
private List<PlatformSummary> platforms;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台维度汇总
|
||||
*/
|
||||
@Schema(description = "平台维度汇总")
|
||||
private List<PlatformSummary> platformSummary;
|
||||
private PlatformOverview platformSummary;
|
||||
|
||||
/**
|
||||
* 汇总ROI
|
||||
|
||||
+233
-5
@@ -225,9 +225,9 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
overviewVO.setCategoryComparisons(categoryComparisons);
|
||||
|
||||
// 11. 平台维度汇总
|
||||
List<CompanyOverviewVO.PlatformSummary> platformSummary = calculatePlatformSummary(
|
||||
CompanyOverviewVO.PlatformOverview platformOverview = calculatePlatformSummary(
|
||||
shops, orders, promotionFees, brushOrders, refundStatusId, companyId, startDate, endDate);
|
||||
overviewVO.setPlatformSummary(platformSummary);
|
||||
overviewVO.setPlatformSummary(platformOverview);
|
||||
|
||||
// 12. 汇总ROI和总税后盈亏
|
||||
BigDecimal totalROI = calculateTotalROI(orders, promotionFees, brushOrders, refundStatusId);
|
||||
@@ -906,7 +906,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
/**
|
||||
* 计算平台维度汇总
|
||||
*/
|
||||
private List<CompanyOverviewVO.PlatformSummary> calculatePlatformSummary(
|
||||
private CompanyOverviewVO.PlatformOverview calculatePlatformSummary(
|
||||
List<ShopPO> shops, List<OrderPO> orders, List<PromotionFeePO> promotionFees,
|
||||
List<BrushOrderPO> brushOrders, Long refundStatusId, Long companyId,
|
||||
LocalDate startDate, LocalDate endDate) {
|
||||
@@ -920,11 +920,16 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
Map<Long, PlatformPO> platformMap = allPlatforms.stream()
|
||||
.collect(Collectors.toMap(PlatformPO::getId, p -> p));
|
||||
|
||||
// 按平台分组店铺
|
||||
// 按平台分组店铺(有platformId的)
|
||||
Map<Long, List<ShopPO>> shopsByPlatform = shops.stream()
|
||||
.filter(shop -> shop.getPlatformId() != null)
|
||||
.collect(Collectors.groupingBy(ShopPO::getPlatformId));
|
||||
|
||||
// 没有platformId的店铺,汇总为"其他平台"
|
||||
List<ShopPO> shopsWithoutPlatform = shops.stream()
|
||||
.filter(shop -> shop.getPlatformId() == null)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 生成目标月份列表
|
||||
List<LocalDate> targetMonths = new ArrayList<>();
|
||||
LocalDate currentMonth = startDate.withDayOfMonth(1);
|
||||
@@ -1106,9 +1111,232 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
platformSummaries.add(platformSummary);
|
||||
}
|
||||
|
||||
// 处理没有平台的店铺,汇总为"其他平台"
|
||||
if (!shopsWithoutPlatform.isEmpty()) {
|
||||
CompanyOverviewVO.PlatformSummary otherSummary = calculateOtherPlatformSummary(
|
||||
shopsWithoutPlatform, ordersByShop, promotionFeesByShop, brushOrdersByShop,
|
||||
targetsByShop, refundStatusId, taxRate);
|
||||
if (otherSummary.getOrderCount() > 0) {
|
||||
platformSummaries.add(otherSummary);
|
||||
}
|
||||
}
|
||||
|
||||
// 按销售额降序排序
|
||||
platformSummaries.sort(Comparator.comparing(CompanyOverviewVO.PlatformSummary::getSalesAmount).reversed());
|
||||
return platformSummaries;
|
||||
|
||||
// 计算合计行
|
||||
CompanyOverviewVO.PlatformSummary total = computePlatformTotal(platformSummaries);
|
||||
|
||||
// 封装为 PlatformOverview
|
||||
CompanyOverviewVO.PlatformOverview overview = new CompanyOverviewVO.PlatformOverview();
|
||||
overview.setTotal(total);
|
||||
overview.setPlatforms(platformSummaries);
|
||||
return overview;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算平台汇总的合计行
|
||||
*/
|
||||
private CompanyOverviewVO.PlatformSummary computePlatformTotal(List<CompanyOverviewVO.PlatformSummary> platforms) {
|
||||
BigDecimal totalSalesAmount = BigDecimal.ZERO;
|
||||
int totalOrderCount = 0;
|
||||
BigDecimal totalTargetAmount = BigDecimal.ZERO;
|
||||
int totalTargetOrderCount = 0;
|
||||
BigDecimal totalProductCost = BigDecimal.ZERO;
|
||||
BigDecimal totalShippingCost = BigDecimal.ZERO;
|
||||
BigDecimal totalOtherCost = BigDecimal.ZERO;
|
||||
BigDecimal totalRefundAmount = BigDecimal.ZERO;
|
||||
BigDecimal totalPromotionFee = BigDecimal.ZERO;
|
||||
BigDecimal totalBrushFee = BigDecimal.ZERO;
|
||||
|
||||
for (CompanyOverviewVO.PlatformSummary p : platforms) {
|
||||
totalSalesAmount = totalSalesAmount.add(p.getSalesAmount() != null ? p.getSalesAmount() : BigDecimal.ZERO);
|
||||
totalOrderCount += p.getOrderCount() != null ? p.getOrderCount() : 0;
|
||||
totalTargetAmount = totalTargetAmount.add(p.getTargetAmount() != null ? p.getTargetAmount() : BigDecimal.ZERO);
|
||||
totalTargetOrderCount += p.getTargetOrderCount() != null ? p.getTargetOrderCount() : 0;
|
||||
totalProductCost = totalProductCost.add(p.getProductCost() != null ? p.getProductCost() : BigDecimal.ZERO);
|
||||
totalShippingCost = totalShippingCost.add(p.getShippingCost() != null ? p.getShippingCost() : BigDecimal.ZERO);
|
||||
totalOtherCost = totalOtherCost.add(p.getOtherCost() != null ? p.getOtherCost() : BigDecimal.ZERO);
|
||||
totalRefundAmount = totalRefundAmount.add(p.getRefundAmount() != null ? p.getRefundAmount() : BigDecimal.ZERO);
|
||||
totalPromotionFee = totalPromotionFee.add(p.getTotalPromotionFee() != null ? p.getTotalPromotionFee() : BigDecimal.ZERO);
|
||||
totalBrushFee = totalBrushFee.add(p.getBrushFee() != null ? p.getBrushFee() : BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
BigDecimal avgOrderValue = totalOrderCount > 0
|
||||
? totalSalesAmount.divide(new BigDecimal(totalOrderCount), 2, RoundingMode.HALF_UP)
|
||||
: BigDecimal.ZERO;
|
||||
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
||||
BigDecimal profitBeforeTax = totalSalesAmount.subtract(totalCost).subtract(totalRefundAmount);
|
||||
BigDecimal taxRate = new BigDecimal("0.04");
|
||||
BigDecimal salesTax = totalSalesAmount.multiply(taxRate);
|
||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
||||
BigDecimal roi = totalPromotionFee.compareTo(BigDecimal.ZERO) > 0
|
||||
? totalSalesAmount.subtract(totalRefundAmount).divide(totalPromotionFee, 4, RoundingMode.HALF_UP)
|
||||
: BigDecimal.ZERO;
|
||||
BigDecimal feeRatio = totalSalesAmount.compareTo(BigDecimal.ZERO) > 0
|
||||
? totalPromotionFee.add(totalBrushFee).divide(totalSalesAmount, 4, RoundingMode.HALF_UP)
|
||||
: BigDecimal.ZERO;
|
||||
BigDecimal salesAchievementRate = totalTargetAmount.compareTo(BigDecimal.ZERO) > 0
|
||||
? totalSalesAmount.divide(totalTargetAmount, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100"))
|
||||
: totalSalesAmount.compareTo(BigDecimal.ZERO) > 0 ? new BigDecimal("100") : BigDecimal.ZERO;
|
||||
BigDecimal orderAchievementRate = totalTargetOrderCount > 0
|
||||
? new BigDecimal(totalOrderCount).divide(new BigDecimal(totalTargetOrderCount), 4, RoundingMode.HALF_UP)
|
||||
.multiply(new BigDecimal("100"))
|
||||
: totalOrderCount > 0 ? new BigDecimal("100") : BigDecimal.ZERO;
|
||||
|
||||
CompanyOverviewVO.PlatformSummary total = new CompanyOverviewVO.PlatformSummary();
|
||||
total.setPlatformId(0L);
|
||||
total.setPlatformName("合计");
|
||||
total.setSalesAmount(totalSalesAmount);
|
||||
total.setOrderCount(totalOrderCount);
|
||||
total.setAverageOrderValue(avgOrderValue);
|
||||
total.setTargetAmount(totalTargetAmount);
|
||||
total.setTargetOrderCount(totalTargetOrderCount);
|
||||
total.setSalesAmountAchievementRate(salesAchievementRate);
|
||||
total.setOrderCountAchievementRate(orderAchievementRate);
|
||||
total.setProductCost(totalProductCost);
|
||||
total.setShippingCost(totalShippingCost);
|
||||
total.setOtherCost(totalOtherCost);
|
||||
total.setRefundAmount(totalRefundAmount);
|
||||
total.setTotalPromotionFee(totalPromotionFee);
|
||||
total.setBrushFee(totalBrushFee);
|
||||
total.setFeeRatio(feeRatio);
|
||||
total.setTotalProfitBeforeTax(profitBeforeTax);
|
||||
total.setSalesTaxAmount(salesTax);
|
||||
total.setRoi(roi);
|
||||
total.setProfitAfterTax(profitAfterTax);
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算"其他平台"汇总(没有绑定平台的店铺)
|
||||
*/
|
||||
private CompanyOverviewVO.PlatformSummary calculateOtherPlatformSummary(
|
||||
List<ShopPO> shops,
|
||||
Map<Long, List<OrderPO>> ordersByShop,
|
||||
Map<Long, List<PromotionFeePO>> promotionFeesByShop,
|
||||
Map<Long, List<BrushOrderPO>> brushOrdersByShop,
|
||||
Map<Long, List<ShopMonthlyTargetPO>> targetsByShop,
|
||||
Long refundStatusId,
|
||||
BigDecimal taxRate) {
|
||||
|
||||
BigDecimal totalSalesAmount = BigDecimal.ZERO;
|
||||
int totalOrderCount = 0;
|
||||
BigDecimal totalRefundAmount = BigDecimal.ZERO;
|
||||
BigDecimal totalProductCost = BigDecimal.ZERO;
|
||||
BigDecimal totalShippingCost = BigDecimal.ZERO;
|
||||
BigDecimal totalOtherCost = BigDecimal.ZERO;
|
||||
BigDecimal totalPromotionFee = BigDecimal.ZERO;
|
||||
BigDecimal totalBrushFee = BigDecimal.ZERO;
|
||||
BigDecimal totalTargetAmount = BigDecimal.ZERO;
|
||||
int totalTargetOrderCount = 0;
|
||||
|
||||
for (ShopPO shop : shops) {
|
||||
List<OrderPO> shopOrders = ordersByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
List<PromotionFeePO> shopPromotionFees = promotionFeesByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
List<BrushOrderPO> shopBrushOrders = brushOrdersByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
List<ShopMonthlyTargetPO> shopTargets = targetsByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
|
||||
BigDecimal shopSales = shopOrders.stream()
|
||||
.map(o -> o.getReceivedAmount() != null ? o.getReceivedAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
totalSalesAmount = totalSalesAmount.add(shopSales);
|
||||
totalOrderCount += shopOrders.size();
|
||||
|
||||
BigDecimal shopRefund = shopOrders.stream()
|
||||
.filter(o -> refundStatusId != null && refundStatusId.equals(o.getStatusId()))
|
||||
.map(o -> o.getReceivedAmount() != null ? o.getReceivedAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
totalRefundAmount = totalRefundAmount.add(shopRefund);
|
||||
|
||||
BigDecimal shopProductCost = shopOrders.stream()
|
||||
.map(o -> {
|
||||
BigDecimal c = o.getProductCost() != null ? o.getProductCost() : BigDecimal.ZERO;
|
||||
int qty = o.getQuantity() != null ? o.getQuantity() : 1;
|
||||
return c.multiply(new BigDecimal(qty));
|
||||
})
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
totalProductCost = totalProductCost.add(shopProductCost);
|
||||
|
||||
BigDecimal shopShippingCost = shopOrders.stream()
|
||||
.map(o -> {
|
||||
BigDecimal c = o.getShippingCost() != null ? o.getShippingCost() : BigDecimal.ZERO;
|
||||
int qty = o.getQuantity() != null ? o.getQuantity() : 1;
|
||||
return c.multiply(new BigDecimal(qty));
|
||||
})
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
totalShippingCost = totalShippingCost.add(shopShippingCost);
|
||||
|
||||
BigDecimal shopOtherCost = shopOrders.stream()
|
||||
.map(o -> o.getOtherCost() != null ? o.getOtherCost() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
totalOtherCost = totalOtherCost.add(shopOtherCost);
|
||||
|
||||
BigDecimal shopPromoFee = shopPromotionFees.stream()
|
||||
.map(f -> f.getFeeAmount() != null ? f.getFeeAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
totalPromotionFee = totalPromotionFee.add(shopPromoFee);
|
||||
|
||||
BigDecimal shopBrush = shopBrushOrders.stream()
|
||||
.map(b -> b.getBrushAmount() != null ? b.getBrushAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
totalBrushFee = totalBrushFee.add(shopBrush);
|
||||
|
||||
BigDecimal shopTargetAmount = shopTargets.stream()
|
||||
.map(t -> t.getTargetAmount() != null ? t.getTargetAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
totalTargetAmount = totalTargetAmount.add(shopTargetAmount);
|
||||
|
||||
int shopTargetOrderCount = shopTargets.stream()
|
||||
.mapToInt(t -> t.getTargetOrderCount() != null ? t.getTargetOrderCount() : 0)
|
||||
.sum();
|
||||
totalTargetOrderCount += shopTargetOrderCount;
|
||||
}
|
||||
|
||||
BigDecimal averageOrderValue = totalOrderCount > 0
|
||||
? totalSalesAmount.divide(new BigDecimal(totalOrderCount), 2, RoundingMode.HALF_UP)
|
||||
: BigDecimal.ZERO;
|
||||
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
||||
BigDecimal profitBeforeTax = totalSalesAmount.subtract(totalCost).subtract(totalRefundAmount);
|
||||
BigDecimal salesTaxAmount = totalSalesAmount.multiply(taxRate);
|
||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
||||
BigDecimal roi = totalPromotionFee.compareTo(BigDecimal.ZERO) > 0
|
||||
? totalSalesAmount.subtract(totalRefundAmount).divide(totalPromotionFee, 4, RoundingMode.HALF_UP)
|
||||
: BigDecimal.ZERO;
|
||||
BigDecimal feeRatio = totalSalesAmount.compareTo(BigDecimal.ZERO) > 0
|
||||
? totalPromotionFee.add(totalBrushFee).divide(totalSalesAmount, 4, RoundingMode.HALF_UP)
|
||||
: BigDecimal.ZERO;
|
||||
BigDecimal salesAchievementRate = totalTargetAmount.compareTo(BigDecimal.ZERO) > 0
|
||||
? totalSalesAmount.divide(totalTargetAmount, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100"))
|
||||
: totalSalesAmount.compareTo(BigDecimal.ZERO) > 0 ? new BigDecimal("100") : BigDecimal.ZERO;
|
||||
BigDecimal orderAchievementRate = totalTargetOrderCount > 0
|
||||
? new BigDecimal(totalOrderCount).divide(new BigDecimal(totalTargetOrderCount), 4, RoundingMode.HALF_UP)
|
||||
.multiply(new BigDecimal("100"))
|
||||
: totalOrderCount > 0 ? new BigDecimal("100") : BigDecimal.ZERO;
|
||||
|
||||
CompanyOverviewVO.PlatformSummary summary = new CompanyOverviewVO.PlatformSummary();
|
||||
summary.setPlatformId(0L); // 0表示"其他平台"
|
||||
summary.setPlatformName("其他平台");
|
||||
summary.setTargetOrderCount(totalTargetOrderCount);
|
||||
summary.setOrderCountAchievementRate(orderAchievementRate);
|
||||
summary.setTargetAmount(totalTargetAmount);
|
||||
summary.setSalesAmountAchievementRate(salesAchievementRate);
|
||||
summary.setSalesAmount(totalSalesAmount);
|
||||
summary.setOrderCount(totalOrderCount);
|
||||
summary.setAverageOrderValue(averageOrderValue);
|
||||
summary.setProductCost(totalProductCost);
|
||||
summary.setShippingCost(totalShippingCost);
|
||||
summary.setOtherCost(totalOtherCost);
|
||||
summary.setRefundAmount(totalRefundAmount);
|
||||
summary.setTotalPromotionFee(totalPromotionFee);
|
||||
summary.setBrushFee(totalBrushFee);
|
||||
summary.setFeeRatio(feeRatio);
|
||||
summary.setTotalProfitBeforeTax(profitBeforeTax);
|
||||
summary.setSalesTaxAmount(salesTaxAmount);
|
||||
summary.setRoi(roi);
|
||||
summary.setProfitAfterTax(profitAfterTax);
|
||||
|
||||
return summary;
|
||||
}
|
||||
|
||||
private String getPlatformNameById(Long platformId) {
|
||||
|
||||
+10
-2
@@ -27,8 +27,8 @@ export namespace CompanyOverviewVO {
|
||||
shopComparisons?: ShopComparison[];
|
||||
/** 多品类数据横向对比 */
|
||||
categoryComparisons?: CategoryComparison[];
|
||||
/** 平台维度汇总 */
|
||||
platformSummary?: PlatformSummary[];
|
||||
/** 平台维度概览(包含合计行和平台列表) */
|
||||
platformSummary?: PlatformOverview;
|
||||
/** 汇总ROI */
|
||||
totalROI?: number;
|
||||
/** 总税后盈亏 */
|
||||
@@ -194,4 +194,12 @@ export namespace CompanyOverviewVO {
|
||||
/** 税后盈亏 */
|
||||
profitAfterTax?: number;
|
||||
}
|
||||
|
||||
/** 平台维度概览 */
|
||||
export interface PlatformOverview {
|
||||
/** 合计行 */
|
||||
total: PlatformSummary;
|
||||
/** 各平台汇总列表 */
|
||||
platforms: PlatformSummary[];
|
||||
}
|
||||
}
|
||||
|
||||
+31
-99
@@ -6,7 +6,7 @@ defineOptions({ name: 'PlatformSummaryCard' });
|
||||
|
||||
interface Props {
|
||||
taxRate?: number;
|
||||
platformSummary?: CompanyOverviewVO.PlatformSummary[];
|
||||
platformSummary?: CompanyOverviewVO.PlatformOverview;
|
||||
platformExportMode?: boolean;
|
||||
selectedExportPlatformIds?: number[];
|
||||
}
|
||||
@@ -31,70 +31,6 @@ const somePlatformsSelected = computed(() => {
|
||||
return props.selectedExportPlatformIds.length > 0;
|
||||
});
|
||||
|
||||
// 静态模拟数据 - 按平台汇总(字段与店铺明细表对齐)
|
||||
const mockPlatformData = [
|
||||
{
|
||||
platformId: 1, platformName: '淘宝',
|
||||
targetOrderCount: 5000, orderCountAchievementRate: 90.4,
|
||||
targetAmount: 320000, salesAmountAchievementRate: 88.6,
|
||||
salesAmount: 283600, orderCount: 4521, averageOrderValue: 62.7,
|
||||
productCost: 156000, shippingCost: 8500, otherCost: 3200,
|
||||
refundAmount: 12600, totalPromotionFee: 9800, brushFee: 4200,
|
||||
feeRatio: 18.7,
|
||||
totalProfitBeforeTax: 98600, salesTaxAmount: 11344, roi: 2.34, profitAfterTax: 87256,
|
||||
},
|
||||
{
|
||||
platformId: 2, platformName: '京东',
|
||||
targetOrderCount: 3500, orderCountAchievementRate: 93.7,
|
||||
targetAmount: 210000, salesAmountAchievementRate: 93.7,
|
||||
salesAmount: 196800, orderCount: 3280, averageOrderValue: 60.0,
|
||||
productCost: 108000, shippingCost: 6200, otherCost: 1800,
|
||||
refundAmount: 8900, totalPromotionFee: 6800, brushFee: 2100,
|
||||
feeRatio: 17.6,
|
||||
totalProfitBeforeTax: 71000, salesTaxAmount: 7872, roi: 2.61, profitAfterTax: 63128,
|
||||
},
|
||||
{
|
||||
platformId: 3, platformName: '拼多多',
|
||||
targetOrderCount: 6500, orderCountAchievementRate: 90.6,
|
||||
targetAmount: 170000, salesAmountAchievementRate: 90.7,
|
||||
salesAmount: 154200, orderCount: 5890, averageOrderValue: 26.2,
|
||||
productCost: 92400, shippingCost: 11800, otherCost: 2200,
|
||||
refundAmount: 18200, totalPromotionFee: 5600, brushFee: 3800,
|
||||
feeRatio: 25.9,
|
||||
totalProfitBeforeTax: 22200, salesTaxAmount: 6168, roi: 0.76, profitAfterTax: 16032,
|
||||
},
|
||||
{
|
||||
platformId: 4, platformName: '抖音',
|
||||
targetOrderCount: 2200, orderCountAchievementRate: 95.5,
|
||||
targetAmount: 60000, salesAmountAchievementRate: 103.3,
|
||||
salesAmount: 62000, orderCount: 2100, averageOrderValue: 29.5,
|
||||
productCost: 34100, shippingCost: 4200, otherCost: 1500,
|
||||
refundAmount: 3100, totalPromotionFee: 3200, brushFee: 0,
|
||||
feeRatio: 19.7,
|
||||
totalProfitBeforeTax: 15900, salesTaxAmount: 2480, roi: 2.12, profitAfterTax: 13420,
|
||||
},
|
||||
{
|
||||
platformId: 5, platformName: '天猫',
|
||||
targetOrderCount: 700, orderCountAchievementRate: 97.1,
|
||||
targetAmount: 36000, salesAmountAchievementRate: 98.3,
|
||||
salesAmount: 35400, orderCount: 680, averageOrderValue: 52.1,
|
||||
productCost: 19400, shippingCost: 680, otherCost: 560,
|
||||
refundAmount: 1100, totalPromotionFee: 1800, brushFee: 0,
|
||||
feeRatio: 11.5,
|
||||
totalProfitBeforeTax: 12860, salesTaxAmount: 1416, roi: 3.89, profitAfterTax: 11444,
|
||||
},
|
||||
{
|
||||
platformId: 6, platformName: '快手',
|
||||
targetOrderCount: 600, orderCountAchievementRate: 86.7,
|
||||
targetAmount: 15000, salesAmountAchievementRate: 85.3,
|
||||
salesAmount: 12800, orderCount: 520, averageOrderValue: 24.6,
|
||||
productCost: 7680, shippingCost: 1040, otherCost: 280,
|
||||
refundAmount: 620, totalPromotionFee: 960, brushFee: 0,
|
||||
feeRatio: 19.5,
|
||||
totalProfitBeforeTax: 2220, salesTaxAmount: 512, roi: 1.52, profitAfterTax: 1708,
|
||||
},
|
||||
];
|
||||
|
||||
const formatAmount = (amount: number) => {
|
||||
return `¥${amount.toLocaleString('zh-CN')}`;
|
||||
};
|
||||
@@ -106,10 +42,10 @@ const formatPercentPlain = (value: number | undefined) => {
|
||||
|
||||
const taxRateNum = computed(() => (props.taxRate ?? 0.04) * 100);
|
||||
|
||||
// 优先使用动态数据,否则降级到静态mock
|
||||
// 使用后端返回的平台列表数据
|
||||
const platformData = computed(() => {
|
||||
if (props.platformSummary && props.platformSummary.length > 0) {
|
||||
return props.platformSummary.map(p => ({
|
||||
if (props.platformSummary?.platforms && props.platformSummary.platforms.length > 0) {
|
||||
return props.platformSummary.platforms.map(p => ({
|
||||
platformId: p.platformId,
|
||||
platformName: p.platformName,
|
||||
targetOrderCount: p.targetOrderCount ?? 0,
|
||||
@@ -132,12 +68,11 @@ const platformData = computed(() => {
|
||||
profitAfterTax: p.profitAfterTax ?? 0,
|
||||
}));
|
||||
}
|
||||
return mockPlatformData;
|
||||
return [];
|
||||
});
|
||||
|
||||
const totalSales = computed(() => platformData.value.reduce((sum, p) => sum + p.salesAmount, 0));
|
||||
const totalOrderCount = computed(() => platformData.value.reduce((sum, p) => sum + p.orderCount, 0));
|
||||
const totalProfitAfterTax = computed(() => platformData.value.reduce((sum, p) => sum + p.profitAfterTax, 0));
|
||||
// 后端返回的合计行数据
|
||||
const totalData = computed(() => props.platformSummary?.total ?? null);
|
||||
|
||||
// 表格排序
|
||||
const sortField = ref<string>('salesAmount');
|
||||
@@ -352,53 +287,50 @@ const sortIcon = (field: string) => {
|
||||
</tr>
|
||||
</tbody>
|
||||
<!-- 合计行 -->
|
||||
<tfoot class="bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)]">
|
||||
<tfoot v-if="totalData" class="bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)]">
|
||||
<tr class="font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
|
||||
<td class="sticky-col border-r-2 border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] p-6 text-base">合计</td>
|
||||
<!-- 目标 -->
|
||||
<td class="p-6">{{ platformData.reduce((s, p) => s + p.targetOrderCount, 0).toLocaleString() }}</td>
|
||||
<td class="p-6">{{ totalData.targetOrderCount?.toLocaleString() }}</td>
|
||||
<td class="p-6 text-blue-600 dark:text-blue-400">-</td>
|
||||
<td class="p-6">{{ formatAmount(platformData.reduce((s, p) => s + p.targetAmount, 0)) }}</td>
|
||||
<td class="p-6">{{ formatAmount(totalData.targetAmount) }}</td>
|
||||
<td class="p-6 text-blue-600 dark:text-blue-400">-</td>
|
||||
<!-- 规模 -->
|
||||
<td class="p-6">{{ formatAmount(totalSales) }}</td>
|
||||
<td class="p-6">{{ totalOrderCount.toLocaleString() }}</td>
|
||||
<td class="p-6">{{ formatAmount(totalData.salesAmount) }}</td>
|
||||
<td class="p-6">{{ totalData.orderCount?.toLocaleString() }}</td>
|
||||
<td class="p-6">-</td>
|
||||
<!-- 成本 -->
|
||||
<td class="p-6">{{ formatAmount(platformData.reduce((s, p) => s + p.productCost, 0)) }}</td>
|
||||
<td class="p-6">{{ formatAmount(platformData.reduce((s, p) => s + p.shippingCost, 0)) }}</td>
|
||||
<td class="p-6">{{ formatAmount(platformData.reduce((s, p) => s + p.otherCost, 0)) }}</td>
|
||||
<td class="p-6 text-rose-600 dark:text-rose-400">{{ formatAmount(platformData.reduce((s, p) => s + p.refundAmount, 0)) }}</td>
|
||||
<td class="p-6">{{ formatAmount(platformData.reduce((s, p) => s + p.totalPromotionFee, 0)) }}</td>
|
||||
<td class="p-6 text-orange-600 dark:text-orange-400">{{ formatAmount(platformData.reduce((s, p) => s + p.brushFee, 0)) }}</td>
|
||||
<td class="p-6">{{ formatAmount(totalData.productCost) }}</td>
|
||||
<td class="p-6">{{ formatAmount(totalData.shippingCost) }}</td>
|
||||
<td class="p-6">{{ formatAmount(totalData.otherCost) }}</td>
|
||||
<td class="p-6 text-rose-600 dark:text-rose-400">{{ formatAmount(totalData.refundAmount) }}</td>
|
||||
<td class="p-6">{{ formatAmount(totalData.totalPromotionFee) }}</td>
|
||||
<td class="p-6 text-orange-600 dark:text-orange-400">{{ formatAmount(totalData.brushFee) }}</td>
|
||||
<td class="p-6 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
{{ formatPercentPlain(
|
||||
totalSales > 0
|
||||
? platformData.reduce((s, p) => s + p.productCost + p.shippingCost + p.otherCost + p.refundAmount + p.totalPromotionFee + p.brushFee, 0) / totalSales * 100
|
||||
: 0,
|
||||
) }}
|
||||
{{ formatPercentPlain(totalData.feeRatio) }}
|
||||
</td>
|
||||
<!-- 盈利 -->
|
||||
<td class="p-6">
|
||||
{{ formatAmount(platformData.reduce((s, p) => s + p.totalProfitBeforeTax, 0)) }}
|
||||
{{ formatAmount(totalData.totalProfitBeforeTax) }}
|
||||
</td>
|
||||
<td class="p-6 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
{{ formatAmount(platformData.reduce((s, p) => s + p.salesTaxAmount, 0)) }}
|
||||
{{ formatAmount(totalData.salesTaxAmount) }}
|
||||
</td>
|
||||
<td class="p-6 text-indigo-700 dark:text-indigo-400">
|
||||
{{
|
||||
(() => {
|
||||
const totalProfit = platformData.reduce((s, p) => s + p.totalProfitBeforeTax, 0);
|
||||
const totalCost = platformData.reduce((s, p) => s + p.productCost + p.shippingCost + p.otherCost + p.refundAmount + p.totalPromotionFee + p.brushFee, 0);
|
||||
return totalCost > 0 ? (totalProfit / totalCost).toFixed(2) : '-';
|
||||
})()
|
||||
}}
|
||||
{{ totalData.roi?.toFixed(2) }}
|
||||
</td>
|
||||
<td class="bg-emerald-100 dark:bg-emerald-900/30 p-6 text-base">
|
||||
{{ formatAmount(totalProfitAfterTax) }}
|
||||
<td class="bg-emerald-100 dark:bg-emerald-900/30 p-6 text-base"
|
||||
:class="totalData.profitAfterTax >= 0 ? 'text-emerald-600' : 'text-rose-600'"
|
||||
>
|
||||
{{ formatAmount(totalData.profitAfterTax) }}
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<tfoot v-else class="bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)]">
|
||||
<tr class="text-center text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
<td colspan="19" class="p-6">暂无数据</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -16,7 +16,6 @@ import dayjs from 'dayjs';
|
||||
|
||||
import {
|
||||
Button,
|
||||
DatePicker,
|
||||
message,
|
||||
Popconfirm,
|
||||
Popover,
|
||||
|
||||
Reference in New Issue
Block a user