diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/dto/CompanyExportDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/dto/CompanyExportDTO.java index 8d96eb97..9b026832 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/dto/CompanyExportDTO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/dto/CompanyExportDTO.java @@ -3,8 +3,10 @@ package top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.Size; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.Data; +import java.math.BigDecimal; import java.time.LocalDate; import java.util.List; @@ -12,6 +14,7 @@ import java.util.List; * 公司概览导出DTO */ @Data +@JsonIgnoreProperties(ignoreUnknown = true) @Schema(description = "公司概览导出DTO") public class CompanyExportDTO { @@ -25,4 +28,7 @@ public class CompanyExportDTO { @Schema(description = "导出类型:summary-汇总 / detail-明细 / all-全部,默认 all", example = "all") private String exportType = "all"; + + @Schema(description = "税率,默认 0.04", example = "0.04") + private BigDecimal taxRate = new BigDecimal("0.04"); } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/dto/ShopExportDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/dto/ShopExportDTO.java index 75caed33..9ddca301 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/dto/ShopExportDTO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/dto/ShopExportDTO.java @@ -4,8 +4,10 @@ import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.Data; +import java.math.BigDecimal; import java.time.LocalDate; import java.util.List; @@ -13,6 +15,7 @@ import java.util.List; * 店铺概览导出DTO */ @Data +@JsonIgnoreProperties(ignoreUnknown = true) @Schema(description = "店铺概览导出DTO") public class ShopExportDTO { @@ -27,4 +30,7 @@ public class ShopExportDTO { @Schema(description = "导出类型:summary-汇总 / product-商品明细 / trend-趋势 / all-全部,默认 all", example = "all") private String exportType = "all"; + + @Schema(description = "税率,默认 0.04", example = "0.04") + private BigDecimal taxRate = new BigDecimal("0.04"); } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ExportServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ExportServiceImpl.java index 9a5c1bb6..da715f31 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ExportServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ExportServiceImpl.java @@ -43,7 +43,7 @@ import java.util.stream.Collectors; @Service public class ExportServiceImpl implements ExportService { - private static final BigDecimal SALES_TAX_RATE = new BigDecimal("0.04"); + private static final BigDecimal DEFAULT_TAX_RATE = new BigDecimal("0.04"); private static final DateTimeFormatter DATE_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd"); private final CurrentUserContext currentUserContext; @@ -98,8 +98,10 @@ public class ExportServiceImpl implements ExportService { BigDecimal totalBrushFee = BigDecimal.ZERO; BigDecimal totalProfitBeforeTax = BigDecimal.ZERO; + BigDecimal taxRate = dto.getTaxRate() != null ? dto.getTaxRate() : DEFAULT_TAX_RATE; + for (ShopPO shop : shops) { - Map data = buildShopData(shop, dateRange[0], dateRange[1], autoStatusIds, refundStatusId, companyId); + Map data = buildShopData(shop, dateRange[0], dateRange[1], autoStatusIds, refundStatusId, companyId, taxRate); shopDataList.add(data); totalSales = totalSales.add((BigDecimal) data.get("salesAmount")); @@ -110,7 +112,7 @@ public class ExportServiceImpl implements ExportService { } // 计算汇总数据 - BigDecimal totalTax = totalProfitBeforeTax.multiply(SALES_TAX_RATE).setScale(2, RoundingMode.HALF_UP); + BigDecimal totalTax = totalProfitBeforeTax.multiply(taxRate).setScale(2, RoundingMode.HALF_UP); BigDecimal totalProfitAfterTax = totalProfitBeforeTax.subtract(totalTax); BigDecimal totalCost = totalPromotionFee.add(totalBrushFee); BigDecimal totalRoi = totalCost.compareTo(BigDecimal.ZERO) > 0 @@ -144,7 +146,7 @@ public class ExportServiceImpl implements ExportService { String exportType = dto.getExportType() == null ? "all" : dto.getExportType(); if ("detail".equals(exportType) || "all".equals(exportType)) { Sheet detailSheet = workbook.createSheet("店铺明细"); - createCompanyDetailSheet(detailSheet, dateRangeLabel, shopDataList); + createCompanyDetailSheet(detailSheet, dateRangeLabel, shopDataList, taxRate); } if (("trend".equals(exportType) || "all".equals(exportType)) && !ordersByDate.isEmpty()) { @@ -264,7 +266,7 @@ public class ExportServiceImpl implements ExportService { } } - private void createCompanyDetailSheet(Sheet sheet, String dateRangeLabel, List> shopDataList) { + private void createCompanyDetailSheet(Sheet sheet, String dateRangeLabel, List> shopDataList, BigDecimal taxRate) { Row titleRow = sheet.createRow(0); Cell titleCell = titleRow.createCell(0); titleCell.setCellValue("店铺明细 | " + dateRangeLabel); @@ -274,11 +276,12 @@ public class ExportServiceImpl implements ExportService { CellStyle dataStyle = createDataStyle(sheet.getWorkbook()); // 列顺序与 Dashboard 表格一致 + String taxLabel = (taxRate.multiply(new BigDecimal("100")).setScale(0, RoundingMode.HALF_UP)).toPlainString() + "%税额"; String[] headers = { "店铺名称", "目标单量", "单量达成率(%)", "目标额", "销售达成率(%)", "实际销售额", "单量", "客单价", - "成本运费", "退款金额", "推广费", "刷单费用", "费比", - "税前盈亏", "4%税额", "ROI", "税后盈亏" + "商品成本", "运费", "其他成本", "退款金额", "推广费", "刷单费用", "费比", + "税前盈亏", taxLabel, "ROI", "税后盈亏" }; Row headerRow = sheet.createRow(1); @@ -299,15 +302,17 @@ public class ExportServiceImpl implements ExportService { setCell(row, 5, objToDouble(data.get("salesAmount")), dataStyle); setCell(row, 6, objToDouble(data.get("orderCount")), dataStyle); setCell(row, 7, objToDouble(data.get("avgOrderValue")), dataStyle); - setCell(row, 8, objToDouble(data.get("shippingCost")), dataStyle); - setCell(row, 9, objToDouble(data.get("refundAmount")), dataStyle); - setCell(row, 10, objToDouble(data.get("totalPromotionFee")), dataStyle); - setCell(row, 11, objToDouble(data.get("brushFee")), dataStyle); - setCell(row, 12, objToDouble(data.get("feeRatio")), dataStyle); - setCell(row, 13, objToDouble(data.get("profitBeforeTax")), dataStyle); - setCell(row, 14, objToDouble(data.get("salesTaxAmount")), dataStyle); - setCell(row, 15, objToDouble(data.get("roi")), dataStyle); - setCell(row, 16, objToDouble(data.get("profitAfterTax")), dataStyle); + setCell(row, 8, objToDouble(data.get("productCost")), dataStyle); + setCell(row, 9, objToDouble(data.get("shippingCost")), dataStyle); + setCell(row, 10, objToDouble(data.get("otherCost")), dataStyle); + setCell(row, 11, objToDouble(data.get("refundAmount")), dataStyle); + setCell(row, 12, objToDouble(data.get("totalPromotionFee")), dataStyle); + setCell(row, 13, objToDouble(data.get("brushFee")), dataStyle); + setCell(row, 14, objToDouble(data.get("feeRatio")), dataStyle); + setCell(row, 15, objToDouble(data.get("profitBeforeTax")), dataStyle); + setCell(row, 16, objToDouble(data.get("salesTaxAmount")), dataStyle); + setCell(row, 17, objToDouble(data.get("roi")), dataStyle); + setCell(row, 18, objToDouble(data.get("profitAfterTax")), dataStyle); } for (int i = 0; i < headers.length; i++) { @@ -461,7 +466,7 @@ public class ExportServiceImpl implements ExportService { BigDecimal totalCost = productCost.add(shippingCost); BigDecimal profitBeforeTax = salesAmount.subtract(totalCost).subtract(refundAmount); - BigDecimal tax = profitBeforeTax.multiply(SALES_TAX_RATE).setScale(2, RoundingMode.HALF_UP); + BigDecimal tax = profitBeforeTax.multiply(DEFAULT_TAX_RATE).setScale(2, RoundingMode.HALF_UP); BigDecimal profitAfterTax = profitBeforeTax.subtract(tax); // 按商品分摊推广费和刷单费(按销售额占比) @@ -762,7 +767,8 @@ public class ExportServiceImpl implements ExportService { // ==================== 数据构建方法 ==================== private Map buildShopData(ShopPO shop, LocalDate startDate, LocalDate endDate, - List autoStatusIds, Long refundStatusId, Long companyId) { + List autoStatusIds, Long refundStatusId, Long companyId, + BigDecimal taxRate) { LocalDateTime startDateTime = startDate.atStartOfDay(); LocalDateTime endDateTime = endDate.atTime(23, 59, 59); @@ -843,6 +849,14 @@ public class ExportServiceImpl implements ExportService { }) .reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal otherCostTotal = orders.stream() + .map(o -> { + BigDecimal c = o.getOtherCost() != null ? o.getOtherCost() : BigDecimal.ZERO; + Integer qty = o.getQuantity() != null ? o.getQuantity() : 1; + return c.multiply(new BigDecimal(qty)); + }) + .reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal promotionFee = promotionFees.stream() .map(f -> f.getFeeAmount() != null ? f.getFeeAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); @@ -851,9 +865,9 @@ public class ExportServiceImpl implements ExportService { .map(b -> b.getBrushAmount() != null ? b.getBrushAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); - BigDecimal totalCost = productCostTotal.add(shippingCost); + BigDecimal totalCost = productCostTotal.add(shippingCost).add(otherCostTotal); BigDecimal profitBeforeTax = salesAmount.subtract(totalCost).subtract(refundAmount); - BigDecimal tax = profitBeforeTax.multiply(SALES_TAX_RATE).setScale(2, RoundingMode.HALF_UP); + BigDecimal tax = profitBeforeTax.multiply(taxRate).setScale(2, RoundingMode.HALF_UP); BigDecimal profitAfterTax = profitBeforeTax.subtract(tax); BigDecimal feeRatio = salesAmount.compareTo(BigDecimal.ZERO) > 0 ? promotionFee.divide(salesAmount, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO; @@ -877,7 +891,9 @@ public class ExportServiceImpl implements ExportService { data.put("brushFee", brushFee); data.put("feeRatio", feeRatio); data.put("refundAmount", refundAmount); + data.put("productCost", productCostTotal); data.put("shippingCost", shippingCost); + data.put("otherCost", otherCostTotal); data.put("totalProfitBeforeTax", profitBeforeTax); // 对齐 ShopComparison data.put("salesTaxAmount", tax); // 对齐 ShopComparison data.put("profitAfterTax", profitAfterTax); diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/company-overview/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/company-overview/index.vue index 61e3e6de..962d85ff 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/company-overview/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/company-overview/index.vue @@ -567,6 +567,7 @@ const handleExportCompanyOverview = async () => { endDate.format('YYYY-MM-DD'), ], shopIds, + taxRate: taxRate.value, }, filename, );