任务时间: 2025年06月22日 22:03 - 22:45 任务类型: 功能开发 模块: Farm(农场模块)
在农场统计图表页面中增加各个等级土地的产出果实种类统计功能,为每个土地等级创建独立的统计卡片,显示该土地类型产出的不同果实种类及其出现次数。使用FarmCrop模型进行统计,并包含软删除数据以提供完整的数据分析。
BaseLandFruitStatsCard - 抽象基类,提供通用的果实种类统计功能UCore\DcatAdmin\Metrics\Examples\NumberS2(单行多数字卡片)NormalLandFruitStatsCard (土地类型ID: 1)RedLandFruitStatsCard (土地类型ID: 2)BlackLandFruitStatsCard (土地类型ID: 3)GoldLandFruitStatsCard (土地类型ID: 4)kku_farm_crop_logs(作物事件日志表)harvested(收获事件)event_data.item_id)统计收获次数kku_item_items(物品表,获取果实名称)// 从作物表中统计指定土地等级的产出果实,按果实种类分组
// 使用withTrashed()包含软删除的数据
$cropStats = FarmCrop::withTrashed()
->where('land_level', $this->landType)
->whereNotNull('final_output_item_id')
->select('final_output_item_id', DB::raw('COUNT(*) as crop_count'))
->groupBy('final_output_item_id')
->get();
app/Module/Farm/AdminControllers/FarmMetricsController.php通过SQL查询验证统计数据准确性:
SELECT
land_type,
JSON_EXTRACT(event_data, '$.item_id') as item_id,
COUNT(*) as harvest_count
FROM kku_farm_crop_logs
WHERE event_type = 'harvested'
GROUP BY land_type, JSON_EXTRACT(event_data, '$.item_id')
ORDER BY land_type, harvest_count DESC;
验证结果(包含软删除数据):
第一次提交: 6c7ec653 - 初始实现(总产量统计)
第二次提交: 102686c8 - 重构为果实种类统计
第三次提交: 48654990 - 改用FarmCrop模型进行统计
第四次提交: bac5724b - 包含软删除数据的完整统计分析
最终Message: 农场统计图表:包含软删除数据的完整统计分析
app/Module/Farm/AdminControllers/Metrics/BaseLandFruitStatsCard.php - 抽象基类app/Module/Farm/AdminControllers/Metrics/NormalLandFruitStatsCard.php - 普通土地统计app/Module/Farm/AdminControllers/Metrics/RedLandFruitStatsCard.php - 红土地统计app/Module/Farm/AdminControllers/Metrics/BlackLandFruitStatsCard.php - 黑土地统计app/Module/Farm/AdminControllers/Metrics/GoldLandFruitStatsCard.php - 金土地统计app/Module/Farm/AdminControllers/FarmMetricsController.php - 主控制器app/Module/Farm/AdminControllers/Metrics/FarmLandOutputStatsCard.php - 原总产量统计卡片app/Module/Farm/Models/FarmCropLog.php - 作物日志模型app/Module/GameItems/Models/Item.php - 物品模型