feat: 公司/店铺概览对比表增加商品成本和其他成本字段

CompanyOverviewVO.ShopComparison: 加 productCost、otherCost 字段
ShopOverviewStatisticsVO.ProductComparison: 加 productCost、otherCost 字段
CompanyOverviewServiceImpl / ShopOverviewStatisticsServiceImpl: 分别计算并赋值
前端 API 类型同步更新
公司概览 + 店铺概览页面表格:成本运费列拆为商品成本/运费/其他成本三列
This commit is contained in:
小蟑螂
2026-04-15 22:40:37 +08:00
parent f57b3ebb29
commit 03cf396aea
8 changed files with 152 additions and 18 deletions
@@ -186,9 +186,15 @@ public class CompanyOverviewVO {
@Schema(description = "客单价", example = "100.00")
private BigDecimal averageOrderValue;
@Schema(description = "成本运费", example = "5000.00")
@Schema(description = "商品成本", example = "3000.00")
private BigDecimal productCost;
@Schema(description = "运费", example = "1000.00")
private BigDecimal shippingCost;
@Schema(description = "其他成本", example = "1000.00")
private BigDecimal otherCost;
@Schema(description = "退款金额", example = "1000.00")
private BigDecimal refundAmount;
@@ -147,9 +147,15 @@ public class ShopOverviewStatisticsVO {
@Schema(description = "客单价", example = "100.00")
private BigDecimal averageOrderValue;
@Schema(description = "成本运费", example = "5000.00")
@Schema(description = "商品成本", example = "3000.00")
private BigDecimal productCost;
@Schema(description = "运费", example = "1000.00")
private BigDecimal shippingCost;
@Schema(description = "其他成本", example = "1000.00")
private BigDecimal otherCost;
@Schema(description = "退款金额", example = "1000.00")
private BigDecimal refundAmount;
@@ -471,7 +471,16 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
// 计算成本运费(单独计算运费成本)
// 计算商品成本
BigDecimal productCost = shopOrders.stream()
.map(order -> {
BigDecimal cost = order.getProductCost() != null ? order.getProductCost() : BigDecimal.ZERO;
Integer quantity = order.getQuantity() != null ? order.getQuantity() : 1;
return cost.multiply(new BigDecimal(quantity));
})
.reduce(BigDecimal.ZERO, BigDecimal::add);
// 计算运费成本
BigDecimal shippingCost = shopOrders.stream()
.map(order -> {
BigDecimal cost = order.getShippingCost() != null ? order.getShippingCost() : BigDecimal.ZERO;
@@ -480,6 +489,15 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
})
.reduce(BigDecimal.ZERO, BigDecimal::add);
// 计算其他成本
BigDecimal otherCost = shopOrders.stream()
.map(order -> {
BigDecimal cost = order.getOtherCost() != null ? order.getOtherCost() : BigDecimal.ZERO;
Integer quantity = order.getQuantity() != null ? order.getQuantity() : 1;
return cost.multiply(new BigDecimal(quantity));
})
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal totalCost = calculateShopTotalCost(shopOrders);
BigDecimal profitBeforeTax = salesAmount.subtract(totalCost).subtract(refundAmount);
@@ -540,7 +558,9 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
comparison.setSalesAmount(salesAmount);
comparison.setOrderCount(orderCount);
comparison.setAverageOrderValue(averageOrderValue);
comparison.setProductCost(productCost);
comparison.setShippingCost(shippingCost);
comparison.setOtherCost(otherCost);
comparison.setRefundAmount(refundAmount);
comparison.setTotalPromotionFee(totalPromotionFee);
comparison.setBrushFee(brushFee);
@@ -380,7 +380,16 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
productPromotionFee = totalPromotionFee.multiply(ratio);
}
// 计算成本运费(单独计算运费成本)
// 计算商品成本
BigDecimal productCost = productOrders.stream()
.map(order -> {
BigDecimal cost = order.getProductCost() != null ? order.getProductCost() : BigDecimal.ZERO;
Integer quantity = order.getQuantity() != null ? order.getQuantity() : 1;
return cost.multiply(new BigDecimal(quantity));
})
.reduce(BigDecimal.ZERO, BigDecimal::add);
// 计算运费成本
BigDecimal shippingCost = productOrders.stream()
.map(order -> {
BigDecimal cost = order.getShippingCost() != null ? order.getShippingCost() : BigDecimal.ZERO;
@@ -389,6 +398,15 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
})
.reduce(BigDecimal.ZERO, BigDecimal::add);
// 计算其他成本
BigDecimal otherCost = productOrders.stream()
.map(order -> {
BigDecimal cost = order.getOtherCost() != null ? order.getOtherCost() : BigDecimal.ZERO;
Integer quantity = order.getQuantity() != null ? order.getQuantity() : 1;
return cost.multiply(new BigDecimal(quantity));
})
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal totalCost = calculateProductTotalCost(productOrders);
BigDecimal profitBeforeTax = salesAmount.subtract(totalCost).subtract(refundAmount);
@@ -418,7 +436,9 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
comparison.setSalesAmount(salesAmount);
comparison.setOrderCount(orderCount);
comparison.setAverageOrderValue(averageOrderValue);
comparison.setProductCost(productCost);
comparison.setShippingCost(shippingCost);
comparison.setOtherCost(otherCost);
comparison.setRefundAmount(refundAmount);
comparison.setTotalPromotionFee(productPromotionFee);
comparison.setBrushFee(brushFee);
@@ -87,8 +87,12 @@ export namespace CompanyOverviewVO {
orderCount?: number;
/** 客单价 */
averageOrderValue?: number;
/** 成本运费 */
/** 商品成本 */
productCost?: number;
/** 运费 */
shippingCost?: number;
/** 其他成本 */
otherCost?: number;
/** 退款金额 */
refundAmount?: number;
/** 推广费 */
@@ -159,8 +159,12 @@ export namespace ShopVO {
orderCount?: number;
/** 客单价 */
averageOrderValue?: number;
/** 成本运费 */
/** 商品成本 */
productCost?: number;
/** 运费 */
shippingCost?: number;
/** 其他成本 */
otherCost?: number;
/** 退款金额 */
refundAmount?: number;
/** 推广费 */
@@ -59,6 +59,19 @@ watch(taxRate, (val) => {
loadOverviewData();
});
const formatTaxRate = (value: null | number | string | undefined) => {
if (value === null || value === undefined || value === '') return '';
const num = Number(value);
if (!Number.isFinite(num)) return '';
return `${num * 100}%`;
};
const parseTaxRate = (value: string | undefined) => {
if (!value) return 0;
const num = Number(value.replace('%', '').trim());
return Number.isFinite(num) ? num / 100 : 0;
};
// 当前选中的时间范围类型
const activeTimeRange = ref<
'7days' | '30days' | 'custom' | 'today' | 'yesterday'
@@ -595,7 +608,10 @@ const handleExportSelectedShops = async () => {
<!-- 税率 + 时间选择器 -->
<div class="flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-2">
<!-- 税率输入 -->
<div class="flex items-center gap-1 rounded-xl bg-slate-200/70 px-2 py-1.5">
<div
class="flex h-[42px] items-center gap-2 rounded-2xl border border-slate-200 bg-slate-200/50 px-3"
>
<span class="text-xs font-bold text-slate-400">税率</span>
<InputNumber
v-model:value="taxRate"
:min="0"
@@ -603,9 +619,9 @@ const handleExportSelectedShops = async () => {
: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)"
class="tax-rate-input !h-8 !w-20 !rounded-lg !border-none !bg-white/30 !text-sm !font-bold"
:formatter="formatTaxRate"
:parser="parseTaxRate"
/>
</div>
<!-- 时间选择器容器 -->
@@ -680,7 +696,7 @@ const handleExportSelectedShops = async () => {
format="YYYY-MM-DD"
:allow-clear="false"
:placeholder="['开始', '结束']"
class="!border-none !bg-transparent !text-sm !font-bold"
class="!h-8 !border-none !bg-transparent !text-sm !font-bold"
@change="handleCustomDateRangeChange"
/>
</div>
@@ -985,7 +1001,9 @@ const handleExportSelectedShops = async () => {
<th class="border-b px-6 py-4">单量</th>
<th class="border-b px-6 py-4">客单价</th>
<!-- 成本 -->
<th class="border-b border-l px-6 py-4">成本运费</th>
<th class="border-b border-l px-6 py-4">商品成本</th>
<th class="border-b px-6 py-4">运费</th>
<th class="border-b px-6 py-4">其他成本</th>
<th class="border-b px-6 py-4 font-bold text-rose-600">
退款金额
</th>
@@ -1075,11 +1093,21 @@ const handleExportSelectedShops = async () => {
}}
</td>
<!-- 成本 -->
<td class="p-6">
{{
shop.productCost ? formatAmount(shop.productCost) : '-'
}}
</td>
<td class="p-6">
{{
shop.shippingCost ? formatAmount(shop.shippingCost) : '-'
}}
</td>
<td class="p-6">
{{
shop.otherCost ? formatAmount(shop.otherCost) : '-'
}}
</td>
<td class="p-6 font-bold text-rose-600">
{{
shop.refundAmount ? formatAmount(shop.refundAmount) : '-'
@@ -1163,4 +1191,11 @@ const handleExportSelectedShops = async () => {
left: 0;
z-index: 10;
}
:deep(.tax-rate-input .ant-input-number-input) {
height: 32px;
line-height: 32px;
padding-top: 0;
padding-bottom: 0;
}
</style>
@@ -70,6 +70,19 @@ watch(taxRate, (val) => {
loadOverviewData();
});
const formatTaxRate = (value: null | number | string | undefined) => {
if (value === null || value === undefined || value === '') return '';
const num = Number(value);
if (!Number.isFinite(num)) return '';
return `${num * 100}%`;
};
const parseTaxRate = (value: string | undefined) => {
if (!value) return 0;
const num = Number(value.replace('%', '').trim());
return Number.isFinite(num) ? num / 100 : 0;
};
// 切换时间范围
const switchTimeRange = (
type: '7days' | '30days' | 'custom' | 'today' | 'yesterday',
@@ -722,7 +735,10 @@ onActivated(async () => {
<!-- 税率 + 时间选择器 -->
<div class="flex items-center gap-2">
<!-- 税率输入 -->
<div class="flex items-center gap-1 rounded-xl bg-slate-200/70 px-2 py-1.5">
<div
class="flex h-[42px] items-center gap-2 rounded-2xl border border-slate-200 bg-slate-200/50 px-3"
>
<span class="text-xs font-bold text-slate-400">税率</span>
<InputNumber
v-model:value="taxRate"
:min="0"
@@ -730,9 +746,9 @@ onActivated(async () => {
: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)"
class="tax-rate-input !h-8 !w-20 !rounded-lg !border-none !bg-white/30 !text-sm !font-bold"
:formatter="formatTaxRate"
:parser="parseTaxRate"
/>
</div>
<!-- 时间选择器 -->
@@ -803,7 +819,7 @@ onActivated(async () => {
format="YYYY-MM-DD"
:allow-clear="false"
:placeholder="['开始日期', '结束日期']"
class="!cursor-pointer !border-none !bg-transparent !text-sm !font-bold"
class="!h-8 !cursor-pointer !border-none !bg-transparent !text-sm !font-bold"
@change="handleCustomDateRangeChange"
/>
</div>
@@ -1112,7 +1128,9 @@ onActivated(async () => {
<th class="border-b px-6 py-4">单量</th>
<th class="border-b px-6 py-4">客单价</th>
<!-- 成本 -->
<th class="border-b border-l px-6 py-4">成本运费</th>
<th class="border-b border-l px-6 py-4">商品成本</th>
<th class="border-b px-6 py-4">运费</th>
<th class="border-b px-6 py-4">其他成本</th>
<th class="border-b px-6 py-4 text-rose-600">退款金额</th>
<th class="border-b px-6 py-4">推广费</th>
<th class="border-b px-6 py-4">刷单费用</th>
@@ -1163,6 +1181,13 @@ onActivated(async () => {
}}
</td>
<!-- 成本 -->
<td class="px-6 py-4">
{{
product.productCost
? formatAmount(product.productCost)
: '-'
}}
</td>
<td class="px-6 py-4">
{{
product.shippingCost
@@ -1170,6 +1195,13 @@ onActivated(async () => {
: '-'
}}
</td>
<td class="px-6 py-4">
{{
product.otherCost
? formatAmount(product.otherCost)
: '-'
}}
</td>
<td class="px-6 py-4 font-bold text-rose-500">
{{
product.refundAmount
@@ -1307,4 +1339,11 @@ onActivated(async () => {
left: 0;
z-index: 10;
}
:deep(.tax-rate-input .ant-input-number-input) {
height: 32px;
line-height: 32px;
padding-top: 0;
padding-bottom: 0;
}
</style>