From dfbb6e6172f9a0a82681f0bf8f88e29a05de8046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=9F=91=E8=9E=82?= Date: Wed, 15 Apr 2026 21:57:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=AC=E5=8F=B8/=E5=BA=97=E9=93=BA?= =?UTF-8?q?=E6=A6=82=E8=A7=88=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E7=A8=8E=E7=8E=87=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 后端: - CompanyOverviewQueryDTO / ShopOverviewQueryDTO 增加 taxRate 字段,默认 0.04 - CompanyOverviewServiceImpl / ShopOverviewStatisticsServiceImpl 替换所有硬编码税率,统一使用请求参数中的税率 前端: - API DTO 增加 taxRate 可选参数 - 公司概览页 DatePicker 左侧增加税率输入框,localStorage 持久化 - 店铺概览页同样增加税率输入框,localStorage 持久化 --- .../model/dto/CompanyOverviewQueryDTO.java | 7 +++++ .../model/dto/ShopOverviewQueryDTO.java | 7 +++++ .../impl/CompanyOverviewServiceImpl.java | 12 +++++--- .../ShopOverviewStatisticsServiceImpl.java | 10 +++++-- .../company-overview/types/types.dto.ts | 2 ++ .../src/api/ecommerce/shop/types/types.dto.ts | 2 ++ .../dashboard/company-overview/index.vue | 28 ++++++++++++++++++- .../views/ecommerce/shop/overview/index.vue | 28 ++++++++++++++++++- 8 files changed, 87 insertions(+), 9 deletions(-) diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/dto/CompanyOverviewQueryDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/dto/CompanyOverviewQueryDTO.java index afb8ea81..5cceb3ed 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/dto/CompanyOverviewQueryDTO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/dto/CompanyOverviewQueryDTO.java @@ -5,6 +5,7 @@ import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.Size; import lombok.Data; +import java.math.BigDecimal; import java.time.LocalDate; import java.util.List; @@ -22,5 +23,11 @@ public class CompanyOverviewQueryDTO { @NotEmpty(message = "日期范围不能为空") @Size(min = 1, max = 2, message = "日期范围数组必须包含1-2个日期") private List dateRange; + + /** + * 税率(默认4%) + */ + @Schema(description = "税率,默认为0.04(即4%)", 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/ShopOverviewQueryDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/dto/ShopOverviewQueryDTO.java index 178a0aa8..cc81fede 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/dto/ShopOverviewQueryDTO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/dto/ShopOverviewQueryDTO.java @@ -6,6 +6,7 @@ import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import lombok.Data; +import java.math.BigDecimal; import java.time.LocalDate; import java.util.List; @@ -30,5 +31,11 @@ public class ShopOverviewQueryDTO { @NotEmpty(message = "日期范围不能为空") @Size(min = 1, max = 2, message = "日期范围数组必须包含1-2个日期") private List dateRange; + + /** + * 税率(默认4%) + */ + @Schema(description = "税率,默认为0.04(即4%)", 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/CompanyOverviewServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/CompanyOverviewServiceImpl.java index a58db1e2..d7d9f465 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/CompanyOverviewServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/CompanyOverviewServiceImpl.java @@ -36,7 +36,8 @@ import java.util.stream.Collectors; @Service public class CompanyOverviewServiceImpl implements CompanyOverviewService { - private static final BigDecimal TAX_RATE = new BigDecimal("0.06"); // 税率6% + private static final BigDecimal DEFAULT_TAX_RATE = new BigDecimal("0.04"); + private BigDecimal taxRate = DEFAULT_TAX_RATE; private final CurrentUserContext currentUserContext; private final OrderMapper orderMapper; @@ -64,6 +65,9 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { @Override public CompanyOverviewVO getCompanyOverview(CompanyOverviewQueryDTO queryDTO) { + // 取请求参数中的税率,默认4% + this.taxRate = queryDTO.getTaxRate() != null ? queryDTO.getTaxRate() : DEFAULT_TAX_RATE; + Long companyId = currentUserContext.getCurrentCompanyId(); // 解析日期范围 @@ -181,7 +185,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { // 6. 计算全店总净利(税后)和总税额 BigDecimal totalProfitBeforeTax = calculateTotalProfit(orders); - BigDecimal totalTaxAmount = totalProfitBeforeTax.multiply(TAX_RATE); + BigDecimal totalTaxAmount = totalProfitBeforeTax.multiply(taxRate); BigDecimal totalNetProfitAfterTax = totalProfitBeforeTax.subtract(totalTaxAmount); overviewVO.setTotalNetProfitAfterTax(totalNetProfitAfterTax); overviewVO.setTotalTaxAmount(totalTaxAmount); @@ -480,7 +484,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { BigDecimal profitBeforeTax = salesAmount.subtract(totalCost).subtract(refundAmount); // 销售额4%税额 - BigDecimal salesTaxAmount = salesAmount.multiply(new BigDecimal("0.04")); + BigDecimal salesTaxAmount = salesAmount.multiply(taxRate); // 税后盈亏(扣除销售额4%税额) BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount); @@ -614,7 +618,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { * 计算店铺净利(税后) */ private BigDecimal calculateShopNetProfit(BigDecimal profitBeforeTax) { - BigDecimal taxAmount = profitBeforeTax.multiply(TAX_RATE); + BigDecimal taxAmount = profitBeforeTax.multiply(taxRate); return profitBeforeTax.subtract(taxAmount); } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ShopOverviewStatisticsServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ShopOverviewStatisticsServiceImpl.java index 7c8ce329..d2a7ba2b 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ShopOverviewStatisticsServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ShopOverviewStatisticsServiceImpl.java @@ -38,7 +38,8 @@ import java.util.stream.Collectors; @Service public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatisticsService { - private static final BigDecimal SALES_TAX_RATE = new BigDecimal("0.04"); // 销售额4%税额 + private static final BigDecimal DEFAULT_TAX_RATE = new BigDecimal("0.04"); + private BigDecimal taxRate = DEFAULT_TAX_RATE; private final CurrentUserContext currentUserContext; private final OrderMapper orderMapper; @@ -69,6 +70,9 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics @Override public ShopOverviewStatisticsVO getShopOverviewStatistics(ShopOverviewQueryDTO queryDTO) { + // 取请求参数中的税率,默认4% + this.taxRate = queryDTO.getTaxRate() != null ? queryDTO.getTaxRate() : DEFAULT_TAX_RATE; + Long companyId = currentUserContext.getCurrentCompanyId(); // 解析日期范围 @@ -193,7 +197,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics // 6. 计算店铺总净利(税后)和总税额 BigDecimal totalProfitBeforeTax = calculateTotalProfit(orders); - BigDecimal totalSalesTaxAmount = totalSalesAmount.multiply(SALES_TAX_RATE); + BigDecimal totalSalesTaxAmount = totalSalesAmount.multiply(taxRate); BigDecimal totalNetProfitAfterTax = totalProfitBeforeTax.subtract(totalSalesTaxAmount); overviewVO.setTotalNetProfitAfterTax(totalNetProfitAfterTax); overviewVO.setTotalTaxAmount(totalSalesTaxAmount); @@ -389,7 +393,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics BigDecimal profitBeforeTax = salesAmount.subtract(totalCost).subtract(refundAmount); // 销售额4%税额 - BigDecimal salesTaxAmount = salesAmount.multiply(SALES_TAX_RATE); + BigDecimal salesTaxAmount = salesAmount.multiply(taxRate); // 税后盈亏(扣除销售额4%税额) BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount); diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/company-overview/types/types.dto.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/company-overview/types/types.dto.ts index fca3fd0a..2500a6d9 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/company-overview/types/types.dto.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/company-overview/types/types.dto.ts @@ -7,5 +7,7 @@ export namespace CompanyOverviewDTO { export interface Query { /** 日期范围数组(第一个是开始日期,第二个是结束日期,只有一个日期则返回当天数据) */ dateRange: string[]; + /** 税率(默认0.04,即4%) */ + taxRate?: number; } } diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.dto.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.dto.ts index 764cef53..ed411430 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.dto.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.dto.ts @@ -53,5 +53,7 @@ export namespace ShopDTO { shopId: number; /** 日期范围数组(第一个是开始日期,第二个是结束日期,只有一个日期则返回当天数据) */ dateRange: string[]; + /** 税率(默认0.04,即4%) */ + taxRate?: number; } } 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 0fa02be2..911c0bd9 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 @@ -12,7 +12,7 @@ import { useRoute, useRouter } from 'vue-router'; import { Page } from '@vben/common-ui'; import { EchartsUI, useEcharts } from '@vben/plugins/echarts'; -import { Button, DatePicker, message, Spin } from 'ant-design-vue'; +import { Button, DatePicker, InputNumber, message, Spin } from 'ant-design-vue'; import dayjs from 'dayjs'; import { getCompanyOverviewApi } from '#/api/ecommerce/company-overview'; @@ -50,6 +50,14 @@ const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([ dayjs(), ]); +// 税率(持久化) +const TAX_RATE_KEY = 'company-overview-tax-rate'; +const taxRate = ref(0.04); +taxRate.value = Number(localStorage.getItem(TAX_RATE_KEY)) || 0.04; +watch(taxRate, (val) => { + localStorage.setItem(TAX_RATE_KEY, String(val)); +}); + // 当前选中的时间范围类型 const activeTimeRange = ref< '7days' | '30days' | 'custom' | 'today' | 'yesterday' @@ -262,6 +270,7 @@ const loadOverviewData = async () => { dateRange.value[0].format('YYYY-MM-DD'), dateRange.value[1].format('YYYY-MM-DD'), ], + taxRate: taxRate.value, }; const data = await getCompanyOverviewApi(params); overviewData.value = data; @@ -645,6 +654,23 @@ const handleExportSelectedShops = async () => { + +
+ 税率 + +
+ +
+ +
+ 税率 + +
+ +
自定义日期