feat: 完善公司全店概览

This commit is contained in:
ah--desktop
2026-01-12 23:55:21 +08:00
parent 59a649f002
commit 290223fdba
22 changed files with 2457 additions and 324 deletions
@@ -0,0 +1,76 @@
package top.xyquan.ecomdmbbackend.modules.ecom.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import top.xyquan.ecomdmbbackend.common.annotation.RequireRole;
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shopmonthlytarget.CreateShopMonthlyTargetDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shopmonthlytarget.ShopMonthlyTargetFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shopmonthlytarget.UpdateShopMonthlyTargetDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopMonthlyTargetVO;
import top.xyquan.ecomdmbbackend.modules.ecom.service.ShopMonthlyTargetService;
/**
* 店铺月销量目标管理控制器
*/
@Tag(name = "电商-店铺月销量目标管理", description = "店铺月销量目标的增删改查接口")
@RestController
@RequestMapping("/ec/shop-monthly-target")
public class ShopMonthlyTargetController {
private final ShopMonthlyTargetService shopMonthlyTargetService;
public ShopMonthlyTargetController(ShopMonthlyTargetService shopMonthlyTargetService) {
this.shopMonthlyTargetService = shopMonthlyTargetService;
}
@Operation(summary = "创建店铺月销量目标", description = "创建新的店铺月销量目标")
@PostMapping("/create")
@RequireRole(description = "创建店铺月销量目标", allowUser = false)
public ApiResponse<ShopMonthlyTargetVO> createShopMonthlyTarget(@Valid @RequestBody CreateShopMonthlyTargetDTO createDTO) {
ShopMonthlyTargetVO vo = shopMonthlyTargetService.createShopMonthlyTarget(createDTO);
return ApiResponse.success(vo);
}
@Operation(summary = "更新店铺月销量目标", description = "更新现有店铺月销量目标信息")
@PutMapping("/update/{id}")
@RequireRole(description = "更新店铺月销量目标", allowUser = false)
public ApiResponse<ShopMonthlyTargetVO> updateShopMonthlyTarget(@Valid @RequestBody UpdateShopMonthlyTargetDTO updateDTO,
@Parameter(description = "目标ID") @PathVariable Long id) {
ShopMonthlyTargetVO vo = shopMonthlyTargetService.updateShopMonthlyTarget(updateDTO, id);
return ApiResponse.success(vo);
}
@Operation(summary = "删除店铺月销量目标", description = "删除指定店铺月销量目标")
@DeleteMapping("/delete/{id}")
@RequireRole(description = "删除店铺月销量目标", allowUser = false)
public ApiResponse<Void> deleteShopMonthlyTarget(
@Parameter(description = "目标ID") @PathVariable Long id) {
shopMonthlyTargetService.deleteShopMonthlyTarget(id);
return ApiResponse.success();
}
@Operation(summary = "分页获取店铺月销量目标列表", description = "分页获取店铺月销量目标列表,支持条件过滤")
@PostMapping("/page")
@RequireRole(description = "查询店铺月销量目标列表", allowUser = true)
public ApiResponse<PageResultVO<ShopMonthlyTargetVO>> getShopMonthlyTargetPage(
@Valid @RequestBody PageQueryDTO<ShopMonthlyTargetFilterDTO> pageQueryDTO) {
PageResultVO<ShopMonthlyTargetVO> result = shopMonthlyTargetService.getShopMonthlyTargetPage(pageQueryDTO);
return ApiResponse.success(result);
}
@Operation(summary = "获取店铺月销量目标详情", description = "根据ID获取店铺月销量目标详情")
@GetMapping("/detail/{id}")
@RequireRole(description = "查询店铺月销量目标详情", allowUser = true)
public ApiResponse<ShopMonthlyTargetVO> getShopMonthlyTargetById(
@Parameter(description = "目标ID") @PathVariable Long id) {
ShopMonthlyTargetVO vo = shopMonthlyTargetService.getShopMonthlyTargetById(id);
return ApiResponse.success(vo);
}
}
@@ -0,0 +1,13 @@
package top.xyquan.ecomdmbbackend.modules.ecom.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopMonthlyTargetPO;
/**
* 店铺月销量目标Mapper接口
*/
@Mapper
public interface ShopMonthlyTargetMapper extends BaseMapper<ShopMonthlyTargetPO> {
}
@@ -0,0 +1,54 @@
package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shopmonthlytarget;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.PositiveOrZero;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDate;
/**
* 创建店铺月销量目标DTO
*/
@Data
@Schema(description = "创建店铺月销量目标DTO")
public class CreateShopMonthlyTargetDTO {
/**
* 店铺ID
*/
@Schema(description = "店铺ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "店铺ID不能为空")
private Long shopId;
/**
* 目标月份(格式:YYYY-MM-01)
*/
@Schema(description = "目标月份", example = "2024-01-01", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "目标月份不能为空")
private LocalDate targetMonth;
/**
* 目标销售额
*/
@Schema(description = "目标销售额", example = "100000.00", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "目标销售额不能为空")
@PositiveOrZero(message = "目标销售额必须大于等于0")
private BigDecimal targetAmount;
/**
* 目标订单数
*/
@Schema(description = "目标订单数", example = "1000", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "目标订单数不能为空")
@PositiveOrZero(message = "目标订单数必须大于等于0")
private Integer targetOrderCount;
/**
* 备注
*/
@Schema(description = "备注", example = "1月目标")
private String remark;
}
@@ -0,0 +1,33 @@
package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shopmonthlytarget;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDate;
/**
* 店铺月销量目标分页查询过滤DTO
*/
@Data
@Schema(description = "店铺月销量目标分页查询过滤DTO")
public class ShopMonthlyTargetFilterDTO {
/**
* 店铺ID
*/
@Schema(description = "店铺ID", example = "1")
private Long shopId;
/**
* 目标月份范围-开始月份
*/
@Schema(description = "目标月份范围-开始月份", example = "2024-01-01")
private LocalDate startTargetMonth;
/**
* 目标月份范围-结束月份
*/
@Schema(description = "目标月份范围-结束月份", example = "2024-12-01")
private LocalDate endTargetMonth;
}
@@ -0,0 +1,47 @@
package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shopmonthlytarget;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.PositiveOrZero;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDate;
/**
* 更新店铺月销量目标DTO
*/
@Data
@Schema(description = "更新店铺月销量目标DTO")
public class UpdateShopMonthlyTargetDTO {
/**
* 目标月份(格式:YYYY-MM-01)
*/
@Schema(description = "目标月份", example = "2024-01-01", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "目标月份不能为空")
private LocalDate targetMonth;
/**
* 目标销售额
*/
@Schema(description = "目标销售额", example = "100000.00", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "目标销售额不能为空")
@PositiveOrZero(message = "目标销售额必须大于等于0")
private BigDecimal targetAmount;
/**
* 目标订单数
*/
@Schema(description = "目标订单数", example = "1000", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "目标订单数不能为空")
@PositiveOrZero(message = "目标订单数必须大于等于0")
private Integer targetOrderCount;
/**
* 备注
*/
@Schema(description = "备注", example = "1月目标")
private String remark;
}
@@ -0,0 +1,85 @@
package top.xyquan.ecomdmbbackend.modules.ecom.model.po;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
/**
* 电商-店铺月销量目标实体
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("ec_shop_monthly_target")
public class ShopMonthlyTargetPO {
/**
* 目标ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 公司ID
*/
@TableField("company_id")
private Long companyId;
/**
* 店铺ID
*/
@TableField("shop_id")
private Long shopId;
/**
* 目标月份(格式:YYYY-MM-01)
*/
@TableField("target_month")
private LocalDate targetMonth;
/**
* 目标销售额
*/
@TableField("target_amount")
private BigDecimal targetAmount;
/**
* 目标订单数
*/
@TableField("target_order_count")
private Integer targetOrderCount;
/**
* 备注
*/
@TableField("remark")
private String remark;
/**
* 创建时间
*/
@TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 创建人ID
*/
@TableField("create_by")
private Long createBy;
/**
* 更新人ID
*/
@TableField("update_by")
private Long updateBy;
}
@@ -85,6 +85,30 @@ public class CompanyOverviewVO {
@Schema(description = "总税后盈亏", example = "80000.00")
private BigDecimal totalProfitAfterTax;
/**
* 全店总销量目标(目标订单数)
*/
@Schema(description = "全店总销量目标(目标订单数)", example = "1200")
private Integer totalTargetOrderCount;
/**
* 全店总销售额目标
*/
@Schema(description = "全店总销售额目标", example = "120000.00")
private BigDecimal totalTargetAmount;
/**
* 销量目标达成率(实际订单数/目标订单数)
*/
@Schema(description = "销量目标达成率", example = "83.33")
private BigDecimal orderCountAchievementRate;
/**
* 销售额目标达成率(实际销售额/目标销售额)
*/
@Schema(description = "销售额目标达成率", example = "83.33")
private BigDecimal salesAmountAchievementRate;
/**
* 店铺销售占比
*/
@@ -127,7 +151,7 @@ public class CompanyOverviewVO {
}
/**
* 店铺对比数据(16维度)
* 店铺对比数据
*/
@Data
@Schema(description = "店铺对比数据")
@@ -141,50 +165,53 @@ public class CompanyOverviewVO {
@Schema(description = "平台", example = "拼多多")
private String platform;
@Schema(description = "目标销量(目标订单数)", example = "1000")
private Integer targetOrderCount;
@Schema(description = "销量达成率", example = "83.33")
private BigDecimal orderCountAchievementRate;
@Schema(description = "目标销售额", example = "100000.00")
private BigDecimal targetAmount;
@Schema(description = "销售额达成率", example = "83.33")
private BigDecimal salesAmountAchievementRate;
@Schema(description = "销售额", example = "50000.00")
private BigDecimal salesAmount;
@Schema(description = "ROI", example = "1.5")
private BigDecimal roi;
@Schema(description = "退款金额", example = "1000.00")
private BigDecimal refundAmount;
@Schema(description = "刷单费", example = "2000.00")
private BigDecimal brushFee;
@Schema(description = "推广费总和", example = "5000.00")
private BigDecimal totalPromotionFee;
@Schema(description = "税后盈亏", example = "30000.00")
private BigDecimal profitAfterTax;
@Schema(description = "订单数量", example = "500")
@Schema(description = "单量", example = "500")
private Integer orderCount;
@Schema(description = "总成本", example = "15000.00")
private BigDecimal totalCost;
@Schema(description = "总利润(税前)", example = "35000.00")
private BigDecimal totalProfitBeforeTax;
@Schema(description = "税额", example = "3000.00")
private BigDecimal taxAmount;
@Schema(description = "费比", example = "0.10")
private BigDecimal feeRatio;
@Schema(description = "客单价", example = "100.00")
private BigDecimal averageOrderValue;
@Schema(description = "利润率", example = "0.60")
private BigDecimal profitMargin;
@Schema(description = "成本运费", example = "5000.00")
private BigDecimal shippingCost;
@Schema(description = "推广费占比", example = "0.10")
private BigDecimal promotionFeeRatio;
@Schema(description = "退款金额", example = "1000.00")
private BigDecimal refundAmount;
@Schema(description = "退款率", example = "0.02")
private BigDecimal refundRate;
@Schema(description = "推广费", example = "5000.00")
private BigDecimal totalPromotionFee;
@Schema(description = "刷单费用", example = "2000.00")
private BigDecimal brushFee;
@Schema(description = "费比", example = "0.10")
private BigDecimal feeRatio;
@Schema(description = "税前盈亏", example = "35000.00")
private BigDecimal totalProfitBeforeTax;
@Schema(description = "销售额4%税额", example = "2000.00")
private BigDecimal salesTaxAmount;
@Schema(description = "税后盈亏", example = "30000.00")
private BigDecimal profitAfterTax;
@Schema(description = "ROI", example = "1.5")
private BigDecimal roi;
}
}
@@ -0,0 +1,89 @@
package top.xyquan.ecomdmbbackend.modules.ecom.model.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
/**
* 店铺月销量目标VO
*/
@Data
@Schema(description = "店铺月销量目标VO")
public class ShopMonthlyTargetVO {
/**
* 目标ID
*/
@Schema(description = "目标ID", example = "1")
private Long id;
/**
* 公司ID
*/
@Schema(description = "公司ID", example = "1")
private Long companyId;
/**
* 店铺ID
*/
@Schema(description = "店铺ID", example = "1")
private Long shopId;
/**
* 店铺名称
*/
@Schema(description = "店铺名称", example = "旗舰店")
private String shopName;
/**
* 目标月份
*/
@Schema(description = "目标月份", example = "2024-01-01")
private LocalDate targetMonth;
/**
* 目标销售额
*/
@Schema(description = "目标销售额", example = "100000.00")
private BigDecimal targetAmount;
/**
* 目标订单数
*/
@Schema(description = "目标订单数", example = "1000")
private Integer targetOrderCount;
/**
* 备注
*/
@Schema(description = "备注", example = "1月目标")
private String remark;
/**
* 创建时间
*/
@Schema(description = "创建时间", example = "2024-01-01T10:00:00")
private LocalDateTime createTime;
/**
* 更新时间
*/
@Schema(description = "更新时间", example = "2024-01-01T10:00:00")
private LocalDateTime updateTime;
/**
* 创建人ID
*/
@Schema(description = "创建人ID", example = "1")
private Long createBy;
/**
* 更新人ID
*/
@Schema(description = "更新人ID", example = "1")
private Long updateBy;
}
@@ -0,0 +1,57 @@
package top.xyquan.ecomdmbbackend.modules.ecom.service;
import com.baomidou.mybatisplus.extension.service.IService;
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shopmonthlytarget.CreateShopMonthlyTargetDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shopmonthlytarget.ShopMonthlyTargetFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shopmonthlytarget.UpdateShopMonthlyTargetDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopMonthlyTargetPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopMonthlyTargetVO;
/**
* 店铺月销量目标服务接口
*/
public interface ShopMonthlyTargetService extends IService<ShopMonthlyTargetPO> {
/**
* 创建店铺月销量目标
*
* @param createDTO 创建店铺月销量目标DTO
* @return 店铺月销量目标VO
*/
ShopMonthlyTargetVO createShopMonthlyTarget(CreateShopMonthlyTargetDTO createDTO);
/**
* 更新店铺月销量目标
*
* @param updateDTO 更新店铺月销量目标DTO
* @param id 目标ID
* @return 店铺月销量目标VO
*/
ShopMonthlyTargetVO updateShopMonthlyTarget(UpdateShopMonthlyTargetDTO updateDTO, Long id);
/**
* 删除店铺月销量目标
*
* @param id 目标ID
*/
void deleteShopMonthlyTarget(Long id);
/**
* 分页获取店铺月销量目标列表
*
* @param pageQueryDTO 分页查询DTO
* @return 分页结果
*/
PageResultVO<ShopMonthlyTargetVO> getShopMonthlyTargetPage(PageQueryDTO<ShopMonthlyTargetFilterDTO> pageQueryDTO);
/**
* 根据ID获取店铺月销量目标详情
*
* @param id 目标ID
* @return 店铺月销量目标VO
*/
ShopMonthlyTargetVO getShopMonthlyTargetById(Long id);
}
@@ -6,11 +6,13 @@ import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.BrushOrderMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.OrderMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.PromotionFeeMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.ShopMonthlyTargetMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.overview.CompanyOverviewQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.BrushOrderPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.OrderPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.OrderStatusPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.PromotionFeePO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopMonthlyTargetPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.CompanyOverviewVO;
import top.xyquan.ecomdmbbackend.modules.ecom.service.CompanyOverviewService;
@@ -40,6 +42,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
private final OrderMapper orderMapper;
private final PromotionFeeMapper promotionFeeMapper;
private final BrushOrderMapper brushOrderMapper;
private final ShopMonthlyTargetMapper shopMonthlyTargetMapper;
private final ShopService shopService;
private final OrderStatusService orderStatusService;
@@ -47,12 +50,14 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
OrderMapper orderMapper,
PromotionFeeMapper promotionFeeMapper,
BrushOrderMapper brushOrderMapper,
ShopMonthlyTargetMapper shopMonthlyTargetMapper,
ShopService shopService,
OrderStatusService orderStatusService) {
this.currentUserContext = currentUserContext;
this.orderMapper = orderMapper;
this.promotionFeeMapper = promotionFeeMapper;
this.brushOrderMapper = brushOrderMapper;
this.shopMonthlyTargetMapper = shopMonthlyTargetMapper;
this.shopService = shopService;
this.orderStatusService = orderStatusService;
}
@@ -179,9 +184,9 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
shops, orders, promotionFees, brushOrders, refundStatusId);
overviewVO.setShopEfficiencyQuadrants(shopEfficiencyQuadrants);
// 9. 多店铺数据横向对比(16维度)
// 9. 多店铺数据横向对比
List<CompanyOverviewVO.ShopComparison> shopComparisons = calculateShopComparisons(
shops, orders, promotionFees, brushOrders, refundStatusId);
shops, orders, promotionFees, brushOrders, refundStatusId, companyId, startDate, endDate);
overviewVO.setShopComparisons(shopComparisons);
// 10. 汇总ROI和总税后盈亏
@@ -189,9 +194,81 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
overviewVO.setTotalROI(totalROI);
overviewVO.setTotalProfitAfterTax(totalNetProfitAfterTax);
// 11. 计算目标维度的数据
calculateTargetData(overviewVO, companyId, startDate, endDate, totalSalesAmount, totalOrderCount);
return overviewVO;
}
/**
* 计算目标维度的数据
*/
private void calculateTargetData(CompanyOverviewVO overviewVO, Long companyId, LocalDate startDate, LocalDate endDate,
BigDecimal totalSalesAmount, Integer totalOrderCount) {
// 生成日期范围内所有月份的第一天列表
List<LocalDate> targetMonths = new ArrayList<>();
LocalDate currentMonth = startDate.withDayOfMonth(1);
LocalDate endMonth = endDate.withDayOfMonth(1);
while (!currentMonth.isAfter(endMonth)) {
targetMonths.add(currentMonth);
currentMonth = currentMonth.plusMonths(1);
}
// 查询所有店铺在这些月份的目标数据
LambdaQueryWrapper<ShopMonthlyTargetPO> targetWrapper = new LambdaQueryWrapper<>();
targetWrapper.eq(ShopMonthlyTargetPO::getCompanyId, companyId)
.in(ShopMonthlyTargetPO::getTargetMonth, targetMonths);
List<ShopMonthlyTargetPO> targets = shopMonthlyTargetMapper.selectList(targetWrapper);
// 汇总所有店铺的目标数据(按店铺汇总,因为同一店铺可能有多个月的目标)
Map<Long, List<ShopMonthlyTargetPO>> targetsByShop = targets.stream()
.collect(Collectors.groupingBy(ShopMonthlyTargetPO::getShopId));
// 计算总目标销售额和总目标订单数
BigDecimal totalTargetAmount = BigDecimal.ZERO;
Integer totalTargetOrderCount = 0;
for (List<ShopMonthlyTargetPO> shopTargets : targetsByShop.values()) {
// 对于每个店铺,汇总其所有月份的目标
BigDecimal shopTargetAmount = shopTargets.stream()
.map(target -> target.getTargetAmount() != null ? target.getTargetAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
Integer shopTargetOrderCount = shopTargets.stream()
.mapToInt(target -> target.getTargetOrderCount() != null ? target.getTargetOrderCount() : 0)
.sum();
totalTargetAmount = totalTargetAmount.add(shopTargetAmount);
totalTargetOrderCount += shopTargetOrderCount;
}
overviewVO.setTotalTargetAmount(totalTargetAmount);
overviewVO.setTotalTargetOrderCount(totalTargetOrderCount);
// 计算达成率
BigDecimal salesAmountAchievementRate = BigDecimal.ZERO;
if (totalTargetAmount.compareTo(BigDecimal.ZERO) > 0) {
salesAmountAchievementRate = totalSalesAmount.divide(totalTargetAmount, 4, RoundingMode.HALF_UP)
.multiply(new BigDecimal("100"));
} else if (totalSalesAmount.compareTo(BigDecimal.ZERO) > 0) {
// 目标为0但实际有销售额,达成率设为100%
salesAmountAchievementRate = new BigDecimal("100");
}
overviewVO.setSalesAmountAchievementRate(salesAmountAchievementRate);
BigDecimal orderCountAchievementRate = BigDecimal.ZERO;
if (totalTargetOrderCount > 0) {
orderCountAchievementRate = new BigDecimal(totalOrderCount)
.divide(new BigDecimal(totalTargetOrderCount), 4, RoundingMode.HALF_UP)
.multiply(new BigDecimal("100"));
} else if (totalOrderCount > 0) {
// 目标为0但实际有订单,达成率设为100%
orderCountAchievementRate = new BigDecimal("100");
}
overviewVO.setOrderCountAchievementRate(orderCountAchievementRate);
}
/**
* 计算总利润(税前)
*/
@@ -320,11 +397,11 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
}
/**
* 计算多店铺数据横向对比(16维度)
* 计算多店铺数据横向对比
*/
private List<CompanyOverviewVO.ShopComparison> calculateShopComparisons(
List<ShopPO> shops, List<OrderPO> orders, List<PromotionFeePO> promotionFees,
List<BrushOrderPO> brushOrders, Long refundStatusId) {
List<BrushOrderPO> brushOrders, Long refundStatusId, Long companyId, LocalDate startDate, LocalDate endDate) {
List<CompanyOverviewVO.ShopComparison> comparisons = new ArrayList<>();
// 按店铺分组数据
@@ -335,16 +412,37 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
Map<Long, List<BrushOrderPO>> brushOrdersByShop = brushOrders.stream()
.collect(Collectors.groupingBy(BrushOrderPO::getShopId));
// 查询所有店铺的目标数据
List<LocalDate> targetMonths = new ArrayList<>();
LocalDate currentMonth = startDate.withDayOfMonth(1);
LocalDate endMonth = endDate.withDayOfMonth(1);
while (!currentMonth.isAfter(endMonth)) {
targetMonths.add(currentMonth);
currentMonth = currentMonth.plusMonths(1);
}
LambdaQueryWrapper<ShopMonthlyTargetPO> targetWrapper = new LambdaQueryWrapper<>();
targetWrapper.eq(ShopMonthlyTargetPO::getCompanyId, companyId)
.in(ShopMonthlyTargetPO::getTargetMonth, targetMonths);
List<ShopMonthlyTargetPO> allTargets = shopMonthlyTargetMapper.selectList(targetWrapper);
// 按店铺分组目标数据
Map<Long, List<ShopMonthlyTargetPO>> targetsByShop = allTargets.stream()
.collect(Collectors.groupingBy(ShopMonthlyTargetPO::getShopId));
for (ShopPO shop : shops) {
List<OrderPO> shopOrders = ordersByShop.getOrDefault(shop.getId(), new ArrayList<>());
List<PromotionFeePO> shopPromotionFees = promotionFeesByShop.getOrDefault(shop.getId(), new ArrayList<>());
List<BrushOrderPO> shopBrushOrders = brushOrdersByShop.getOrDefault(shop.getId(), new ArrayList<>());
List<ShopMonthlyTargetPO> shopTargets = targetsByShop.getOrDefault(shop.getId(), new ArrayList<>());
// 计算各项指标
BigDecimal salesAmount = shopOrders.stream()
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
int orderCount = shopOrders.size();
BigDecimal refundAmount = shopOrders.stream()
.filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId()))
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
@@ -358,10 +456,23 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
// 计算成本运费(单独计算运费成本)
BigDecimal shippingCost = shopOrders.stream()
.map(order -> {
BigDecimal cost = order.getShippingCost() != null ? order.getShippingCost() : 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);
BigDecimal taxAmount = profitBeforeTax.multiply(TAX_RATE);
BigDecimal profitAfterTax = profitBeforeTax.subtract(taxAmount);
// 销售额4%税额
BigDecimal salesTaxAmount = salesAmount.multiply(new BigDecimal("0.04"));
// 税后盈亏(扣除销售额4%税额)
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
BigDecimal totalCostForROI = totalPromotionFee.add(brushFee);
BigDecimal roi = calculateShopROI(profitBeforeTax, totalCostForROI);
@@ -372,45 +483,57 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
}
BigDecimal averageOrderValue = BigDecimal.ZERO;
int orderCount = shopOrders.size();
if (orderCount > 0) {
averageOrderValue = salesAmount.divide(new BigDecimal(orderCount), 2, RoundingMode.HALF_UP);
}
BigDecimal profitMargin = BigDecimal.ZERO;
if (salesAmount.compareTo(BigDecimal.ZERO) > 0) {
profitMargin = profitBeforeTax.divide(salesAmount, 4, RoundingMode.HALF_UP);
// 计算目标数据
BigDecimal targetAmount = shopTargets.stream()
.map(target -> target.getTargetAmount() != null ? target.getTargetAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
Integer targetOrderCount = shopTargets.stream()
.mapToInt(target -> target.getTargetOrderCount() != null ? target.getTargetOrderCount() : 0)
.sum();
// 计算达成率
BigDecimal salesAmountAchievementRate = BigDecimal.ZERO;
if (targetAmount.compareTo(BigDecimal.ZERO) > 0) {
salesAmountAchievementRate = salesAmount.divide(targetAmount, 4, RoundingMode.HALF_UP)
.multiply(new BigDecimal("100"));
} else if (salesAmount.compareTo(BigDecimal.ZERO) > 0) {
salesAmountAchievementRate = new BigDecimal("100");
}
BigDecimal promotionFeeRatio = BigDecimal.ZERO;
if (salesAmount.compareTo(BigDecimal.ZERO) > 0) {
promotionFeeRatio = totalPromotionFee.divide(salesAmount, 4, RoundingMode.HALF_UP);
}
BigDecimal refundRate = BigDecimal.ZERO;
if (salesAmount.compareTo(BigDecimal.ZERO) > 0) {
refundRate = refundAmount.divide(salesAmount, 4, RoundingMode.HALF_UP);
BigDecimal orderCountAchievementRate = BigDecimal.ZERO;
if (targetOrderCount > 0) {
orderCountAchievementRate = new BigDecimal(orderCount)
.divide(new BigDecimal(targetOrderCount), 4, RoundingMode.HALF_UP)
.multiply(new BigDecimal("100"));
} else if (orderCount > 0) {
orderCountAchievementRate = new BigDecimal("100");
}
CompanyOverviewVO.ShopComparison comparison = new CompanyOverviewVO.ShopComparison();
comparison.setShopId(shop.getId());
comparison.setShopName(shop.getName());
comparison.setPlatform(shop.getPlatform());
comparison.setTargetOrderCount(targetOrderCount);
comparison.setOrderCountAchievementRate(orderCountAchievementRate);
comparison.setTargetAmount(targetAmount);
comparison.setSalesAmountAchievementRate(salesAmountAchievementRate);
comparison.setSalesAmount(salesAmount);
comparison.setRoi(roi);
comparison.setRefundAmount(refundAmount);
comparison.setBrushFee(brushFee);
comparison.setTotalPromotionFee(totalPromotionFee);
comparison.setProfitAfterTax(profitAfterTax);
comparison.setOrderCount(orderCount);
comparison.setTotalCost(totalCost);
comparison.setTotalProfitBeforeTax(profitBeforeTax);
comparison.setTaxAmount(taxAmount);
comparison.setFeeRatio(feeRatio);
comparison.setAverageOrderValue(averageOrderValue);
comparison.setProfitMargin(profitMargin);
comparison.setPromotionFeeRatio(promotionFeeRatio);
comparison.setRefundRate(refundRate);
comparison.setShippingCost(shippingCost);
comparison.setRefundAmount(refundAmount);
comparison.setTotalPromotionFee(totalPromotionFee);
comparison.setBrushFee(brushFee);
comparison.setFeeRatio(feeRatio);
comparison.setTotalProfitBeforeTax(profitBeforeTax);
comparison.setSalesTaxAmount(salesTaxAmount);
comparison.setProfitAfterTax(profitAfterTax);
comparison.setRoi(roi);
comparisons.add(comparison);
}
@@ -0,0 +1,222 @@
package top.xyquan.ecomdmbbackend.modules.ecom.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.ShopMonthlyTargetMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shopmonthlytarget.CreateShopMonthlyTargetDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shopmonthlytarget.ShopMonthlyTargetFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shopmonthlytarget.UpdateShopMonthlyTargetDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopMonthlyTargetPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopMonthlyTargetVO;
import top.xyquan.ecomdmbbackend.modules.ecom.service.ShopMonthlyTargetService;
import top.xyquan.ecomdmbbackend.modules.ecom.service.ShopService;
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;
/**
* 店铺月销量目标服务实现类
*/
@Service
public class ShopMonthlyTargetServiceImpl extends ServiceImpl<ShopMonthlyTargetMapper, ShopMonthlyTargetPO> implements ShopMonthlyTargetService {
private final CurrentUserContext currentUserContext;
private final ShopService shopService;
public ShopMonthlyTargetServiceImpl(CurrentUserContext currentUserContext, ShopService shopService) {
this.currentUserContext = currentUserContext;
this.shopService = shopService;
}
/**
* 创建店铺月销量目标
*
* @param createDTO 创建店铺月销量目标DTO
* @return 店铺月销量目标VO
*/
@Override
@Transactional
public ShopMonthlyTargetVO createShopMonthlyTarget(CreateShopMonthlyTargetDTO createDTO) {
Long companyId = currentUserContext.getCurrentCompanyId();
Long userId = currentUserContext.getCurrentUserId();
// 验证店铺是否存在且属于当前公司
ShopPO shop = shopService.getById(createDTO.getShopId());
if (shop == null || !shop.getCompanyId().equals(companyId)) {
throw new BusinessException("店铺不存在");
}
// 验证目标月份格式(确保是每月的第一天)
LocalDate targetMonth = createDTO.getTargetMonth();
if (targetMonth.getDayOfMonth() != 1) {
throw new BusinessException("目标月份必须是每月的第一天(格式:YYYY-MM-01)");
}
// 检查该店铺该月份是否已存在目标
LambdaQueryWrapper<ShopMonthlyTargetPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShopMonthlyTargetPO::getShopId, createDTO.getShopId())
.eq(ShopMonthlyTargetPO::getTargetMonth, targetMonth)
.eq(ShopMonthlyTargetPO::getCompanyId, companyId);
if (this.count(wrapper) > 0) {
throw new BusinessException("该店铺该月份的目标已存在");
}
// 创建目标记录
ShopMonthlyTargetPO target = new ShopMonthlyTargetPO();
BeanUtils.copyProperties(createDTO, target);
target.setCompanyId(companyId);
target.setCreateBy(userId);
this.save(target);
return convertToVO(target);
}
/**
* 更新店铺月销量目标
*
* @param updateDTO 更新店铺月销量目标DTO
* @param id 目标ID
* @return 店铺月销量目标VO
*/
@Override
@Transactional
public ShopMonthlyTargetVO updateShopMonthlyTarget(UpdateShopMonthlyTargetDTO updateDTO, Long id) {
Long companyId = currentUserContext.getCurrentCompanyId();
Long userId = currentUserContext.getCurrentUserId();
ShopMonthlyTargetPO existingTarget = this.getById(id);
if (existingTarget == null || !existingTarget.getCompanyId().equals(companyId)) {
throw new BusinessException("目标不存在");
}
// 验证目标月份格式(确保是每月的第一天)
LocalDate targetMonth = updateDTO.getTargetMonth();
if (targetMonth.getDayOfMonth() != 1) {
throw new BusinessException("目标月份必须是每月的第一天(格式:YYYY-MM-01)");
}
// 如果月份改变了,检查新月份是否已存在目标(排除当前记录)
if (!targetMonth.equals(existingTarget.getTargetMonth())) {
LambdaQueryWrapper<ShopMonthlyTargetPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShopMonthlyTargetPO::getShopId, existingTarget.getShopId())
.eq(ShopMonthlyTargetPO::getTargetMonth, targetMonth)
.eq(ShopMonthlyTargetPO::getCompanyId, companyId)
.ne(ShopMonthlyTargetPO::getId, id);
if (this.count(wrapper) > 0) {
throw new BusinessException("该店铺该月份的目标已存在");
}
}
// 更新目标记录
ShopMonthlyTargetPO target = new ShopMonthlyTargetPO();
BeanUtils.copyProperties(updateDTO, target);
target.setId(id);
target.setCompanyId(companyId);
target.setShopId(existingTarget.getShopId()); // 保持店铺ID不变
target.setUpdateBy(userId);
this.updateById(target);
return convertToVO(target);
}
/**
* 删除店铺月销量目标
*
* @param id 目标ID
*/
@Override
@Transactional
public void deleteShopMonthlyTarget(Long id) {
Long companyId = currentUserContext.getCurrentCompanyId();
ShopMonthlyTargetPO existingTarget = this.getById(id);
if (existingTarget == null || !existingTarget.getCompanyId().equals(companyId)) {
throw new BusinessException("目标不存在");
}
this.removeById(id);
}
/**
* 分页获取店铺月销量目标列表
*
* @param pageQueryDTO 分页查询DTO
* @return 分页结果VO
*/
@Override
public PageResultVO<ShopMonthlyTargetVO> getShopMonthlyTargetPage(PageQueryDTO<ShopMonthlyTargetFilterDTO> pageQueryDTO) {
Long companyId = currentUserContext.getCurrentCompanyId();
Page<ShopMonthlyTargetPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
LambdaQueryWrapper<ShopMonthlyTargetPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShopMonthlyTargetPO::getCompanyId, companyId);
ShopMonthlyTargetFilterDTO filter = pageQueryDTO.getFilters();
if (filter != null) {
if (filter.getShopId() != null) {
wrapper.eq(ShopMonthlyTargetPO::getShopId, filter.getShopId());
}
if (filter.getStartTargetMonth() != null) {
wrapper.ge(ShopMonthlyTargetPO::getTargetMonth, filter.getStartTargetMonth());
}
if (filter.getEndTargetMonth() != null) {
wrapper.le(ShopMonthlyTargetPO::getTargetMonth, filter.getEndTargetMonth());
}
}
wrapper.orderByDesc(ShopMonthlyTargetPO::getTargetMonth)
.orderByDesc(ShopMonthlyTargetPO::getCreateTime);
IPage<ShopMonthlyTargetPO> pageResult = this.page(page, wrapper);
List<ShopMonthlyTargetVO> voList = pageResult.getRecords().stream()
.map(this::convertToVO)
.collect(Collectors.toList());
return PageResultVO.create(voList, pageResult.getTotal(), pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
}
/**
* 根据ID获取店铺月销量目标详情
*
* @param id 目标ID
* @return 店铺月销量目标VO
*/
@Override
public ShopMonthlyTargetVO getShopMonthlyTargetById(Long id) {
Long companyId = currentUserContext.getCurrentCompanyId();
ShopMonthlyTargetPO target = this.getById(id);
if (target == null || !target.getCompanyId().equals(companyId)) {
throw new BusinessException("目标不存在");
}
return convertToVO(target);
}
/**
* 转换为VO
*/
private ShopMonthlyTargetVO convertToVO(ShopMonthlyTargetPO target) {
ShopMonthlyTargetVO vo = new ShopMonthlyTargetVO();
BeanUtils.copyProperties(target, vo);
// 设置店铺名称
if (target.getShopId() != null) {
ShopPO shop = shopService.getById(target.getShopId());
if (shop != null) {
vo.setShopName(shop.getName());
}
}
return vo;
}
}
@@ -327,3 +327,30 @@ CREATE TABLE `ec_brush_order` (
CONSTRAINT `fk_ec_brush_order_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_brush_order_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-刷单记录表';
-- 店铺月销量目标表
CREATE TABLE `ec_shop_monthly_target` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '目标ID',
`company_id` BIGINT UNSIGNED NOT NULL COMMENT '公司ID',
`shop_id` BIGINT UNSIGNED NOT NULL COMMENT '店铺ID',
`target_month` DATE NOT NULL COMMENT '目标月份(格式:YYYY-MM-01)',
`target_amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT '目标销售额',
`target_order_count` INT NOT NULL DEFAULT 0 COMMENT '目标订单数',
`remark` VARCHAR(500) DEFAULT NULL COMMENT '备注',
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
PRIMARY KEY (`id`),
KEY `idx_company_id` (`company_id`),
KEY `idx_shop_id` (`shop_id`),
KEY `idx_target_month` (`target_month`),
KEY `idx_company_shop_month` (`company_id`, `shop_id`, `target_month`),
KEY `fk_ec_shop_monthly_target_creator` (`create_by`),
KEY `fk_ec_shop_monthly_target_updater` (`update_by`),
UNIQUE KEY `uk_shop_month` (`shop_id`, `target_month`),
CONSTRAINT `fk_ec_shop_monthly_target_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_monthly_target_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_monthly_target_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_shop_monthly_target_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-店铺月销量目标表';
@@ -29,6 +29,14 @@ export namespace CompanyOverviewVO {
totalROI?: number;
/** 总税后盈亏 */
totalProfitAfterTax?: number;
/** 全店总销量目标(目标订单数) */
totalTargetOrderCount?: number;
/** 全店总销售额目标 */
totalTargetAmount?: number;
/** 销量目标达成率(实际订单数/目标订单数) */
orderCountAchievementRate?: number;
/** 销售额目标达成率(实际销售额/目标销售额) */
salesAmountAchievementRate?: number;
}
/** 店铺销售占比 */
@@ -65,35 +73,37 @@ export namespace CompanyOverviewVO {
shopName: string;
/** 平台 */
platform?: string;
/** 目标销量(目标订单数) */
targetOrderCount?: number;
/** 销量达成率 */
orderCountAchievementRate?: number;
/** 目标销售额 */
targetAmount?: number;
/** 销售额达成率 */
salesAmountAchievementRate?: number;
/** 销售额 */
salesAmount: number;
/** ROI */
roi?: number;
/** 退款金额 */
refundAmount?: number;
/** 刷单费 */
brushFee?: number;
/** 推广费总和 */
totalPromotionFee?: number;
/** 税后盈亏 */
profitAfterTax?: number;
/** 订单数量 */
/** 单量 */
orderCount?: number;
/** 总成本 */
totalCost?: number;
/** 总利润(税前) */
totalProfitBeforeTax?: number;
/** 税额 */
taxAmount?: number;
/** 费比 */
feeRatio?: number;
/** 客单价 */
averageOrderValue?: number;
/** 利润率 */
profitMargin?: number;
/** 推广费占比 */
promotionFeeRatio?: number;
/** 退款率 */
refundRate?: number;
/** 成本运费 */
shippingCost?: number;
/** 退款金额 */
refundAmount?: number;
/** 推广费 */
totalPromotionFee?: number;
/** 刷单费用 */
brushFee?: number;
/** 费比 */
feeRatio?: number;
/** 税前盈亏 */
totalProfitBeforeTax?: number;
/** 销售额4%税额 */
salesTaxAmount?: number;
/** 税后盈亏 */
profitAfterTax?: number;
/** ROI */
roi?: number;
}
}
@@ -0,0 +1,65 @@
import type {
ShopMonthlyTargetDTO,
ShopMonthlyTargetVO,
} from './types';
import type { PageQueryDTO, PageResultVO } from '#/types/common';
import { requestClient } from '#/api/request';
/**
* 店铺月销量目标管理API
*/
/**
* 创建店铺月销量目标
*/
export async function createShopMonthlyTargetApi(
data: ShopMonthlyTargetDTO.Create,
) {
return requestClient.post<ShopMonthlyTargetVO.Info>(
'/ec/shop-monthly-target/create',
data,
);
}
/**
* 更新店铺月销量目标
*/
export async function updateShopMonthlyTargetApi(
id: number,
data: ShopMonthlyTargetDTO.Update,
) {
return requestClient.put<ShopMonthlyTargetVO.Info>(
`/ec/shop-monthly-target/update/${id}`,
data,
);
}
/**
* 删除店铺月销量目标
*/
export async function deleteShopMonthlyTargetApi(id: number) {
return requestClient.delete(`/ec/shop-monthly-target/delete/${id}`);
}
/**
* 分页获取店铺月销量目标列表
*/
export async function getShopMonthlyTargetPageApi(
params: PageQueryDTO<ShopMonthlyTargetDTO.Filters>,
) {
return requestClient.post<PageResultVO<ShopMonthlyTargetVO.Info>>(
'/ec/shop-monthly-target/page',
params,
);
}
/**
* 获取店铺月销量目标详情
*/
export async function getShopMonthlyTargetByIdApi(id: number) {
return requestClient.get<ShopMonthlyTargetVO.Info>(
`/ec/shop-monthly-target/detail/${id}`,
);
}
@@ -0,0 +1,6 @@
/**
* 店铺月销量目标管理模块API导出
*/
export * from './apis';
export * from './types';
@@ -0,0 +1,6 @@
/**
* 店铺月销量目标管理模块类型定义导出
*/
export * from './types.dto';
export * from './types.vo';
@@ -0,0 +1,41 @@
/**
* 店铺月销量目标相关DTO类型定义
*/
export namespace ShopMonthlyTargetDTO {
/** 创建店铺月销量目标参数 */
export interface Create {
/** 店铺ID */
shopId: number;
/** 目标月份(格式:YYYY-MM-01) */
targetMonth: string;
/** 目标销售额 */
targetAmount: number;
/** 目标订单数 */
targetOrderCount: number;
/** 备注 */
remark?: string;
}
/** 更新店铺月销量目标参数 */
export interface Update {
/** 目标月份(格式:YYYY-MM-01) */
targetMonth: string;
/** 目标销售额 */
targetAmount: number;
/** 目标订单数 */
targetOrderCount: number;
/** 备注 */
remark?: string;
}
/** 店铺月销量目标过滤条件 */
export interface Filters {
/** 店铺ID */
shopId?: number;
/** 目标月份范围-开始月份 */
startTargetMonth?: string;
/** 目标月份范围-结束月份 */
endTargetMonth?: string;
}
}
@@ -0,0 +1,33 @@
/**
* 店铺月销量目标相关VO类型定义
*/
export namespace ShopMonthlyTargetVO {
/** 店铺月销量目标信息 */
export interface Info {
/** 目标ID */
id: number;
/** 公司ID */
companyId: number;
/** 店铺ID */
shopId: number;
/** 店铺名称 */
shopName: string;
/** 目标月份 */
targetMonth: string;
/** 目标销售额 */
targetAmount: number;
/** 目标订单数 */
targetOrderCount: number;
/** 备注 */
remark?: string;
/** 创建时间 */
createTime: string;
/** 更新时间 */
updateTime: string;
/** 创建人ID */
createBy?: number;
/** 更新人ID */
updateBy?: number;
}
}
@@ -101,11 +101,6 @@ const { renderEcharts: renderScatterChart } = useEcharts(scatterChartRef);
// 格式化金额
const formatAmount = (amount: number) => {
return `¥${(amount / 10_000).toFixed(2)}万`;
};
// 格式化金额(完整)
const formatAmountFull = (amount: number) => {
return `¥${amount.toLocaleString('zh-CN')}`;
};
@@ -115,6 +110,12 @@ const formatPercent = (value: number | undefined) => {
return `${value > 0 ? '+' : ''}${value.toFixed(1)}%`;
};
// 格式化百分比(不带符号)
const formatPercentPlain = (value: number | undefined) => {
if (value === undefined) return '-';
return `${value.toFixed(1)}%`;
};
// 加载店铺数量
const loadShopCount = async () => {
try {
@@ -155,9 +156,16 @@ const renderShopBarChart = () => {
const ratios = overviewData.value.shopSalesRatios;
const shopNames = ratios.map((r) => r.shopName).reverse();
const salesAmounts = ratios.map((r) => r.salesAmount / 1000).reverse(); // 转换为千元
const salesAmounts = ratios.map((r) => r.salesAmount).reverse();
renderBarChart({
grid: {
left: '3%',
right: '12%',
bottom: '3%',
top: '3%',
containLabel: true,
},
tooltip: {
trigger: 'axis',
formatter: (params: any) => {
@@ -165,23 +173,32 @@ const renderShopBarChart = () => {
const index = param.dataIndex;
const shop = ratios[ratios.length - 1 - index];
if (!shop) return '';
return `${shop.shopName}<br/>销售额: ${formatAmountFull(shop.salesAmount)}<br/>占比: ${shop.ratio.toFixed(2)}%`;
return `${shop.shopName}<br/>销售额: ${formatAmount(shop.salesAmount)}<br/>占比: ${shop.ratio.toFixed(2)}%`;
},
},
xAxis: {
type: 'value',
show: false,
axisLabel: { show: false },
splitLine: { show: false },
},
yAxis: {
type: 'category',
data: shopNames,
axisLine: { show: false },
axisTick: { show: false },
axisLabel: {
fontWeight: 'bold',
color: '#1e293b',
fontSize: 13,
},
},
series: [
{
type: 'bar',
data: salesAmounts,
barWidth: 20,
itemStyle: {
borderRadius: [0, 10, 10, 0],
color: {
type: 'linear',
x: 1,
@@ -193,9 +210,15 @@ const renderShopBarChart = () => {
{ offset: 1, color: '#a5b4fc' },
],
},
borderRadius: [0, 10, 10, 0],
},
barWidth: 25,
label: {
show: true,
position: 'right',
formatter: (params: any) =>
`¥${params.value.toLocaleString('zh-CN')}`,
fontWeight: 900,
color: '#0f172a',
},
},
],
});
@@ -207,52 +230,59 @@ const renderShopScatterChart = () => {
return;
const quadrants = overviewData.value.shopEfficiencyQuadrants;
const data = quadrants.map((q) => [q.roi, q.netProfit / 1000]); // 净利转换为千元
const data = quadrants.map((q) => [
q.roi,
q.netProfit / 10_000, // 转换为万元
q.shopName,
]);
renderScatterChart({
grid: {
top: '10%',
bottom: '10%',
left: '10%',
right: '10%',
},
tooltip: {
trigger: 'item',
formatter: (params: any) => {
const index = params.dataIndex;
const shop = quadrants[index];
const shop = quadrants[params.dataIndex];
if (!shop) return '';
return `${shop.shopName}<br/>ROI: ${shop.roi.toFixed(2)}<br/>净利: ${formatAmountFull(shop.netProfit)}`;
return `<div style="padding:4px; font-weight:bold">${shop.shopName}</div><hr/>投资回报率 (ROI): ${shop.roi.toFixed(2)}<br/>净利润: ¥${(shop.netProfit / 10_000).toFixed(2)}万`;
},
},
xAxis: {
name: 'ROI',
name: '投资回报率 (ROI)',
nameLocation: 'middle',
nameGap: 30,
nameGap: 35,
axisLabel: { fontWeight: 'bold' },
splitLine: {
lineStyle: {
type: 'dashed',
},
lineStyle: { type: 'dashed' },
},
},
yAxis: {
name: '净利(千元)',
name: '税后净利润 (单位: 万元)',
nameLocation: 'middle',
nameGap: 50,
axisLabel: { fontWeight: 'bold' },
splitLine: {
lineStyle: {
type: 'dashed',
},
lineStyle: { type: 'dashed' },
},
},
series: [
{
type: 'scatter',
symbolSize: 40,
symbolSize: 45,
data,
itemStyle: {
color: '#6366f1',
opacity: 0.6,
color: (params: any) => {
const roi = params.data[0];
const profit = params.data[1];
if (roi >= 3.5 && profit >= 10) return '#10b981'; // 高产区
if (roi < 3 || profit < 0) return '#f43f5e'; // 风险区
return '#6366f1'; // 潜力区
},
shadowBlur: 15,
shadowColor: 'rgba(0,0,0,0.1)',
},
markLine: {
silent: true,
lineStyle: { type: 'dashed', color: '#94a3b8' },
data: [{ xAxis: 3.5 }, { yAxis: 10 }],
},
},
],
@@ -290,142 +320,111 @@ onMounted(async () => {
</script>
<template>
<Page
title="全店铺经营大盘"
auto-content-height
class="bg-gradient-to-br from-rose-50 via-indigo-50 to-green-50"
>
<Page title="全店铺经营概览大盘" auto-content-height class="bg-[#f8fafc]">
<template #description>
<div class="font-bold text-indigo-600">
Company Dashboard · 共 {{ shopCount }} 家在营店铺
<div class="mt-1 text-sm font-bold text-slate-500">
数据范围:公司旗下所有店铺汇总统计 · 共 {{ shopCount }} 家在营店铺
</div>
</template>
<template #extra>
<div class="flex items-center gap-4">
<!-- 汇总 ROI 和总税后盈亏 -->
<div
class="flex items-center gap-6 rounded-[2rem] border border-white/60 bg-white/50 px-6 py-3 shadow-[0_10px_30px_rgba(0,0,0,0.02)] backdrop-blur-[20px]"
>
<div class="text-center">
<div class="text-[10px] font-bold uppercase text-slate-400">
汇总 ROI
</div>
<div class="text-lg font-black">
{{ overviewData?.totalROI?.toFixed(2) || '-' }}
</div>
</div>
<div class="h-8 w-px bg-slate-200"></div>
<div class="text-center">
<div class="text-[10px] font-bold uppercase text-slate-400">
总税后盈亏
</div>
<div class="text-lg font-black text-emerald-600">
{{
overviewData?.totalProfitAfterTax
? formatAmount(overviewData.totalProfitAfterTax)
: '-'
}}
</div>
</div>
</div>
<!-- 时间选择器组件 -->
<div
class="flex flex-wrap items-center gap-2 rounded-2xl border border-white/60 bg-white/40 p-1.5 shadow-[0_8px_32px_0_rgba(31,38,135,0.05)] backdrop-blur-[16px]"
>
<!-- 快速选择按钮 -->
<div class="flex rounded-xl bg-white/30 p-1">
<Button
:type="activeTimeRange === 'today' ? 'primary' : 'text'"
size="small"
class="!h-auto border-none !px-4 !py-1.5 !text-sm !font-bold"
:class="
activeTimeRange === 'today'
? '!bg-indigo-600 !text-white !shadow-[0_4px_12px_rgba(99,102,241,0.3)]'
: ''
"
@click="switchTimeRange('today')"
>
今日
</Button>
<Button
:type="activeTimeRange === 'yesterday' ? 'primary' : 'text'"
size="small"
class="!h-auto border-none !px-4 !py-1.5 !text-sm !font-bold"
:class="
activeTimeRange === 'yesterday'
? '!bg-indigo-600 !text-white !shadow-[0_4px_12px_rgba(99,102,241,0.3)]'
: ''
"
@click="switchTimeRange('yesterday')"
>
昨日
</Button>
<Button
:type="activeTimeRange === '7days' ? 'primary' : 'text'"
size="small"
class="!h-auto border-none !px-4 !py-1.5 !text-sm !font-bold"
:class="
activeTimeRange === '7days'
? '!bg-indigo-600 !text-white !shadow-[0_4px_12px_rgba(99,102,241,0.3)]'
: ''
"
@click="switchTimeRange('7days')"
>
近7日
</Button>
<Button
:type="activeTimeRange === '30days' ? 'primary' : 'text'"
size="small"
class="!h-auto border-none !px-4 !py-1.5 !text-sm !font-bold"
:class="
activeTimeRange === '30days'
? '!bg-indigo-600 !text-white !shadow-[0_4px_12px_rgba(99,102,241,0.3)]'
: ''
"
@click="switchTimeRange('30days')"
>
近30日
</Button>
</div>
<!-- 分隔线 -->
<div class="mx-1 h-6 w-px bg-slate-300"></div>
<!-- 自定义时间 -->
<div
class="flex items-center gap-2 rounded-xl bg-white/30 px-3 py-1.5"
<!-- 时间选择器 -->
<div
class="flex items-center gap-2 rounded-2xl border border-slate-200 bg-slate-200/50 p-1.5"
>
<!-- 快速选择按钮组 -->
<div class="flex items-center gap-1 rounded-xl bg-white/30 p-1">
<Button
type="text"
size="small"
class="!h-auto !min-w-0 !rounded-xl !border-none !px-5 !py-2 !text-sm !font-bold !shadow-none !transition-colors"
:class="
activeTimeRange === 'today'
? '!bg-white !text-blue-600 !shadow-sm'
: '!bg-transparent !text-slate-600 hover:!bg-white/50'
"
@click="switchTimeRange('today')"
>
<span class="text-[10px] font-bold uppercase text-slate-400">
自定义
</span>
<DatePicker.RangePicker
v-model:value="customDateRange"
size="small"
format="YYYY-MM-DD"
:allow-clear="false"
class="!border-none !bg-transparent"
:class="
activeTimeRange === 'custom'
? '[&_.ant-picker-input>input]:!font-bold [&_.ant-picker-input>input]:!text-indigo-600'
: ''
"
@change="handleCustomDateRangeChange"
/>
</div>
今日
</Button>
<Button
type="text"
size="small"
class="!h-auto !min-w-0 !rounded-xl !border-none !px-5 !py-2 !text-sm !font-bold !shadow-none !transition-colors"
:class="
activeTimeRange === 'yesterday'
? '!bg-white !text-blue-600 !shadow-sm'
: '!bg-transparent !text-slate-600 hover:!bg-white/50'
"
@click="switchTimeRange('yesterday')"
>
昨日
</Button>
<Button
type="text"
size="small"
class="!h-auto !min-w-0 !rounded-xl !border-none !px-5 !py-2 !text-sm !font-bold !shadow-none !transition-colors"
:class="
activeTimeRange === '7days'
? '!bg-white !text-blue-600 !shadow-sm'
: '!bg-transparent !text-slate-600 hover:!bg-white/50'
"
@click="switchTimeRange('7days')"
>
近7日
</Button>
<Button
type="text"
size="small"
class="!h-auto !min-w-0 !rounded-xl !border-none !px-5 !py-2 !text-sm !font-bold !shadow-none !transition-colors"
:class="
activeTimeRange === '30days'
? '!bg-white !text-blue-600 !shadow-sm'
: '!bg-transparent !text-slate-600 hover:!bg-white/50'
"
@click="switchTimeRange('30days')"
>
近30日
</Button>
</div>
<!-- 分隔线 -->
<div class="h-6 w-px bg-slate-300"></div>
<!-- 自定义日期选择器 -->
<div class="flex items-center gap-2 rounded-xl bg-white/30 px-3 py-1.5">
<span class="text-xs font-bold text-slate-400">自定义日期</span>
<DatePicker.RangePicker
v-model:value="customDateRange"
size="small"
format="YYYY-MM-DD"
:allow-clear="false"
:placeholder="['开始日期', '结束日期']"
class="!border-none !bg-transparent !text-sm !font-bold"
@change="handleCustomDateRangeChange"
/>
</div>
</div>
</template>
<Spin :spinning="loading">
<div class="mx-auto max-w-[1600px] space-y-8 p-6">
<!-- 汇总卡片 -->
<div class="grid grid-cols-1 gap-6 md:grid-cols-4">
<!-- 全店总销售额 -->
<div class="mx-auto w-full space-y-6 p-4 md:p-8">
<!-- 第一层:核心汇总指标 -->
<div class="grid grid-cols-1 gap-6 sm:grid-cols-2 xl:grid-cols-4">
<!-- 销售额 -->
<div
class="rounded-[2rem] border border-white/60 bg-white/50 bg-gradient-to-br from-indigo-500/10 to-transparent p-8 shadow-[0_10px_30px_rgba(0,0,0,0.02)] backdrop-blur-[20px]"
class="rounded-2xl border border-slate-200 bg-white/90 p-6 shadow-[0_4px_12px_rgba(0,0,0,0.03)] backdrop-blur-[10px]"
>
<div class="text-sm font-bold text-slate-500">全店总销售额</div>
<div class="mt-1 text-3xl font-black">
<div class="mb-4 flex items-start justify-between">
<span class="text-xs font-black text-slate-500">
全店总销售额
</span>
<span
v-if="overviewData?.monthOverMonthGrowth !== undefined"
class="rounded bg-emerald-50 px-2 py-1 text-xs font-bold text-emerald-600"
>
{{ formatPercent(overviewData.monthOverMonthGrowth) }} 较上月
</span>
</div>
<div class="text-4xl font-black leading-none text-slate-900">
{{
overviewData?.totalSalesAmount
? formatAmount(overviewData.totalSalesAmount)
@@ -433,153 +432,346 @@ onMounted(async () => {
}}
</div>
<div
v-if="overviewData?.monthOverMonthGrowth !== undefined"
class="mt-4 w-fit rounded-lg bg-emerald-50 px-2 py-1 text-xs font-bold text-emerald-500"
v-if="overviewData?.salesAmountAchievementRate !== undefined"
class="mt-6 flex items-center justify-between border-t border-slate-100 pt-4"
>
{{ formatPercent(overviewData.monthOverMonthGrowth) }} 较上月同期
<span class="text-xs font-bold text-slate-400">
销售额目标达成率
</span>
>
<span class="text-sm font-black text-blue-600">
{{
formatPercentPlain(overviewData.salesAmountAchievementRate)
}}
</span>
</div>
</div>
<!-- 全店总单量 -->
<!-- ROI效率 -->
<div
class="rounded-[2rem] border border-white/60 bg-white/50 p-8 shadow-[0_10px_30px_rgba(0,0,0,0.02)] backdrop-blur-[20px]"
class="rounded-2xl border border-slate-200 bg-white/90 p-6 shadow-[0_4px_12px_rgba(0,0,0,0.03)] backdrop-blur-[10px]"
>
<div class="text-sm font-bold text-slate-500">全店总单量</div>
<div class="mt-1 text-3xl font-black">
{{
overviewData?.totalOrderCount?.toLocaleString('zh-CN') || '-'
}}
<div class="mb-4 text-xs font-black text-slate-500">
投资回报率 (ROI)
</div>
<div class="mt-4 text-xs font-bold italic text-slate-400">
目标达成率 92%
<div class="text-4xl font-black leading-none text-indigo-600">
{{ overviewData?.totalROI?.toFixed(2) || '-' }}
</div>
<div
v-if="overviewData?.averageFeeRatio !== undefined"
class="mt-6 flex justify-between border-t border-slate-100 pt-4 text-xs font-bold text-slate-400"
>
<span>全店平均费比</span>
<span class="text-slate-900">
{{ formatPercentPlain(overviewData.averageFeeRatio) }}
</span>
</div>
</div>
<!-- 总推广费支出 -->
<!-- 订单达成 -->
<div
class="rounded-[2rem] border border-white/60 bg-white/50 p-8 shadow-[0_10px_30px_rgba(0,0,0,0.02)] backdrop-blur-[20px]"
class="rounded-2xl border border-slate-200 bg-white/90 p-6 shadow-[0_4px_12px_rgba(0,0,0,0.03)] backdrop-blur-[10px]"
>
<div class="text-sm font-bold text-slate-500">总推广费支出</div>
<div class="mt-1 text-3xl font-black">
<div class="mb-4 text-xs font-black text-slate-500">
销量目标达成率 (订单数)
</div>
<div class="text-4xl font-black leading-none text-slate-900">
{{
overviewData?.totalPromotionFee
? formatAmount(overviewData.totalPromotionFee)
overviewData?.orderCountAchievementRate !== undefined
? formatPercentPlain(overviewData.orderCountAchievementRate)
: '-'
}}
</div>
<div class="mt-4 text-xs font-bold text-indigo-400">
平均费比:
{{
overviewData?.averageFeeRatio
? `${overviewData.averageFeeRatio.toFixed(1)}%`
: '-'
}}
<div
v-if="overviewData?.orderCountAchievementRate !== undefined"
class="mt-6 h-2 w-full overflow-hidden rounded-full bg-slate-100"
>
<div
class="h-full bg-indigo-500"
:style="{
width: `${Math.min(overviewData.orderCountAchievementRate, 100)}%`,
}"
></div>
</div>
</div>
<!-- 全店总净利 -->
<!-- 税后利润 -->
<div
class="rounded-[2rem] border border-white/60 bg-white/50 bg-gradient-to-br from-emerald-500/10 to-transparent p-8 shadow-[0_10px_30px_rgba(0,0,0,0.02)] backdrop-blur-[20px]"
class="rounded-2xl border-l-4 border-slate-200 border-l-emerald-500 bg-white/90 p-6 shadow-[0_4px_12px_rgba(0,0,0,0.03)] backdrop-blur-[10px]"
>
<div class="text-sm font-bold text-slate-500">
全店总净利 (税后)
<div class="mb-4 text-xs font-black text-emerald-600">
全店总净利润 (税后)
</div>
<div class="mt-1 text-3xl font-black text-emerald-600">
<div class="text-4xl font-black leading-none text-emerald-600">
{{
overviewData?.totalNetProfitAfterTax
? formatAmount(overviewData.totalNetProfitAfterTax)
: '-'
}}
</div>
<div class="mt-4 text-xs font-bold text-slate-400">
扣除总税额:
{{
overviewData?.totalTaxAmount
? formatAmount(overviewData.totalTaxAmount)
: '-'
}}
<div
v-if="overviewData?.totalTaxAmount !== undefined"
class="mt-6 flex justify-between border-t border-slate-100 pt-4 text-[11px] font-bold text-slate-400"
>
<span>已扣除预扣税额 (4%)</span>
<span>{{ formatAmount(overviewData.totalTaxAmount) }}</span>
</div>
</div>
</div>
<!-- 各店对比分析 -->
<div class="grid grid-cols-1 gap-8 lg:grid-cols-2">
<!-- 店铺销售占比排行 -->
<!-- 第二层:深度分析图表 -->
<div class="grid grid-cols-1 gap-6 xl:grid-cols-2">
<!-- 销售占比排行 -->
<div
class="rounded-[2rem] border border-white/60 bg-white/50 p-8 shadow-[0_10px_30px_rgba(0,0,0,0.02)] backdrop-blur-[20px]"
class="rounded-2xl border border-slate-200 bg-white/90 p-8 shadow-[0_4px_12px_rgba(0,0,0,0.03)] backdrop-blur-[10px]"
>
<h3 class="mb-6 text-xl font-bold">各店铺销售占比排行</h3>
<div class="h-[400px]">
<h3 class="mb-6 text-lg font-black text-slate-800">
各店铺销售贡献排行
</h3>
<div class="h-[380px] w-full">
<EchartsUI ref="barChartRef" />
</div>
</div>
<!-- 店铺效率象限 -->
<!-- 效率象限图 -->
<div
class="rounded-[2rem] border border-white/60 bg-white/50 p-8 shadow-[0_10px_30px_rgba(0,0,0,0.02)] backdrop-blur-[20px]"
class="rounded-2xl border border-slate-200 bg-white/90 p-8 shadow-[0_4px_12px_rgba(0,0,0,0.03)] backdrop-blur-[10px]"
>
<h3 class="mb-6 text-xl font-bold">店铺效率象限 (ROI vs 净利)</h3>
<div class="h-[400px]">
<h3 class="mb-6 text-lg font-black text-slate-800">
店铺经营效率象限 (ROI vs 净利)
</h3>
<div class="h-[380px] w-full">
<EchartsUI ref="scatterChartRef" />
</div>
<!-- 象限图说明 -->
<div class="mt-4 flex justify-center gap-6">
<div
class="flex items-center gap-2 text-xs font-bold text-slate-600"
>
<span class="h-3 w-3 rounded-full bg-emerald-500"></span>
高产区
</div>
<div
class="flex items-center gap-2 text-xs font-bold text-slate-600"
>
<span class="h-3 w-3 rounded-full bg-blue-500"></span>
潜力区
</div>
<div
class="flex items-center gap-2 text-xs font-bold text-slate-600"
>
<span class="h-3 w-3 rounded-full bg-rose-500"></span>
风险区
</div>
</div>
</div>
</div>
<!-- 店铺多维度对比表 -->
<!-- 第三层:横向对比大表 (16维度) -->
<div
class="overflow-hidden rounded-[2rem] border border-white/60 bg-white/50 shadow-[0_10px_30px_rgba(0,0,0,0.02)] backdrop-blur-[20px]"
class="overflow-hidden rounded-2xl border border-slate-200 bg-white/90 shadow-[0_4px_12px_rgba(0,0,0,0.03)] backdrop-blur-[10px]"
>
<div class="flex items-center justify-between p-8">
<h3 class="text-xl font-bold">多店铺数据横向对比</h3>
<div
class="flex flex-col items-start justify-between gap-4 border-b border-slate-100 p-8 md:flex-row md:items-center"
>
<div>
<h3 class="text-xl font-black text-slate-800">
各店铺多维度经营明细对比
</h3>
<p class="mt-1 text-xs font-bold text-slate-400">
包含:目标达成、规模、成本及最终损益所有维度
</p>
</div>
<Button
type="primary"
class="!h-auto !rounded-2xl !border-none !bg-slate-900 !px-8 !py-3 !text-sm !font-bold !shadow-xl !shadow-slate-200 !transition-all hover:!scale-105 active:!scale-95"
>
导出财务分析报表
</Button>
</div>
<div class="overflow-x-auto px-4 pb-6">
<table class="w-full border-collapse whitespace-nowrap text-left">
<div class="table-container overflow-x-auto">
<table class="w-full whitespace-nowrap text-left text-sm">
<!-- 表头分组 -->
<thead
class="border-b border-white/40 text-[11px] uppercase text-slate-400"
class="bg-slate-50 text-[11px] font-black uppercase text-slate-500"
>
<tr>
<th class="p-4 font-black">店铺名称</th>
<th class="p-4 font-black">销售额</th>
<th class="p-4 font-black text-indigo-600">ROI</th>
<th class="p-4 font-black text-red-400">退款/刷单费</th>
<th class="p-4 font-black">推广费总和</th>
<th class="p-4 font-black text-emerald-600">税后盈亏</th>
<th
rowspan="2"
class="sticky-col border-b p-6 text-sm font-black text-slate-900 shadow-sm"
>
店铺名称
</th>
<th
colspan="4"
class="border-b border-l border-slate-200 bg-blue-50/50 p-3 text-center text-blue-700"
>
目标达成维度
</th>
<th
colspan="3"
class="border-b border-l border-slate-200 bg-slate-100/50 p-3 text-center"
>
经营规模维度
</th>
<th
colspan="5"
class="border-b border-l border-slate-200 bg-orange-50/50 p-3 text-center text-orange-700"
>
成本费用维度
</th>
<th
colspan="4"
class="border-b border-l border-slate-200 bg-emerald-50/50 p-3 text-center text-emerald-700"
>
盈利分析维度
</th>
</tr>
<tr class="bg-slate-50/80">
<!-- 目标 -->
<th class="border-b border-l px-6 py-4">目标单量</th>
<th class="border-b px-6 py-4 text-blue-600">单量达成率</th>
<th class="border-b px-6 py-4">目标额</th>
<th class="border-b px-6 py-4 text-blue-600">销售达成率</th>
<!-- 规模 -->
<th
class="border-b border-l px-6 py-4 font-black text-slate-900"
>
实际销售额
</th>
<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 px-6 py-4 font-bold text-rose-600">
退款金额
</th>
<th class="border-b px-6 py-4">推广费</th>
<th class="border-b px-6 py-4 text-orange-600">刷单费用</th>
<th class="border-b px-6 py-4 text-slate-400">费比 %</th>
<!-- 盈利 -->
<th class="border-b border-l px-6 py-4 font-bold">
税前盈亏
</th>
<th class="border-b px-6 py-4 italic text-rose-500">
4%税额
</th>
<th class="border-b px-6 py-4 font-black text-indigo-700">
ROI
</th>
<th
class="border-b bg-emerald-600 px-6 py-4 font-black text-white"
>
税后盈亏
</th>
</tr>
</thead>
<tbody class="text-sm">
<tbody class="divide-y divide-slate-100">
<tr
v-for="shop in overviewData?.shopComparisons"
:key="shop.shopId"
class="border-t border-white/20 transition hover:bg-white/40"
class="transition-colors hover:bg-blue-50/50"
>
<td class="p-4 font-bold">{{ shop.shopName }}</td>
<td class="p-4">
{{ formatAmountFull(shop.salesAmount) }}
<td
class="sticky-col border-r-2 border-slate-100 bg-white p-6 font-bold text-slate-900 shadow-sm"
>
{{ shop.shopName }}
</td>
<td class="p-4 font-black text-indigo-600">
{{ shop.roi?.toFixed(2) || '-' }}
<!-- 目标 -->
<td class="p-6 font-medium">
{{ shop.targetOrderCount?.toLocaleString('zh-CN') || '-' }}
</td>
<td class="p-4 text-red-400">
{{ formatAmountFull(shop.refundAmount || 0) }} /
{{ formatAmountFull(shop.brushFee || 0) }}
</td>
<td class="p-4">
<td class="p-6 font-black text-blue-600">
{{
shop.totalPromotionFee
? formatAmountFull(shop.totalPromotionFee)
shop.orderCountAchievementRate !== undefined
? formatPercentPlain(shop.orderCountAchievementRate)
: '-'
}}
</td>
<td class="p-4 font-black text-emerald-600">
<td class="p-6 font-medium">
{{
shop.targetAmount ? formatAmount(shop.targetAmount) : '-'
}}
</td>
<td class="p-6 font-black text-blue-600">
{{
shop.salesAmountAchievementRate !== undefined
? formatPercentPlain(shop.salesAmountAchievementRate)
: '-'
}}
</td>
<!-- 规模 -->
<td class="p-6 font-black">
{{ formatAmount(shop.salesAmount) }}
</td>
<td class="p-6 font-medium">
{{ shop.orderCount?.toLocaleString('zh-CN') || '-' }}
</td>
<td class="p-6 font-medium">
{{
shop.averageOrderValue
? formatAmount(shop.averageOrderValue)
: '-'
}}
</td>
<!-- 成本 -->
<td class="p-6">
{{
shop.shippingCost ? formatAmount(shop.shippingCost) : '-'
}}
</td>
<td class="p-6 font-bold text-rose-600">
{{
shop.refundAmount ? formatAmount(shop.refundAmount) : '-'
}}
</td>
<td class="p-6">
{{
shop.totalPromotionFee
? formatAmount(shop.totalPromotionFee)
: '-'
}}
</td>
<td class="p-6 text-orange-600">
{{ shop.brushFee ? formatAmount(shop.brushFee) : '-' }}
</td>
<td class="p-6 text-slate-400">
{{
shop.feeRatio !== undefined
? formatPercentPlain(shop.feeRatio)
: '-'
}}
</td>
<!-- 盈利 -->
<td class="p-6 font-bold">
{{
shop.totalProfitBeforeTax
? formatAmount(shop.totalProfitBeforeTax)
: '-'
}}
</td>
<td class="p-6 italic text-slate-400">
{{
shop.salesTaxAmount
? formatAmount(shop.salesTaxAmount)
: '-'
}}
</td>
<td class="p-6 font-black text-indigo-700">
{{ shop.roi?.toFixed(2) || '-' }}
</td>
<td
class="bg-emerald-50 p-6 text-base font-black text-emerald-600"
>
{{
shop.profitAfterTax
? formatAmountFull(shop.profitAfterTax)
? formatAmount(shop.profitAfterTax)
: '-'
}}
</td>
</tr>
<tr v-if="!overviewData?.shopComparisons?.length">
<td colspan="6" class="p-8 text-center text-gray-400">
<td colspan="17" class="p-8 text-center text-gray-400">
暂无数据
</td>
</tr>
@@ -593,5 +785,22 @@ onMounted(async () => {
</template>
<style scoped>
/* 自定义样式 */
/* 表格滚动条 */
.table-container::-webkit-scrollbar {
height: 8px;
}
.table-container::-webkit-scrollbar-thumb {
background: #cbd5e1;
border-radius: 10px;
}
.table-container::-webkit-scrollbar-track {
background: #f1f5f9;
}
/* 固定首列 */
.sticky-col {
position: sticky;
left: 0;
z-index: 10;
}
</style>
@@ -0,0 +1,274 @@
<script setup lang="ts">
import type {
ShopMonthlyTargetDTO,
ShopMonthlyTargetVO,
} from '#/api/ecommerce/shop-monthly-target';
import type { ShopVO } from '#/api/ecommerce/shop/types';
import dayjs from 'dayjs';
import { onMounted, ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import {
DatePicker,
Form,
Input,
InputNumber,
message,
Select,
} from 'ant-design-vue';
import {
createShopMonthlyTargetApi,
updateShopMonthlyTargetApi,
} from '#/api/ecommerce/shop-monthly-target';
import { getShopPageApi } from '#/api/ecommerce/shop';
defineOptions({ name: 'ShopMonthlyTargetFormModal' });
const props = defineProps<Props>();
const emit = defineEmits<Emits>();
// Props
interface Props {
open: boolean;
shopMonthlyTargetData?: null | ShopMonthlyTargetVO.Info;
}
// Emits
interface Emits {
(e: 'update:open', value: boolean): void;
(e: 'success'): void;
(e: 'cancel'): void;
}
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[700px]',
onCancel() {
handleCancel();
},
onConfirm() {
handleOk();
},
});
// 响应式数据
const formRef = ref();
const isEdit = ref(false);
// 表单数据
const formData = ref<ShopMonthlyTargetDTO.Create>({
shopId: undefined as any,
targetMonth: '',
targetAmount: undefined as any,
targetOrderCount: undefined as any,
remark: '',
});
// 目标月份选择器的值(dayjs对象)
const targetMonthValue = ref<dayjs.Dayjs | null>(null);
// 表单验证规则
const rules = {
shopId: [{ required: true, message: '请选择店铺', trigger: 'change' }],
targetMonth: [
{ required: true, message: '请选择目标月份', trigger: 'change' },
],
targetAmount: [
{ required: true, message: '请输入目标销售额', trigger: 'blur' },
],
targetOrderCount: [
{ required: true, message: '请输入目标订单数', trigger: 'blur' },
],
} as any;
// 店铺列表
const shopList = ref<ShopVO.Info[]>([]);
const shopListLoading = ref(false);
// 监听props变化
watch(
() => props.open,
(newVal) => {
if (newVal) {
modalApi.open();
isEdit.value = !!props.shopMonthlyTargetData;
if (props.shopMonthlyTargetData) {
// 编辑模式,填充表单数据
formData.value = {
shopId: props.shopMonthlyTargetData.shopId,
targetMonth: props.shopMonthlyTargetData.targetMonth,
targetAmount: props.shopMonthlyTargetData.targetAmount,
targetOrderCount: props.shopMonthlyTargetData.targetOrderCount,
remark: props.shopMonthlyTargetData.remark || '',
};
// 设置目标月份选择器的值
targetMonthValue.value = dayjs(props.shopMonthlyTargetData.targetMonth);
} else {
// 新增模式,重置表单数据
resetFormData();
}
} else {
modalApi.close();
}
},
{ immediate: true },
);
// 监听目标月份选择器变化
watch(
() => targetMonthValue.value,
(newVal) => {
if (newVal) {
// 格式化为 YYYY-MM-01
formData.value.targetMonth = newVal.format('YYYY-MM-01');
} else {
formData.value.targetMonth = '';
}
},
);
// 加载店铺列表
const loadShopList = async () => {
shopListLoading.value = true;
try {
const response = await getShopPageApi({
page: 1,
pageSize: 1000,
filters: {},
});
shopList.value = response.records;
} catch (error) {
console.error('加载店铺列表失败:', error);
} finally {
shopListLoading.value = false;
}
};
// 重置表单数据
const resetFormData = () => {
formData.value = {
shopId: undefined as any,
targetMonth: '',
targetAmount: undefined as any,
targetOrderCount: undefined as any,
remark: '',
};
targetMonthValue.value = null;
};
// 确认操作
const handleOk = async () => {
try {
await formRef.value?.validate();
if (isEdit.value && props.shopMonthlyTargetData) {
// 更新店铺月销量目标
const updateData: ShopMonthlyTargetDTO.Update = {
targetMonth: formData.value.targetMonth,
targetAmount: formData.value.targetAmount,
targetOrderCount: formData.value.targetOrderCount,
remark: formData.value.remark,
};
await updateShopMonthlyTargetApi(
props.shopMonthlyTargetData.id,
updateData,
);
message.success('更新成功');
} else {
// 创建店铺月销量目标
await createShopMonthlyTargetApi(formData.value);
message.success('创建成功');
}
emit('success');
modalApi.close();
emit('update:open', false);
} catch (error) {
console.error('操作失败:', error);
message.error(isEdit.value ? '更新失败' : '创建失败');
}
};
// 取消操作
const handleCancel = () => {
emit('cancel');
modalApi.close();
emit('update:open', false);
resetFormData();
};
// 组件挂载时加载数据
onMounted(() => {
loadShopList();
});
</script>
<template>
<Modal :title="isEdit ? '编辑月销量目标' : '新增月销量目标'">
<Form
ref="formRef"
:model="formData"
:rules="rules"
:label-col="{ span: 6 }"
:wrapper-col="{ span: 18 }"
>
<Form.Item label="店铺" name="shopId" required>
<Select
v-model:value="formData.shopId"
placeholder="请选择店铺"
:loading="shopListLoading"
:options="
shopList.map((shop) => ({
label: shop.name,
value: shop.id,
}))
"
/>
</Form.Item>
<Form.Item label="目标月份" name="targetMonth" required>
<DatePicker
v-model:value="targetMonthValue"
placeholder="请选择目标月份"
picker="month"
format="YYYY-MM"
style="width: 100%"
/>
</Form.Item>
<Form.Item label="目标销售额" name="targetAmount" required>
<InputNumber
v-model:value="formData.targetAmount"
placeholder="请输入目标销售额"
:min="0"
:precision="2"
style="width: 100%"
/>
</Form.Item>
<Form.Item label="目标订单数" name="targetOrderCount" required>
<InputNumber
v-model:value="formData.targetOrderCount"
placeholder="请输入目标订单数"
:min="0"
:precision="0"
style="width: 100%"
/>
</Form.Item>
<Form.Item label="备注" name="remark">
<Input.TextArea
v-model:value="formData.remark"
placeholder="请输入备注(可选)"
:rows="4"
/>
</Form.Item>
</Form>
</Modal>
</template>
@@ -0,0 +1,330 @@
<script lang="ts" setup>
import type { VxeGridProps } from '#/adapter/vxe-table';
import type {
ShopMonthlyTargetDTO,
ShopMonthlyTargetVO,
} from '#/api/ecommerce/shop-monthly-target';
import type { ShopVO } from '#/api/ecommerce/shop/types';
import type { PageQueryDTO } from '#/types/common';
import { computed, onMounted, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
import { Button, message, Popconfirm, Space } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getShopPageApi } from '#/api/ecommerce/shop';
import {
deleteShopMonthlyTargetApi,
getShopMonthlyTargetPageApi,
} from '#/api/ecommerce/shop-monthly-target';
import ShopMonthlyTargetFormModal from './components/ShopMonthlyTargetFormModal.vue';
defineOptions({ name: 'ShopMonthlyTargetManagement' });
// 创建图标组件
const PlusIcon = createIconifyIcon('lucide:plus');
// 响应式数据
const loading = ref(false);
const formModalVisible = ref(false);
const currentShopMonthlyTargetData = ref<null | ShopMonthlyTargetVO.Info>(null);
// 搜索表单
const searchForm = ref({
shopId: undefined as number | undefined,
startTargetMonth: undefined as string | undefined,
endTargetMonth: undefined as string | undefined,
});
// 店铺选项
const shopOptions = ref<{ label: string; value: number }[]>([]);
// VbenVxeGrid 表格配置
const gridOptions: VxeGridProps<any> = {
columns: [
{
type: 'seq' as const,
minWidth: 'auto',
title: '序号',
},
{
field: 'shopName',
title: '店铺名称',
minWidth: 'auto',
showOverflow: 'tooltip' as const,
},
{
field: 'targetMonth',
title: '目标月份',
minWidth: 'auto',
},
{
title: '目标销售额',
minWidth: 'auto',
slots: { default: 'targetAmount' },
},
{
field: 'targetOrderCount',
title: '目标订单数',
minWidth: 'auto',
},
{
field: 'remark',
title: '备注',
minWidth: 'auto',
showOverflow: 'tooltip' as const,
},
{
field: 'createTime',
title: '创建时间',
minWidth: 'auto',
},
{
title: '操作',
minWidth: 'auto',
fixed: 'right' as const,
slots: { default: 'action' },
},
],
height: 'auto',
border: true,
stripe: true,
highlightHoverRow: true,
showOverflow: true,
size: 'small',
toolbarConfig: {
custom: true,
refresh: true,
zoom: true,
},
data: [],
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50, 100],
layouts: [
'PrevJump',
'PrevPage',
'Number',
'NextPage',
'NextJump',
'Sizes',
'FullJump',
'Total',
] as (
| 'FullJump'
| 'NextJump'
| 'NextPage'
| 'Number'
| 'PrevJump'
| 'PrevPage'
| 'Sizes'
| 'Total'
)[],
},
// 配置远程加载
proxyConfig: {
ajax: {
query: async ({ page }) => {
try {
loading.value = true;
const params: PageQueryDTO<ShopMonthlyTargetDTO.Filters> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
shopId: searchForm.value.shopId,
startTargetMonth: searchForm.value.startTargetMonth,
endTargetMonth: searchForm.value.endTargetMonth,
},
};
const data = await getShopMonthlyTargetPageApi(params);
return {
items: data.records,
total: data.total,
};
} catch (error) {
console.error('获取店铺月销量目标列表失败:', error);
message.error('获取店铺月销量目标列表失败');
return {
items: [],
total: 0,
};
} finally {
loading.value = false;
}
},
},
},
};
// 搜索表单配置
const formOptions = computed(() => ({
schema: [
{
component: 'Select',
componentProps: {
placeholder: '请选择店铺',
options: shopOptions.value,
allowClear: true,
},
fieldName: 'shopId',
label: '店铺',
},
{
component: 'DatePicker',
componentProps: {
placeholder: '开始月份',
picker: 'month',
style: { width: '100%' },
},
fieldName: 'startTargetMonth',
label: '目标月份',
},
{
component: 'DatePicker',
componentProps: {
placeholder: '结束月份',
picker: 'month',
style: { width: '100%' },
},
fieldName: 'endTargetMonth',
label: '至',
},
],
showDefaultActions: true,
collapsed: true,
collapsedRows: 1,
}));
// 刷新表格数据
function refreshTable() {
if (gridApi) {
gridApi.reload();
}
}
// 创建 VbenVxeGrid 实例
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
formOptions: formOptions.value,
showSearchForm: true,
tableTitle: '店铺月销量目标管理',
});
// 处理新增
const handleAdd = () => {
currentShopMonthlyTargetData.value = null;
formModalVisible.value = true;
};
// 处理编辑
const handleEdit = (record: ShopMonthlyTargetVO.Info) => {
currentShopMonthlyTargetData.value = record;
formModalVisible.value = true;
};
// 处理删除
const handleDelete = async (id: number) => {
try {
await deleteShopMonthlyTargetApi(id);
message.success('删除成功');
refreshTable();
} catch {
message.error('删除失败');
}
};
// 处理表单成功
const handleFormSuccess = () => {
refreshTable();
};
// 格式化金额
const formatAmount = (amount: number) => {
return `¥${amount.toFixed(2)}`;
};
// 获取店铺选项
const fetchShopOptions = async () => {
try {
const response = await getShopPageApi({
page: 1,
pageSize: 1000,
filters: {},
});
shopOptions.value = response.records.map((shop: ShopVO.Info) => ({
label: shop.name,
value: shop.id,
}));
} catch (error) {
console.error('获取店铺列表失败:', error);
}
};
// 初始化
onMounted(() => {
fetchShopOptions();
});
</script>
<template>
<Page title="店铺月销量目标管理" auto-content-height>
<template #description>
<div class="text-foreground/80 mt-2">
管理店铺月销量目标,支持按店铺、目标月份等维度查询和统计
</div>
</template>
<template #extra>
<Space>
<Button type="primary" @click="handleAdd">
<PlusIcon class="mr-2 h-4 w-4" />
新增月销量目标
</Button>
</Space>
</template>
<!-- 数据表格 -->
<Grid :loading="loading">
<!-- 工具栏工具 -->
<template #toolbar-tools>
<Space>
<span class="text-gray-500">
支持按店铺、目标月份等维度查询月销量目标
</span>
</Space>
</template>
<!-- 目标销售额列 -->
<template #targetAmount="{ row }: { row: any }">
<span class="font-medium text-red-600">
{{ formatAmount(row.targetAmount) }}
</span>
</template>
<!-- 操作列 -->
<template #action="{ row }: { row: any }">
<Space>
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
<Popconfirm
title="确定要删除这条月销量目标吗?"
@confirm="handleDelete(row.id)"
>
<Button size="small" danger> 删除 </Button>
</Popconfirm>
</Space>
</template>
</Grid>
<!-- 表单弹窗 -->
<ShopMonthlyTargetFormModal
v-model:open="formModalVisible"
:shop-monthly-target-data="currentShopMonthlyTargetData"
@success="handleFormSuccess"
@cancel="formModalVisible = false"
/>
</Page>
</template>
@@ -0,0 +1,306 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>全店铺经营看板</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js"></script>
<!-- 引入中文字体优化 -->
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700;900&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Noto Sans SC', sans-serif;
background-color: #f8fafc; /* 参考背景色 */
color: #0f172a; /* 加深文字颜色提升清晰度 */
}
.glass-card {
background: rgba(255, 255, 255, 0.9); /* 增加不透明度提升识别度 */
backdrop-filter: blur(10px);
border: 1px solid #e2e8f0;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
border-radius: 16px;
}
/* 表格滚动条 */
.table-container::-webkit-scrollbar { height: 8px; }
.table-container::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
.table-container::-webkit-scrollbar-track { background: #f1f5f9; }
/* 固定首列颜色 */
.sticky-col {
position: sticky;
left: 0;
background: #fff;
z-index: 10;
border-right: 2px solid #f1f5f9;
}
</style>
</head>
<body class="p-4 md:p-8">
<div class="w-full mx-auto space-y-6">
<!-- 头部:标题与筛选 -->
<header class="flex flex-col lg:flex-row justify-between items-start lg:items-center gap-6">
<div>
<h1 class="text-3xl font-black text-slate-900 tracking-tight">全店铺经营概览大盘</h1>
<p class="text-slate-500 font-bold mt-1 text-sm">数据范围:公司旗下所有店铺汇总统计</p>
</div>
<!-- 时间选择器 -->
<div class="flex items-center gap-2 bg-slate-200/50 p-1.5 rounded-2xl border border-slate-200">
<div class="flex gap-1">
<button class="bg-white px-5 py-2 text-sm font-bold rounded-xl shadow-sm text-blue-600">今日</button>
<button class="px-5 py-2 text-sm font-bold text-slate-600 hover:bg-white/50 rounded-xl transition">昨日</button>
<button class="px-5 py-2 text-sm font-bold text-slate-600 hover:bg-white/50 rounded-xl transition">近7日</button>
<button class="px-5 py-2 text-sm font-bold text-slate-600 hover:bg-white/50 rounded-xl transition">近30日</button>
</div>
<div class="w-px h-6 bg-slate-300 mx-2"></div>
<div class="flex items-center gap-2 px-3">
<span class="text-xs font-bold text-slate-400">自定义日期</span>
<input type="date" class="bg-transparent text-sm font-bold outline-none border-none cursor-pointer">
</div>
</div>
</header>
<!-- 第一层:核心汇总指标 (适配 Info 接口) -->
<div class="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-6">
<!-- 销售额 -->
<div class="glass-card p-6">
<div class="flex justify-between items-start mb-4">
<span class="text-xs font-black text-slate-500">全店总销售额</span>
<span class="text-xs font-bold text-emerald-600 bg-emerald-50 px-2 py-1 rounded">较上月 +14.2%</span>
</div>
<div class="text-4xl font-black text-slate-900 leading-none">¥4,829,400</div>
<div class="mt-6 pt-4 border-t border-slate-100 flex justify-between items-center">
<span class="text-xs font-bold text-slate-400">销售额目标达成率</span>
<span class="text-sm font-black text-blue-600">96.5%</span>
</div>
</div>
<!-- ROI效率 -->
<div class="glass-card p-6">
<div class="text-xs font-black text-slate-500 mb-4">投资回报率 (ROI)</div>
<div class="text-4xl font-black text-indigo-600 leading-none">4.05</div>
<div class="mt-6 pt-4 border-t border-slate-100">
<div class="flex justify-between text-xs font-bold text-slate-400">
<span>全店平均费比</span>
<span class="text-slate-900">24.6%</span>
</div>
</div>
</div>
<!-- 订单达成 -->
<div class="glass-card p-6">
<div class="text-xs font-black text-slate-500 mb-4">销量目标达成率 (订单数)</div>
<div class="text-4xl font-black text-slate-900 leading-none">92.1%</div>
<div class="w-full bg-slate-100 h-2 mt-6 rounded-full overflow-hidden">
<div class="bg-indigo-500 h-full" style="width: 92.1%"></div>
</div>
</div>
<!-- 税后利润 -->
<div class="glass-card p-6 border-l-4 border-l-emerald-500">
<div class="text-xs font-black text-emerald-600 mb-4">全店总净利润 (税后)</div>
<div class="text-4xl font-black text-emerald-600 leading-none">¥842,500</div>
<div class="mt-6 pt-4 border-t border-slate-100 flex justify-between text-[11px] font-bold text-slate-400">
<span>已扣除预扣税额 (4%)</span>
<span>¥193,176</span>
</div>
</div>
</div>
<!-- 第二层:深度分析图表 -->
<div class="grid grid-cols-1 xl:grid-cols-2 gap-6">
<!-- 销售占比排行 -->
<div class="glass-card p-8">
<h3 class="text-lg font-black text-slate-800 mb-6">各店铺销售贡献排行</h3>
<div id="salesRatioChart" style="height: 380px;" class="w-full"></div>
</div>
<!-- 效率象限图 -->
<div class="glass-card p-8">
<h3 class="text-lg font-black text-slate-800 mb-6">店铺经营效率象限 (ROI vs 净利)</h3>
<div id="efficiencyChart" style="height: 380px;" class="w-full"></div>
<!-- 象限图中文说明 -->
<div class="mt-4 flex gap-6 justify-center">
<div class="flex items-center gap-2 text-xs font-bold text-slate-600"><span class="w-3 h-3 bg-emerald-500 rounded-full"></span> 高产区</div>
<div class="flex items-center gap-2 text-xs font-bold text-slate-600"><span class="w-3 h-3 bg-blue-500 rounded-full"></span> 潜力区</div>
<div class="flex items-center gap-2 text-xs font-bold text-slate-600"><span class="w-3 h-3 bg-rose-500 rounded-full"></span> 风险区</div>
</div>
</div>
</div>
<!-- 第三层:横向对比大表 (适配 16 个维度) -->
<div class="glass-card overflow-hidden">
<div class="p-8 border-b border-slate-100 flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
<div>
<h3 class="text-xl font-black text-slate-800">各店铺多维度经营明细对比</h3>
<p class="text-xs text-slate-400 font-bold mt-1">包含:目标达成、规模、成本及最终损益所有维度</p>
</div>
<button class="bg-slate-900 text-white px-8 py-3 rounded-2xl text-sm font-bold shadow-xl shadow-slate-200 hover:scale-105 active:scale-95 transition-all">导出财务分析报表</button>
</div>
<div class="table-container overflow-x-auto">
<table class="w-full text-left text-sm whitespace-nowrap">
<!-- 表头分组 -->
<thead class="bg-slate-50 text-[11px] font-black text-slate-500 uppercase">
<tr>
<th rowspan="2" class="p-6 border-b sticky-col shadow-sm text-slate-900 text-sm">店铺名称</th>
<th colspan="4" class="p-3 border-b border-l border-slate-200 text-center bg-blue-50/50 text-blue-700">目标达成维度</th>
<th colspan="3" class="p-3 border-b border-l border-slate-200 text-center bg-slate-100/50">经营规模维度</th>
<th colspan="5" class="p-3 border-b border-l border-slate-200 text-center bg-orange-50/50 text-orange-700">成本费用维度</th>
<th colspan="4" class="p-3 border-b border-l border-slate-200 text-center bg-emerald-50/50 text-emerald-700">盈利分析维度</th>
</tr>
<tr class="bg-slate-50/80">
<!-- 目标 -->
<th class="px-6 py-4 border-b border-l">目标单量</th>
<th class="px-6 py-4 border-b text-blue-600">单量达成率</th>
<th class="px-6 py-4 border-b">目标额</th>
<th class="px-6 py-4 border-b text-blue-600">销售达成率</th>
<!-- 规模 -->
<th class="px-6 py-4 border-b border-l text-slate-900">实际销售额</th>
<th class="px-6 py-4 border-b">单量</th>
<th class="px-6 py-4 border-b">客单价</th>
<!-- 成本 -->
<th class="px-6 py-4 border-b border-l">成本运费</th>
<th class="px-6 py-4 border-b text-rose-600">退款金额</th>
<th class="px-6 py-4 border-b">推广费</th>
<th class="px-6 py-4 border-b">刷单费用</th>
<th class="px-6 py-4 border-b">费比 %</th>
<!-- 盈利 -->
<th class="px-6 py-4 border-b border-l">税前盈亏</th>
<th class="px-6 py-4 border-b text-rose-500 italic">4%税额</th>
<th class="px-6 py-4 border-b font-black text-indigo-700">ROI</th>
<th class="px-6 py-4 border-b bg-emerald-600 text-white font-black">税后盈亏</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
<!-- 演示数据 -->
<tr class="hover:bg-blue-50/50 transition-colors">
<td class="p-6 font-bold text-slate-900 sticky-col shadow-sm">精品家居旗舰店</td>
<!-- 目标 -->
<td class="p-6 font-medium">2,000</td>
<td class="p-6 font-black text-blue-600">85.4%</td>
<td class="p-6 font-medium">¥320,000</td>
<td class="p-6 font-black text-blue-600">92.1%</td>
<!-- 规模 -->
<td class="p-6 font-black">¥294,000</td>
<td class="p-6 font-medium">1,708</td>
<td class="p-6 font-medium">¥172.1</td>
<!-- 成本 -->
<td class="p-6">¥82,400</td>
<td class="p-6 text-rose-600 font-bold">¥12,400</td>
<td class="p-6">¥45,000</td>
<td class="p-6 text-orange-600">¥4,500</td>
<td class="p-6 text-slate-400">15.3%</td>
<!-- 盈利 -->
<td class="p-6 font-bold">¥142,500</td>
<td class="p-6 text-slate-400 italic">¥11,760</td>
<td class="p-6 font-black text-indigo-700">4.21</td>
<td class="p-6 font-black text-emerald-600 bg-emerald-50 text-base">¥124,500</td>
</tr>
<!-- 第二行数据 -->
<tr class="hover:bg-blue-50/50 transition-colors">
<td class="p-6 font-bold text-slate-900 sticky-col shadow-sm">运动户外品牌店</td>
<!-- 目标 -->
<td class="p-6">5,000</td>
<td class="p-6 font-black text-emerald-600">105.2%</td>
<td class="p-6">¥1,000,000</td>
<td class="p-6 font-black text-emerald-600">108.4%</td>
<!-- 规模 -->
<td class="p-6 font-black">¥1,084,000</td>
<td class="p-6">5,210</td>
<td class="p-6">¥208.1</td>
<!-- 成本 -->
<td class="p-6">¥324,000</td>
<td class="p-6 text-rose-600 font-bold">¥42,100</td>
<td class="p-6">¥185,000</td>
<td class="p-6 text-orange-600">¥10,000</td>
<td class="p-6 text-slate-400">17.1%</td>
<!-- 盈利 -->
<td class="p-6 font-bold">¥485,000</td>
<td class="p-6 text-slate-400 italic">¥43,360</td>
<td class="p-6 font-black text-indigo-700">5.85</td>
<td class="p-6 font-black text-emerald-600 bg-emerald-50 text-base">¥441,640</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<script>
// 1. 各店铺排行 (中文优化)
const salesChart = echarts.init(document.getElementById('salesRatioChart'));
salesChart.setOption({
grid: { left: '3%', right: '12%', bottom: '3%', top: '3%', containLabel: true },
tooltip: { trigger: 'axis' },
xAxis: { type: 'value', axisLabel: { show: false }, splitLine: { show: false } },
yAxis: {
type: 'category',
data: ['海外旗舰店', '运动户外店', '潮流男装店', '精品家居店'],
axisLine: { show: false },
axisTick: { show: false },
axisLabel: { fontWeight: 'bold', color: '#1e293b', fontSize: 13 }
},
series: [{
type: 'bar',
data: [420000, 1084000, 1150000, 1284000],
barWidth: 20,
itemStyle: {
borderRadius: [0, 10, 10, 0],
color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [
{ offset: 0, color: '#6366f1' },
{ offset: 1, color: '#a5b4fc' }
])
},
label: { show: true, position: 'right', formatter: '¥{c}', fontWeight: '900', color: '#0f172a' }
}]
});
// 2. 效率象限图 (中文标签)
const efficiencyChart = echarts.init(document.getElementById('efficiencyChart'));
efficiencyChart.setOption({
tooltip: {
formatter: (params) => `<div style="padding:4px font-weight:bold">${params.data[2]}</div><hr/>投资回报率 (ROI): ${params.data[0]}<br/>净利润: ¥${params.data[1]}w`
},
xAxis: {
name: '投资回报率 (ROI)', nameLocation: 'center', nameGap: 35,
axisLabel: { fontWeight: 'bold' },
splitLine: { lineStyle: { type: 'dashed' } }
},
yAxis: {
name: '税后净利润 (单位: 万元)',
axisLabel: { fontWeight: 'bold' },
splitLine: { lineStyle: { type: 'dashed' } }
},
series: [{
type: 'scatter',
symbolSize: 45,
data: [
[4.21, 12.45, '精品家居店'],
[5.85, 44.16, '运动户外店'],
[3.10, 8.20, '潮流男装店'],
[2.10, -5.40, '海外旗舰店']
],
itemStyle: {
color: (p) => {
if (p.data[0] >= 3.5 && p.data[1] >= 10) return '#10b981';
if (p.data[0] < 3 || p.data[1] < 0) return '#f43f5e';
return '#6366f1';
},
shadowBlur: 15,
shadowColor: 'rgba(0,0,0,0.1)'
},
markLine: {
silent: true,
lineStyle: { type: 'dashed', color: '#94a3b8' },
data: [{ xAxis: 3.5 }, { yAxis: 10 }]
}
}]
});
window.onresize = () => { salesChart.resize(); efficiencyChart.resize(); };
</script>
</body>
</html>