mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:19:19 +08:00
feat: 公司/店铺概览增加自定义税率参数
后端: - CompanyOverviewQueryDTO / ShopOverviewQueryDTO 增加 taxRate 字段,默认 0.04 - CompanyOverviewServiceImpl / ShopOverviewStatisticsServiceImpl 替换所有硬编码税率,统一使用请求参数中的税率 前端: - API DTO 增加 taxRate 可选参数 - 公司概览页 DatePicker 左侧增加税率输入框,localStorage 持久化 - 店铺概览页同样增加税率输入框,localStorage 持久化
This commit is contained in:
+7
@@ -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<LocalDate> dateRange;
|
||||
|
||||
/**
|
||||
* 税率(默认4%)
|
||||
*/
|
||||
@Schema(description = "税率,默认为0.04(即4%)", example = "0.04")
|
||||
private BigDecimal taxRate = new BigDecimal("0.04");
|
||||
}
|
||||
|
||||
|
||||
+7
@@ -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<LocalDate> dateRange;
|
||||
|
||||
/**
|
||||
* 税率(默认4%)
|
||||
*/
|
||||
@Schema(description = "税率,默认为0.04(即4%)", example = "0.04")
|
||||
private BigDecimal taxRate = new BigDecimal("0.04");
|
||||
}
|
||||
|
||||
|
||||
+8
-4
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+7
-3
@@ -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);
|
||||
|
||||
@@ -7,5 +7,7 @@ export namespace CompanyOverviewDTO {
|
||||
export interface Query {
|
||||
/** 日期范围数组(第一个是开始日期,第二个是结束日期,只有一个日期则返回当天数据) */
|
||||
dateRange: string[];
|
||||
/** 税率(默认0.04,即4%) */
|
||||
taxRate?: number;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,5 +53,7 @@ export namespace ShopDTO {
|
||||
shopId: number;
|
||||
/** 日期范围数组(第一个是开始日期,第二个是结束日期,只有一个日期则返回当天数据) */
|
||||
dateRange: string[];
|
||||
/** 税率(默认0.04,即4%) */
|
||||
taxRate?: number;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<number>(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 () => {
|
||||
</div>
|
||||
<!-- 分隔线 - 移动端隐藏 -->
|
||||
<div class="hidden h-6 w-px bg-slate-300 sm:block"></div>
|
||||
<!-- 税率输入 -->
|
||||
<div class="flex items-center gap-1 rounded-xl bg-white/30 px-2 py-1.5">
|
||||
<span class="text-xs font-bold text-slate-400">税率</span>
|
||||
<InputNumber
|
||||
v-model:value="taxRate"
|
||||
:min="0"
|
||||
:max="1"
|
||||
:step="0.01"
|
||||
:precision="2"
|
||||
size="small"
|
||||
class="!w-16 !border-none !bg-transparent !text-sm !font-bold"
|
||||
:formatter="(val: number) => `${Number(val) * 100}%`"
|
||||
:parser="(val: string) => String(Number(val.replace('%', '')) / 100)"
|
||||
/>
|
||||
</div>
|
||||
<!-- 分隔线 - 移动端隐藏 -->
|
||||
<div class="hidden h-6 w-px bg-slate-300 sm:block"></div>
|
||||
<!-- 自定义日期选择器 -->
|
||||
<div class="flex items-center gap-2 rounded-xl bg-white/30 px-3 py-1.5">
|
||||
<span class="hidden text-xs font-bold text-slate-400 sm:inline">
|
||||
|
||||
@@ -13,7 +13,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, Tag } from 'ant-design-vue';
|
||||
import { Button, DatePicker, InputNumber, message, Spin, Tag } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
@@ -61,6 +61,14 @@ const customDateRange = ref<[dayjs.Dayjs, dayjs.Dayjs] | undefined>([
|
||||
const lastRequestKey = ref('');
|
||||
const isSyncingRouteQuery = ref(false);
|
||||
|
||||
// 税率(持久化)
|
||||
const TAX_RATE_KEY = 'shop-overview-tax-rate';
|
||||
const taxRate = ref<number>(0.04);
|
||||
taxRate.value = Number(localStorage.getItem(TAX_RATE_KEY)) || 0.04;
|
||||
watch(taxRate, (val) => {
|
||||
localStorage.setItem(TAX_RATE_KEY, String(val));
|
||||
});
|
||||
|
||||
// 切换时间范围
|
||||
const switchTimeRange = (
|
||||
type: '7days' | '30days' | 'custom' | 'today' | 'yesterday',
|
||||
@@ -234,6 +242,7 @@ const loadOverviewData = async () => {
|
||||
dateRange.value[0].format('YYYY-MM-DD'),
|
||||
dateRange.value[1].format('YYYY-MM-DD'),
|
||||
],
|
||||
taxRate: taxRate.value,
|
||||
};
|
||||
const data = await getShopOverviewStatisticsApi(params);
|
||||
overviewData.value = data;
|
||||
@@ -770,6 +779,23 @@ onActivated(async () => {
|
||||
</div>
|
||||
<!-- 分隔线 -->
|
||||
<div class="mx-2 h-6 w-px bg-slate-300"></div>
|
||||
<!-- 税率输入 -->
|
||||
<div class="flex items-center gap-1 px-2">
|
||||
<span class="text-xs font-bold text-slate-400">税率</span>
|
||||
<InputNumber
|
||||
v-model:value="taxRate"
|
||||
:min="0"
|
||||
:max="1"
|
||||
:step="0.01"
|
||||
:precision="2"
|
||||
size="small"
|
||||
class="!w-16 !border-none !bg-transparent !text-sm !font-bold"
|
||||
:formatter="(val: number) => `${Number(val) * 100}%`"
|
||||
:parser="(val: string) => String(Number(val.replace('%', '')) / 100)"
|
||||
/>
|
||||
</div>
|
||||
<!-- 分隔线 -->
|
||||
<div class="mx-2 h-6 w-px bg-slate-300"></div>
|
||||
<!-- 自定义日期选择器 -->
|
||||
<div class="flex items-center gap-2 px-3">
|
||||
<span class="text-xs font-bold text-slate-400">自定义日期</span>
|
||||
|
||||
Reference in New Issue
Block a user