mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 15:49:19 +08:00
fix: 优化多处细节
- 导出功能修复 Token 刷新机制,使用 requestClient 发送请求 - 店铺/商品单元格添加跳转图标 tdesign:jump - 店铺概览 ROI 计算精度统一为两位小数 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+22
-6
@@ -50,6 +50,17 @@ public class CategoryExportExcelServiceImpl implements CategoryExportExcelServic
|
|||||||
private static final BigDecimal DEFAULT_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 static final DateTimeFormatter DATE_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
|
|
||||||
|
private static BigDecimal salesTaxOnNetForCategoryExport(BigDecimal sales, BigDecimal refund, BigDecimal taxRate) {
|
||||||
|
BigDecimal s = sales != null ? sales : BigDecimal.ZERO;
|
||||||
|
BigDecimal rfd = refund != null ? refund : BigDecimal.ZERO;
|
||||||
|
BigDecimal r = taxRate != null ? taxRate : DEFAULT_TAX_RATE;
|
||||||
|
BigDecimal base = s.subtract(rfd);
|
||||||
|
if (base.compareTo(BigDecimal.ZERO) < 0) {
|
||||||
|
base = BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
return base.multiply(r).setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
private final CurrentUserContext currentUserContext;
|
private final CurrentUserContext currentUserContext;
|
||||||
private final OrderMapper orderMapper;
|
private final OrderMapper orderMapper;
|
||||||
private final PromotionFeeMapper promotionFeeMapper;
|
private final PromotionFeeMapper promotionFeeMapper;
|
||||||
@@ -380,7 +391,7 @@ public class CategoryExportExcelServiceImpl implements CategoryExportExcelServic
|
|||||||
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
||||||
BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund)
|
BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund)
|
||||||
.subtract(totalPromoFee).subtract(totalBrushFee);
|
.subtract(totalPromoFee).subtract(totalBrushFee);
|
||||||
BigDecimal salesTax = totalSales.multiply(taxRate);
|
BigDecimal salesTax = salesTaxOnNetForCategoryExport(totalSales, totalRefund, taxRate);
|
||||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
||||||
BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
||||||
? totalSales.subtract(totalRefund).divide(totalPromoFee, 4, RoundingMode.HALF_UP)
|
? totalSales.subtract(totalRefund).divide(totalPromoFee, 4, RoundingMode.HALF_UP)
|
||||||
@@ -449,10 +460,10 @@ public class CategoryExportExcelServiceImpl implements CategoryExportExcelServic
|
|||||||
|
|
||||||
int r = 2;
|
int r = 2;
|
||||||
for (ShopOverviewStatisticsVO.CategorySummary rowData : rows) {
|
for (ShopOverviewStatisticsVO.CategorySummary rowData : rows) {
|
||||||
fillCategoryDataRow(sheet.createRow(r++), rowData, dataStyle);
|
fillCategoryDataRow(sheet.createRow(r++), rowData, dataStyle, taxRate);
|
||||||
}
|
}
|
||||||
if (totalRow != null) {
|
if (totalRow != null) {
|
||||||
fillCategoryDataRow(sheet.createRow(r), totalRow, totalStyle);
|
fillCategoryDataRow(sheet.createRow(r), totalRow, totalStyle, taxRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
sheet.setColumnWidth(0, 5200);
|
sheet.setColumnWidth(0, 5200);
|
||||||
@@ -461,7 +472,8 @@ public class CategoryExportExcelServiceImpl implements CategoryExportExcelServic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillCategoryDataRow(Row row, ShopOverviewStatisticsVO.CategorySummary d, CellStyle style) {
|
private void fillCategoryDataRow(
|
||||||
|
Row row, ShopOverviewStatisticsVO.CategorySummary d, CellStyle style, BigDecimal taxRate) {
|
||||||
setCell(row, 0, d.getCategoryName() != null ? d.getCategoryName() : "", style);
|
setCell(row, 0, d.getCategoryName() != null ? d.getCategoryName() : "", style);
|
||||||
setCell(row, 1, bd2Money(d.getSalesAmount()), style);
|
setCell(row, 1, bd2Money(d.getSalesAmount()), style);
|
||||||
Cell oc = row.createCell(2);
|
Cell oc = row.createCell(2);
|
||||||
@@ -477,9 +489,13 @@ public class CategoryExportExcelServiceImpl implements CategoryExportExcelServic
|
|||||||
setCell(row, 10, bd2Money(d.getBrushFee()), style);
|
setCell(row, 10, bd2Money(d.getBrushFee()), style);
|
||||||
setCell(row, 11, bd2FeeRatioPercent(d.getFeeRatio()), style);
|
setCell(row, 11, bd2FeeRatioPercent(d.getFeeRatio()), style);
|
||||||
setCell(row, 12, bd2Money(d.getTotalProfitBeforeTax()), style);
|
setCell(row, 12, bd2Money(d.getTotalProfitBeforeTax()), style);
|
||||||
setCell(row, 13, bd2Money(d.getSalesTaxAmount()), style);
|
BigDecimal salesTax = salesTaxOnNetForCategoryExport(d.getSalesAmount(), d.getRefundAmount(), taxRate);
|
||||||
|
BigDecimal profitAfterTax = (d.getTotalProfitBeforeTax() != null ? d.getTotalProfitBeforeTax() : BigDecimal.ZERO)
|
||||||
|
.subtract(salesTax)
|
||||||
|
.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
setCell(row, 13, bd2Money(salesTax), style);
|
||||||
setCell(row, 14, bd2Roi(d.getRoi()), style);
|
setCell(row, 14, bd2Roi(d.getRoi()), style);
|
||||||
setCell(row, 15, bd2Money(d.getProfitAfterTax()), style);
|
setCell(row, 15, bd2Money(profitAfterTax), style);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double bd2Money(BigDecimal v) {
|
private static double bd2Money(BigDecimal v) {
|
||||||
|
|||||||
+44
-17
@@ -85,6 +85,31 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
this.platformMapper = platformMapper;
|
this.platformMapper = platformMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 税额 = max(0, 销售额 − 退款) × 税率,保留两位小数。
|
||||||
|
*/
|
||||||
|
private BigDecimal salesTaxOnNetSales(BigDecimal salesAmount, BigDecimal refundAmount) {
|
||||||
|
BigDecimal sales = salesAmount != null ? salesAmount : BigDecimal.ZERO;
|
||||||
|
BigDecimal refund = refundAmount != null ? refundAmount : BigDecimal.ZERO;
|
||||||
|
BigDecimal base = sales.subtract(refund);
|
||||||
|
if (base.compareTo(BigDecimal.ZERO) < 0) {
|
||||||
|
base = BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
BigDecimal rate = taxRate != null ? taxRate : DEFAULT_TAX_RATE;
|
||||||
|
return base.multiply(rate).setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BigDecimal salesTaxOnNetSales(BigDecimal salesAmount, BigDecimal refundAmount, BigDecimal rate) {
|
||||||
|
BigDecimal sales = salesAmount != null ? salesAmount : BigDecimal.ZERO;
|
||||||
|
BigDecimal refund = refundAmount != null ? refundAmount : BigDecimal.ZERO;
|
||||||
|
BigDecimal base = sales.subtract(refund);
|
||||||
|
if (base.compareTo(BigDecimal.ZERO) < 0) {
|
||||||
|
base = BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
BigDecimal r = rate != null ? rate : DEFAULT_TAX_RATE;
|
||||||
|
return base.multiply(r).setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompanyOverviewVO getCompanyOverview(CompanyOverviewQueryDTO queryDTO) {
|
public CompanyOverviewVO getCompanyOverview(CompanyOverviewQueryDTO queryDTO) {
|
||||||
// 取请求参数中的税率,默认4%
|
// 取请求参数中的税率,默认4%
|
||||||
@@ -172,6 +197,10 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
overviewVO.setTotalSalesAmount(totalSalesAmount);
|
overviewVO.setTotalSalesAmount(totalSalesAmount);
|
||||||
|
|
||||||
|
BigDecimal totalRefundAmountCompany = orders.stream()
|
||||||
|
.map(stat::receivedForRefund)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
|
||||||
// 2. 计算较上月同期增长百分比
|
// 2. 计算较上月同期增长百分比
|
||||||
BigDecimal lastMonthSalesAmount = lastMonthOrders.stream()
|
BigDecimal lastMonthSalesAmount = lastMonthOrders.stream()
|
||||||
.map(stat::receivedForSales)
|
.map(stat::receivedForSales)
|
||||||
@@ -207,11 +236,11 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
}
|
}
|
||||||
overviewVO.setAverageFeeRatio(averageFeeRatio);
|
overviewVO.setAverageFeeRatio(averageFeeRatio);
|
||||||
|
|
||||||
// 6. 计算全店总净利(税后)和总税额:税前盈亏 = 订单维度毛利 − 推广费 − 刷单费;税额按销售额比例
|
// 6. 计算全店总净利(税后)和总税额:税前盈亏 = 订单维度毛利 − 推广费 − 刷单费;税额按 (销售额 − 退款) × 税率
|
||||||
BigDecimal totalProfitBeforeTax = calculateTotalProfit(orders, stat)
|
BigDecimal totalProfitBeforeTax = calculateTotalProfit(orders, stat)
|
||||||
.subtract(totalPromotionFee)
|
.subtract(totalPromotionFee)
|
||||||
.subtract(totalBrushFee);
|
.subtract(totalBrushFee);
|
||||||
BigDecimal totalTaxAmount = totalSalesAmount.multiply(taxRate);
|
BigDecimal totalTaxAmount = salesTaxOnNetSales(totalSalesAmount, totalRefundAmountCompany);
|
||||||
BigDecimal totalNetProfitAfterTax = totalProfitBeforeTax.subtract(totalTaxAmount).setScale(2, RoundingMode.HALF_UP);
|
BigDecimal totalNetProfitAfterTax = totalProfitBeforeTax.subtract(totalTaxAmount).setScale(2, RoundingMode.HALF_UP);
|
||||||
overviewVO.setTotalNetProfitAfterTax(totalNetProfitAfterTax);
|
overviewVO.setTotalNetProfitAfterTax(totalNetProfitAfterTax);
|
||||||
overviewVO.setTotalTaxAmount(totalTaxAmount);
|
overviewVO.setTotalTaxAmount(totalTaxAmount);
|
||||||
@@ -409,7 +438,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
BigDecimal roi = calculateSalesROI(shopSales.subtract(shopRefund), shopPromotionFee);
|
BigDecimal roi = calculateSalesROI(shopSales.subtract(shopRefund), shopPromotionFee);
|
||||||
BigDecimal profit = calculateShopProfit(shopOrders, stat, shopPromotionFee, shopBrushTotal);
|
BigDecimal profit = calculateShopProfit(shopOrders, stat, shopPromotionFee, shopBrushTotal);
|
||||||
BigDecimal netProfit = calculateShopNetProfit(profit, shopSales);
|
BigDecimal netProfit = calculateShopNetProfit(profit, shopSales, shopRefund);
|
||||||
|
|
||||||
allROIs.add(roi);
|
allROIs.add(roi);
|
||||||
allNetProfits.add(netProfit);
|
allNetProfits.add(netProfit);
|
||||||
@@ -442,7 +471,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
BigDecimal roi = calculateSalesROI(shopSales.subtract(shopRefund), shopPromotionFee);
|
BigDecimal roi = calculateSalesROI(shopSales.subtract(shopRefund), shopPromotionFee);
|
||||||
BigDecimal profit = calculateShopProfit(shopOrders, stat, shopPromotionFee, shopBrushTotal);
|
BigDecimal profit = calculateShopProfit(shopOrders, stat, shopPromotionFee, shopBrushTotal);
|
||||||
BigDecimal netProfit = calculateShopNetProfit(profit, shopSales);
|
BigDecimal netProfit = calculateShopNetProfit(profit, shopSales, shopRefund);
|
||||||
|
|
||||||
int quadrant;
|
int quadrant;
|
||||||
if (roi.compareTo(avgROI) >= 0 && netProfit.compareTo(avgNetProfit) >= 0) {
|
if (roi.compareTo(avgROI) >= 0 && netProfit.compareTo(avgNetProfit) >= 0) {
|
||||||
@@ -545,10 +574,9 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
BigDecimal profitBeforeTax = salesAmount.subtract(orderLineCost).subtract(refundAmount)
|
BigDecimal profitBeforeTax = salesAmount.subtract(orderLineCost).subtract(refundAmount)
|
||||||
.subtract(totalPromotionFee).subtract(brushFee);
|
.subtract(totalPromotionFee).subtract(brushFee);
|
||||||
|
|
||||||
// 销售额4%税额
|
BigDecimal salesTaxAmount = salesTaxOnNetSales(salesAmount, refundAmount);
|
||||||
BigDecimal salesTaxAmount = salesAmount.multiply(taxRate);
|
|
||||||
|
|
||||||
// 税后盈亏(扣除销售额4%税额)
|
// 税后盈亏(扣除税额)
|
||||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
||||||
|
|
||||||
BigDecimal roi = calculateSalesROI(salesAmount.subtract(refundAmount), totalPromotionFee);
|
BigDecimal roi = calculateSalesROI(salesAmount.subtract(refundAmount), totalPromotionFee);
|
||||||
@@ -663,7 +691,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
||||||
BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund)
|
BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund)
|
||||||
.subtract(totalPromoFee).subtract(totalBrushFee);
|
.subtract(totalPromoFee).subtract(totalBrushFee);
|
||||||
BigDecimal salesTax = totalSales.multiply(taxRate);
|
BigDecimal salesTax = salesTaxOnNetSales(totalSales, totalRefund);
|
||||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
||||||
BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
||||||
? totalSales.subtract(totalRefund).divide(totalPromoFee, 4, RoundingMode.HALF_UP)
|
? totalSales.subtract(totalRefund).divide(totalPromoFee, 4, RoundingMode.HALF_UP)
|
||||||
@@ -728,11 +756,10 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 店铺净利(税后):税额按「计入销售额」的销售额比例,与单店概览一致
|
* 店铺净利(税后):税额按 (销售额 − 退款) × 税率,与单店概览一致
|
||||||
*/
|
*/
|
||||||
private BigDecimal calculateShopNetProfit(BigDecimal profitBeforeTax, BigDecimal salesAmountForTax) {
|
private BigDecimal calculateShopNetProfit(BigDecimal profitBeforeTax, BigDecimal salesAmount, BigDecimal refundAmount) {
|
||||||
BigDecimal salesAmount = salesAmountForTax != null ? salesAmountForTax : BigDecimal.ZERO;
|
return profitBeforeTax.subtract(salesTaxOnNetSales(salesAmount, refundAmount));
|
||||||
return profitBeforeTax.subtract(salesAmount.multiply(taxRate));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -882,7 +909,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
BigDecimal totalCost = productCost.add(shippingCost).add(otherCost);
|
BigDecimal totalCost = productCost.add(shippingCost).add(otherCost);
|
||||||
BigDecimal profitBeforeTax = salesAmount.subtract(totalCost).subtract(refundAmount)
|
BigDecimal profitBeforeTax = salesAmount.subtract(totalCost).subtract(refundAmount)
|
||||||
.subtract(totalPromotionFee).subtract(totalBrushFee);
|
.subtract(totalPromotionFee).subtract(totalBrushFee);
|
||||||
BigDecimal salesTaxAmount = salesAmount.multiply(taxRate);
|
BigDecimal salesTaxAmount = salesTaxOnNetSales(salesAmount, refundAmount);
|
||||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
||||||
|
|
||||||
BigDecimal roi = BigDecimal.ZERO;
|
BigDecimal roi = BigDecimal.ZERO;
|
||||||
@@ -965,7 +992,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
||||||
BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund)
|
BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund)
|
||||||
.subtract(totalPromoFee).subtract(totalBrushFee);
|
.subtract(totalPromoFee).subtract(totalBrushFee);
|
||||||
BigDecimal salesTax = totalSales.multiply(taxRate);
|
BigDecimal salesTax = salesTaxOnNetSales(totalSales, totalRefund);
|
||||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
||||||
BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
||||||
? totalSales.subtract(totalRefund).divide(totalPromoFee, 4, RoundingMode.HALF_UP)
|
? totalSales.subtract(totalRefund).divide(totalPromoFee, 4, RoundingMode.HALF_UP)
|
||||||
@@ -1139,7 +1166,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
||||||
BigDecimal profitBeforeTax = totalSalesAmount.subtract(totalCost).subtract(totalRefundAmount)
|
BigDecimal profitBeforeTax = totalSalesAmount.subtract(totalCost).subtract(totalRefundAmount)
|
||||||
.subtract(totalPromotionFee).subtract(totalBrushFee);
|
.subtract(totalPromotionFee).subtract(totalBrushFee);
|
||||||
BigDecimal salesTaxAmount = totalSalesAmount.multiply(taxRate);
|
BigDecimal salesTaxAmount = salesTaxOnNetSales(totalSalesAmount, totalRefundAmount);
|
||||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
||||||
|
|
||||||
BigDecimal roi = BigDecimal.ZERO;
|
BigDecimal roi = BigDecimal.ZERO;
|
||||||
@@ -1253,7 +1280,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
||||||
BigDecimal profitBeforeTax = totalSalesAmount.subtract(totalCost).subtract(totalRefundAmount)
|
BigDecimal profitBeforeTax = totalSalesAmount.subtract(totalCost).subtract(totalRefundAmount)
|
||||||
.subtract(totalPromotionFee).subtract(totalBrushFee);
|
.subtract(totalPromotionFee).subtract(totalBrushFee);
|
||||||
BigDecimal salesTax = totalSalesAmount.multiply(this.taxRate);
|
BigDecimal salesTax = salesTaxOnNetSales(totalSalesAmount, totalRefundAmount);
|
||||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
||||||
BigDecimal roi = totalPromotionFee.compareTo(BigDecimal.ZERO) > 0
|
BigDecimal roi = totalPromotionFee.compareTo(BigDecimal.ZERO) > 0
|
||||||
? totalSalesAmount.subtract(totalRefundAmount).divide(totalPromotionFee, 4, RoundingMode.HALF_UP)
|
? totalSalesAmount.subtract(totalRefundAmount).divide(totalPromotionFee, 4, RoundingMode.HALF_UP)
|
||||||
@@ -1376,7 +1403,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
||||||
BigDecimal profitBeforeTax = totalSalesAmount.subtract(totalCost).subtract(totalRefundAmount)
|
BigDecimal profitBeforeTax = totalSalesAmount.subtract(totalCost).subtract(totalRefundAmount)
|
||||||
.subtract(totalPromotionFee).subtract(totalBrushFee);
|
.subtract(totalPromotionFee).subtract(totalBrushFee);
|
||||||
BigDecimal salesTaxAmount = totalSalesAmount.multiply(taxRate);
|
BigDecimal salesTaxAmount = salesTaxOnNetSales(totalSalesAmount, totalRefundAmount, taxRate);
|
||||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
||||||
BigDecimal roi = totalPromotionFee.compareTo(BigDecimal.ZERO) > 0
|
BigDecimal roi = totalPromotionFee.compareTo(BigDecimal.ZERO) > 0
|
||||||
? totalSalesAmount.subtract(totalRefundAmount).divide(totalPromotionFee, 4, RoundingMode.HALF_UP)
|
? totalSalesAmount.subtract(totalRefundAmount).divide(totalPromotionFee, 4, RoundingMode.HALF_UP)
|
||||||
|
|||||||
+43
-7
@@ -178,11 +178,11 @@ public class ExportServiceImpl implements ExportService {
|
|||||||
int rowIdx = 2;
|
int rowIdx = 2;
|
||||||
for (Map<String, Object> data : dataList) {
|
for (Map<String, Object> data : dataList) {
|
||||||
Row row = sheet.createRow(rowIdx++);
|
Row row = sheet.createRow(rowIdx++);
|
||||||
writeOverviewDetailRow(row, data, dataStyle, firstColumnValue.apply(data));
|
writeOverviewDetailRow(row, data, dataStyle, firstColumnValue.apply(data), taxRate);
|
||||||
}
|
}
|
||||||
if (totalRowMap != null) {
|
if (totalRowMap != null) {
|
||||||
Row row = sheet.createRow(rowIdx);
|
Row row = sheet.createRow(rowIdx);
|
||||||
writeOverviewDetailRow(row, totalRowMap, boldStyle, firstColumnValue.apply(totalRowMap));
|
writeOverviewDetailRow(row, totalRowMap, boldStyle, firstColumnValue.apply(totalRowMap), taxRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < headers.length; i++) {
|
for (int i = 0; i < headers.length; i++) {
|
||||||
@@ -190,7 +190,8 @@ public class ExportServiceImpl implements ExportService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeOverviewDetailRow(Row row, Map<String, Object> data, CellStyle style, String firstColumnText) {
|
private void writeOverviewDetailRow(
|
||||||
|
Row row, Map<String, Object> data, CellStyle style, String firstColumnText, BigDecimal taxRate) {
|
||||||
setCell(row, 0, firstColumnText, style);
|
setCell(row, 0, firstColumnText, style);
|
||||||
setCell(row, 1, objToDouble(data.get("targetOrderCount")), style);
|
setCell(row, 1, objToDouble(data.get("targetOrderCount")), style);
|
||||||
setCell(row, 2, objToPct(data.get("orderCountAchievementRate")), style);
|
setCell(row, 2, objToPct(data.get("orderCountAchievementRate")), style);
|
||||||
@@ -208,9 +209,32 @@ public class ExportServiceImpl implements ExportService {
|
|||||||
setCell(row, 14, objToDouble(data.get("brushFee")), style);
|
setCell(row, 14, objToDouble(data.get("brushFee")), style);
|
||||||
setCell(row, 15, objToDouble(data.get("feeRatio")), style);
|
setCell(row, 15, objToDouble(data.get("feeRatio")), style);
|
||||||
setCell(row, 16, objToDouble(data.get("totalProfitBeforeTax")), style);
|
setCell(row, 16, objToDouble(data.get("totalProfitBeforeTax")), style);
|
||||||
setCell(row, 17, objToDouble(data.get("salesTaxAmount")), style);
|
BigDecimal salesTax = salesTaxOnNetForExport(
|
||||||
|
mapToBigDecimal(data.get("salesAmount")),
|
||||||
|
mapToBigDecimal(data.get("refundAmount")),
|
||||||
|
taxRate);
|
||||||
|
BigDecimal profitAfterTax = mapToBigDecimal(data.get("totalProfitBeforeTax"))
|
||||||
|
.subtract(salesTax)
|
||||||
|
.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
setCell(row, 17, salesTax.doubleValue(), style);
|
||||||
setCell(row, 18, objToDouble(data.get("roi")), style);
|
setCell(row, 18, objToDouble(data.get("roi")), style);
|
||||||
setCell(row, 19, objToDouble(data.get("profitAfterTax")), style);
|
setCell(row, 19, profitAfterTax.doubleValue(), style);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BigDecimal mapToBigDecimal(Object val) {
|
||||||
|
if (val == null) {
|
||||||
|
return BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
if (val instanceof BigDecimal) {
|
||||||
|
return (BigDecimal) val;
|
||||||
|
}
|
||||||
|
if (val instanceof Integer) {
|
||||||
|
return BigDecimal.valueOf((Integer) val);
|
||||||
|
}
|
||||||
|
if (val instanceof Long) {
|
||||||
|
return BigDecimal.valueOf((Long) val);
|
||||||
|
}
|
||||||
|
return BigDecimal.ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Object> shopSummaryToRowMap(CompanyOverviewVO.ShopSummary s) {
|
private Map<String, Object> shopSummaryToRowMap(CompanyOverviewVO.ShopSummary s) {
|
||||||
@@ -238,6 +262,18 @@ public class ExportServiceImpl implements ExportService {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 与全店概览一致:税额 = max(0, 销售额 − 退款) × 税率,两位小数。 */
|
||||||
|
private static BigDecimal salesTaxOnNetForExport(BigDecimal sales, BigDecimal refund, BigDecimal taxRate) {
|
||||||
|
BigDecimal s = sales != null ? sales : BigDecimal.ZERO;
|
||||||
|
BigDecimal rfd = refund != null ? refund : BigDecimal.ZERO;
|
||||||
|
BigDecimal r = taxRate != null ? taxRate : new BigDecimal("0.04");
|
||||||
|
BigDecimal base = s.subtract(rfd);
|
||||||
|
if (base.compareTo(BigDecimal.ZERO) < 0) {
|
||||||
|
base = BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
return base.multiply(r).setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
private CompanyOverviewVO.ShopSummary aggregateShopSummariesForExport(
|
private CompanyOverviewVO.ShopSummary aggregateShopSummariesForExport(
|
||||||
List<CompanyOverviewVO.ShopSummary> shops, BigDecimal taxRate) {
|
List<CompanyOverviewVO.ShopSummary> shops, BigDecimal taxRate) {
|
||||||
BigDecimal totalSales = BigDecimal.ZERO;
|
BigDecimal totalSales = BigDecimal.ZERO;
|
||||||
@@ -270,7 +306,7 @@ public class ExportServiceImpl implements ExportService {
|
|||||||
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
||||||
BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund)
|
BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund)
|
||||||
.subtract(totalPromoFee).subtract(totalBrushFee);
|
.subtract(totalPromoFee).subtract(totalBrushFee);
|
||||||
BigDecimal salesTax = totalSales.multiply(taxRate);
|
BigDecimal salesTax = salesTaxOnNetForExport(totalSales, totalRefund, taxRate);
|
||||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
||||||
BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
||||||
? totalSales.subtract(totalRefund).divide(totalPromoFee, 4, RoundingMode.HALF_UP)
|
? totalSales.subtract(totalRefund).divide(totalPromoFee, 4, RoundingMode.HALF_UP)
|
||||||
@@ -368,7 +404,7 @@ public class ExportServiceImpl implements ExportService {
|
|||||||
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
||||||
BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund)
|
BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund)
|
||||||
.subtract(totalPromoFee).subtract(totalBrushFee);
|
.subtract(totalPromoFee).subtract(totalBrushFee);
|
||||||
BigDecimal salesTax = totalSales.multiply(taxRate);
|
BigDecimal salesTax = salesTaxOnNetForExport(totalSales, totalRefund, taxRate);
|
||||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
||||||
BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
||||||
? totalSales.subtract(totalRefund).divide(totalPromoFee, 4, RoundingMode.HALF_UP)
|
? totalSales.subtract(totalRefund).divide(totalPromoFee, 4, RoundingMode.HALF_UP)
|
||||||
|
|||||||
+20
-7
@@ -83,6 +83,19 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
|||||||
this.categoryService = categoryService;
|
this.categoryService = categoryService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 税额 = max(0, 销售额 − 退款) × 当前税率,四舍五入保留两位小数(与税后盈亏扣减口径一致)。
|
||||||
|
*/
|
||||||
|
private BigDecimal toSalesTaxAmount(BigDecimal salesAmount, BigDecimal refundAmount) {
|
||||||
|
BigDecimal sales = salesAmount != null ? salesAmount : BigDecimal.ZERO;
|
||||||
|
BigDecimal refund = refundAmount != null ? refundAmount : BigDecimal.ZERO;
|
||||||
|
BigDecimal base = sales.subtract(refund);
|
||||||
|
if (base.compareTo(BigDecimal.ZERO) < 0) {
|
||||||
|
base = BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
return base.multiply(taxRate).setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ShopOverviewStatisticsVO getShopOverviewStatistics(ShopOverviewQueryDTO queryDTO) {
|
public ShopOverviewStatisticsVO getShopOverviewStatistics(ShopOverviewQueryDTO queryDTO) {
|
||||||
// 取请求参数中的税率,默认4%
|
// 取请求参数中的税率,默认4%
|
||||||
@@ -229,7 +242,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
|||||||
.subtract(totalPromotionFee)
|
.subtract(totalPromotionFee)
|
||||||
.subtract(totalBrushFee);
|
.subtract(totalBrushFee);
|
||||||
overviewVO.setTotalProfitBeforeTax(totalProfitBeforeTax);
|
overviewVO.setTotalProfitBeforeTax(totalProfitBeforeTax);
|
||||||
BigDecimal totalSalesTaxAmount = totalSalesAmount.multiply(taxRate);
|
BigDecimal totalSalesTaxAmount = toSalesTaxAmount(totalSalesAmount, refundAmountAgg);
|
||||||
BigDecimal totalNetProfitAfterTax = totalProfitBeforeTax.subtract(totalSalesTaxAmount);
|
BigDecimal totalNetProfitAfterTax = totalProfitBeforeTax.subtract(totalSalesTaxAmount);
|
||||||
overviewVO.setTotalNetProfitAfterTax(totalNetProfitAfterTax.setScale(2, RoundingMode.HALF_UP));
|
overviewVO.setTotalNetProfitAfterTax(totalNetProfitAfterTax.setScale(2, RoundingMode.HALF_UP));
|
||||||
overviewVO.setTotalTaxAmount(totalSalesTaxAmount);
|
overviewVO.setTotalTaxAmount(totalSalesTaxAmount);
|
||||||
@@ -512,10 +525,10 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
|||||||
BigDecimal profitBeforeTax = salesAmount.subtract(totalCost).subtract(refundAmount)
|
BigDecimal profitBeforeTax = salesAmount.subtract(totalCost).subtract(refundAmount)
|
||||||
.subtract(productPromotionFee).subtract(brushFee);
|
.subtract(productPromotionFee).subtract(brushFee);
|
||||||
|
|
||||||
// 销售额4%税额
|
// (销售额 − 退款) × 税率,税额保留两位小数
|
||||||
BigDecimal salesTaxAmount = salesAmount.multiply(taxRate);
|
BigDecimal salesTaxAmount = toSalesTaxAmount(salesAmount, refundAmount);
|
||||||
|
|
||||||
// 税后盈亏(扣除销售额4%税额)
|
// 税后盈亏(扣除税额)
|
||||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
||||||
|
|
||||||
BigDecimal roi = calculateSalesROI(salesAmount.subtract(refundAmount), productPromotionFee);
|
BigDecimal roi = calculateSalesROI(salesAmount.subtract(refundAmount), productPromotionFee);
|
||||||
@@ -595,7 +608,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
|||||||
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
||||||
BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund)
|
BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund)
|
||||||
.subtract(totalPromoFee).subtract(totalBrushFee);
|
.subtract(totalPromoFee).subtract(totalBrushFee);
|
||||||
BigDecimal salesTax = totalSales.multiply(taxRate);
|
BigDecimal salesTax = toSalesTaxAmount(totalSales, totalRefund);
|
||||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
||||||
BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
||||||
? totalSales.subtract(totalRefund).divide(totalPromoFee, 2, RoundingMode.HALF_UP)
|
? totalSales.subtract(totalRefund).divide(totalPromoFee, 2, RoundingMode.HALF_UP)
|
||||||
@@ -835,7 +848,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
|||||||
BigDecimal totalCost = productCost.add(shippingCost).add(otherCost);
|
BigDecimal totalCost = productCost.add(shippingCost).add(otherCost);
|
||||||
BigDecimal profitBeforeTax = salesAmount.subtract(totalCost).subtract(refundAmount)
|
BigDecimal profitBeforeTax = salesAmount.subtract(totalCost).subtract(refundAmount)
|
||||||
.subtract(catPromotionFee).subtract(catBrushFee);
|
.subtract(catPromotionFee).subtract(catBrushFee);
|
||||||
BigDecimal salesTaxAmount = salesAmount.multiply(taxRate);
|
BigDecimal salesTaxAmount = toSalesTaxAmount(salesAmount, refundAmount);
|
||||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
||||||
|
|
||||||
BigDecimal roi = calculateSalesROI(salesAmount.subtract(refundAmount), catPromotionFee);
|
BigDecimal roi = calculateSalesROI(salesAmount.subtract(refundAmount), catPromotionFee);
|
||||||
@@ -912,7 +925,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
|||||||
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
||||||
BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund)
|
BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund)
|
||||||
.subtract(totalPromoFee).subtract(totalBrushFee);
|
.subtract(totalPromoFee).subtract(totalBrushFee);
|
||||||
BigDecimal salesTax = totalSales.multiply(taxRate);
|
BigDecimal salesTax = toSalesTaxAmount(totalSales, totalRefund);
|
||||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
||||||
BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
||||||
? totalSales.subtract(totalRefund).divide(totalPromoFee, 2, RoundingMode.HALF_UP)
|
? totalSales.subtract(totalRefund).divide(totalPromoFee, 2, RoundingMode.HALF_UP)
|
||||||
|
|||||||
+17
-8
@@ -58,6 +58,18 @@ public class ProductOverviewServiceImpl implements ProductOverviewService {
|
|||||||
this.shopMonthlyTargetMapper = shopMonthlyTargetMapper;
|
this.shopMonthlyTargetMapper = shopMonthlyTargetMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 税额 = max(0, 销售额 − 退款) × 税率,保留两位小数。 */
|
||||||
|
private static BigDecimal salesTaxOnNetSales(BigDecimal salesAmount, BigDecimal refundAmount, BigDecimal taxRate) {
|
||||||
|
BigDecimal sales = salesAmount != null ? salesAmount : BigDecimal.ZERO;
|
||||||
|
BigDecimal refund = refundAmount != null ? refundAmount : BigDecimal.ZERO;
|
||||||
|
BigDecimal rate = taxRate != null ? taxRate : new BigDecimal("0.04");
|
||||||
|
BigDecimal base = sales.subtract(refund);
|
||||||
|
if (base.compareTo(BigDecimal.ZERO) < 0) {
|
||||||
|
base = BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
return base.multiply(rate).setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProductOverviewVO getProductOverview(ProductOverviewQueryDTO queryDTO) {
|
public ProductOverviewVO getProductOverview(ProductOverviewQueryDTO queryDTO) {
|
||||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
@@ -184,9 +196,7 @@ public class ProductOverviewServiceImpl implements ProductOverviewService {
|
|||||||
vo.setAverageFeeRatio(avgFeeRatio.multiply(new BigDecimal("100"))
|
vo.setAverageFeeRatio(avgFeeRatio.multiply(new BigDecimal("100"))
|
||||||
.setScale(2, RoundingMode.HALF_UP)); // 转为百分比
|
.setScale(2, RoundingMode.HALF_UP)); // 转为百分比
|
||||||
|
|
||||||
// 税额 = 销售额 × 税率
|
BigDecimal totalTaxAmount = salesTaxOnNetSales(totalSalesAmount, totalRefundAmount, taxRate);
|
||||||
BigDecimal totalTaxAmount = totalSalesAmount.multiply(taxRate)
|
|
||||||
.setScale(2, RoundingMode.HALF_UP);
|
|
||||||
vo.setTotalTaxAmount(totalTaxAmount);
|
vo.setTotalTaxAmount(totalTaxAmount);
|
||||||
|
|
||||||
// 税后盈亏
|
// 税后盈亏
|
||||||
@@ -457,9 +467,7 @@ public class ProductOverviewServiceImpl implements ProductOverviewService {
|
|||||||
.subtract(refundAmount)
|
.subtract(refundAmount)
|
||||||
.subtract(specPromotionFee);
|
.subtract(specPromotionFee);
|
||||||
|
|
||||||
// 税额
|
BigDecimal salesTaxAmount = salesTaxOnNetSales(salesAmount, refundAmount, taxRate);
|
||||||
BigDecimal salesTaxAmount = salesAmount.multiply(taxRate)
|
|
||||||
.setScale(2, RoundingMode.HALF_UP);
|
|
||||||
|
|
||||||
// ROI = (销售额 - 退款) / 推广费
|
// ROI = (销售额 - 退款) / 推广费
|
||||||
BigDecimal roi = specPromotionFee.compareTo(BigDecimal.ZERO) > 0
|
BigDecimal roi = specPromotionFee.compareTo(BigDecimal.ZERO) > 0
|
||||||
@@ -536,10 +544,11 @@ public class ProductOverviewServiceImpl implements ProductOverviewService {
|
|||||||
.subtract(total.getPromotionFee());
|
.subtract(total.getPromotionFee());
|
||||||
total.setProfitBeforeTax(totalProfitBT);
|
total.setProfitBeforeTax(totalProfitBT);
|
||||||
|
|
||||||
BigDecimal totalSalesTax = totalSalesAmt.multiply(taxRate).setScale(2, RoundingMode.HALF_UP);
|
BigDecimal totalRefundAgg = total.getRefundAmount();
|
||||||
|
BigDecimal totalSalesTax = salesTaxOnNetSales(totalSalesAmt, totalRefundAgg, taxRate);
|
||||||
total.setSalesTaxAmount(totalSalesTax);
|
total.setSalesTaxAmount(totalSalesTax);
|
||||||
|
|
||||||
BigDecimal totalRefundForRoi = total.getRefundAmount();
|
BigDecimal totalRefundForRoi = totalRefundAgg;
|
||||||
BigDecimal totalRoi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
BigDecimal totalRoi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
||||||
? totalSalesAmt.subtract(totalRefundForRoi)
|
? totalSalesAmt.subtract(totalRefundForRoi)
|
||||||
.divide(totalPromoFee, 4, RoundingMode.HALF_UP)
|
.divide(totalPromoFee, 4, RoundingMode.HALF_UP)
|
||||||
|
|||||||
+22
-5
@@ -29,6 +29,18 @@ public class ShopExportServiceImpl implements ShopExportService {
|
|||||||
private static final BigDecimal DEFAULT_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 static final DateTimeFormatter DATE_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
|
|
||||||
|
/** 与店铺概览一致:税额 = max(0, 销售额 − 退款) × 税率,两位小数。 */
|
||||||
|
private static BigDecimal salesTaxOnNetForShopExport(BigDecimal sales, BigDecimal refund, BigDecimal taxRate) {
|
||||||
|
BigDecimal s = sales != null ? sales : BigDecimal.ZERO;
|
||||||
|
BigDecimal rfd = refund != null ? refund : BigDecimal.ZERO;
|
||||||
|
BigDecimal r = taxRate != null ? taxRate : DEFAULT_TAX_RATE;
|
||||||
|
BigDecimal base = s.subtract(rfd);
|
||||||
|
if (base.compareTo(BigDecimal.ZERO) < 0) {
|
||||||
|
base = BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
return base.multiply(r).setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
private final ShopOverviewStatisticsService shopOverviewStatisticsService;
|
private final ShopOverviewStatisticsService shopOverviewStatisticsService;
|
||||||
private final CategoryExportExcelService categoryExportExcelService;
|
private final CategoryExportExcelService categoryExportExcelService;
|
||||||
|
|
||||||
@@ -134,10 +146,10 @@ public class ShopExportServiceImpl implements ShopExportService {
|
|||||||
int rowIdx = 2;
|
int rowIdx = 2;
|
||||||
for (ShopOverviewStatisticsVO.ProductSummary p : products) {
|
for (ShopOverviewStatisticsVO.ProductSummary p : products) {
|
||||||
Row row = sheet.createRow(rowIdx++);
|
Row row = sheet.createRow(rowIdx++);
|
||||||
fillProductDataRow(row, p, dataStyle, false);
|
fillProductDataRow(row, p, dataStyle, false, taxRate);
|
||||||
}
|
}
|
||||||
if (totalRow != null) {
|
if (totalRow != null) {
|
||||||
fillProductDataRow(sheet.createRow(rowIdx), totalRow, totalStyle, true);
|
fillProductDataRow(sheet.createRow(rowIdx), totalRow, totalStyle, true, taxRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
sheet.setColumnWidth(0, 5200);
|
sheet.setColumnWidth(0, 5200);
|
||||||
@@ -150,7 +162,8 @@ public class ShopExportServiceImpl implements ShopExportService {
|
|||||||
Row row,
|
Row row,
|
||||||
ShopOverviewStatisticsVO.ProductSummary p,
|
ShopOverviewStatisticsVO.ProductSummary p,
|
||||||
CellStyle style,
|
CellStyle style,
|
||||||
boolean isTotalRow) {
|
boolean isTotalRow,
|
||||||
|
BigDecimal taxRate) {
|
||||||
String nameCol = isTotalRow
|
String nameCol = isTotalRow
|
||||||
? "合计"
|
? "合计"
|
||||||
: (p.getProductName() != null ? p.getProductName() : "")
|
: (p.getProductName() != null ? p.getProductName() : "")
|
||||||
@@ -174,8 +187,12 @@ public class ShopExportServiceImpl implements ShopExportService {
|
|||||||
setCell(row, 11, feePct, style);
|
setCell(row, 11, feePct, style);
|
||||||
setCell(row, 12, nvl(p.getRoi(), BigDecimal.ZERO).setScale(4, RoundingMode.HALF_UP).doubleValue(), style);
|
setCell(row, 12, nvl(p.getRoi(), BigDecimal.ZERO).setScale(4, RoundingMode.HALF_UP).doubleValue(), style);
|
||||||
setCell(row, 13, nvl(p.getTotalProfitBeforeTax(), BigDecimal.ZERO).setScale(2, RoundingMode.HALF_UP).doubleValue(), style);
|
setCell(row, 13, nvl(p.getTotalProfitBeforeTax(), BigDecimal.ZERO).setScale(2, RoundingMode.HALF_UP).doubleValue(), style);
|
||||||
setCell(row, 14, nvl(p.getSalesTaxAmount(), BigDecimal.ZERO).setScale(2, RoundingMode.HALF_UP).doubleValue(), style);
|
BigDecimal salesTax = salesTaxOnNetForShopExport(p.getSalesAmount(), p.getRefundAmount(), taxRate);
|
||||||
setCell(row, 15, nvl(p.getProfitAfterTax(), BigDecimal.ZERO).setScale(2, RoundingMode.HALF_UP).doubleValue(), style);
|
BigDecimal profitAfterTax = nvl(p.getTotalProfitBeforeTax(), BigDecimal.ZERO)
|
||||||
|
.subtract(salesTax)
|
||||||
|
.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
setCell(row, 14, salesTax.doubleValue(), style);
|
||||||
|
setCell(row, 15, profitAfterTax.doubleValue(), style);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createTrendSheetFromVO(Sheet sheet, String dateRangeLabel, ShopOverviewStatisticsVO vo) {
|
private void createTrendSheetFromVO(Sheet sheet, String dateRangeLabel, ShopOverviewStatisticsVO vo) {
|
||||||
|
|||||||
@@ -51,5 +51,5 @@ export const storeOverviewHints = overviewTableHints;
|
|||||||
|
|
||||||
export function salesTaxColumnHint(taxRate: number): string {
|
export function salesTaxColumnHint(taxRate: number): string {
|
||||||
const pct = (taxRate * 100).toFixed(0);
|
const pct = (taxRate * 100).toFixed(0);
|
||||||
return `税额 = 销售额 × ${pct}%(与当前页面所选税率一致,由后端按该税率计算)。`;
|
return `税额 = (销售额 - 退款金额) × ${pct}%(与当前页面所选税率一致,由后端按该税率计算)。`;
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
|
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
|
||||||
|
|
||||||
|
import { createIconifyIcon } from '@vben/icons';
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
|
|
||||||
import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio';
|
import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio';
|
||||||
@@ -12,6 +13,8 @@ import {
|
|||||||
storeOverviewHints,
|
storeOverviewHints,
|
||||||
} from '#/utils/overview-table-hints';
|
} from '#/utils/overview-table-hints';
|
||||||
|
|
||||||
|
const JumpIcon = createIconifyIcon('tdesign:jump');
|
||||||
|
|
||||||
defineOptions({ name: 'ShopComparisonTable' });
|
defineOptions({ name: 'ShopComparisonTable' });
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -275,10 +278,11 @@ const cellRoi = (v: number | null | undefined) =>
|
|||||||
:class="shopExportMode ? 'border-l-0' : ''"
|
:class="shopExportMode ? 'border-l-0' : ''"
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
class="inline-block cursor-pointer rounded-full bg-blue-50 dark:bg-blue-900/30 px-3 py-1 text-sm font-bold text-blue-600 dark:text-blue-400 transition-colors hover:text-blue-300 hover:underline"
|
class="inline-flex cursor-pointer items-center gap-1 rounded-full bg-blue-50 dark:bg-blue-900/30 px-3 py-1 text-sm font-bold text-blue-600 dark:text-blue-400 transition-colors hover:text-blue-300 hover:underline"
|
||||||
@click="emit('navigate', shop.shopId)"
|
@click="emit('navigate', shop.shopId)"
|
||||||
>
|
>
|
||||||
{{ shop.shopName }}
|
{{ shop.shopName }}
|
||||||
|
<JumpIcon class="text-xs" />
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<!-- 目标 -->
|
<!-- 目标 -->
|
||||||
|
|||||||
+7
-1
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||||
|
import { createIconifyIcon } from '@vben/icons';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
import { Button } from 'ant-design-vue';
|
import { Button } from 'ant-design-vue';
|
||||||
@@ -18,6 +19,8 @@ import {
|
|||||||
|
|
||||||
import OverviewColumnHint from '#/components/overview/OverviewColumnHint.vue';
|
import OverviewColumnHint from '#/components/overview/OverviewColumnHint.vue';
|
||||||
|
|
||||||
|
const JumpIcon = createIconifyIcon('tdesign:jump');
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
data: ShopVO.OverviewStatistics | null;
|
data: ShopVO.OverviewStatistics | null;
|
||||||
taxRate: number;
|
taxRate: number;
|
||||||
@@ -187,7 +190,10 @@ function goToProductOverview(productId: number) {
|
|||||||
style="left: 0; position: sticky; z-index: 10;"
|
style="left: 0; position: sticky; z-index: 10;"
|
||||||
@click="goToProductOverview(product.productId)"
|
@click="goToProductOverview(product.productId)"
|
||||||
>
|
>
|
||||||
<span class="inline-block rounded-full bg-blue-50 dark:bg-blue-900/30 px-3 py-1 text-sm font-bold text-blue-600 dark:text-blue-400">{{ product.productName }}</span>
|
<span class="inline-flex items-center gap-1 rounded-full bg-blue-50 dark:bg-blue-900/30 px-3 py-1 text-sm font-bold text-blue-600 dark:text-blue-400">
|
||||||
|
{{ product.productName }}
|
||||||
|
<JumpIcon class="text-xs" />
|
||||||
|
</span>
|
||||||
<div
|
<div
|
||||||
v-if="product.productCode"
|
v-if="product.productCode"
|
||||||
class="mt-0.5 font-mono text-xs text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
class="mt-0.5 font-mono text-xs text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||||
|
|||||||
Reference in New Issue
Block a user