From f405290aaf9e32a9f3c80680eeced43340381a5f Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Thu, 18 Dec 2025 16:15:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/StatisticsController.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/Admin/StatisticsController.php b/app/Http/Controllers/Admin/StatisticsController.php index 52add5f..8fd33dd 100755 --- a/app/Http/Controllers/Admin/StatisticsController.php +++ b/app/Http/Controllers/Admin/StatisticsController.php @@ -491,20 +491,21 @@ class StatisticsController extends CommonController ->get(); // 3. 按「真实价格」去重生成表头列(xx元/天),并取一条样本数据上的因子名称作为小字说明 + // 使用 groupBy('total'),避免闭包分组可能导致的 array_key_exists 问题 $columns = $orderItems - ->groupBy(function ($item) { - return (float) $item->total; // 以真实 total 作为价格分组键 - }) - ->map(function ($group) { + ->groupBy('total') + ->map(function ($group, $total) { /** @var OrderItems $sample */ $sample = $group->first(); - $price = (float) $sample->total; + $price = (float) $total; $factor_item_name = ''; - $factors = json_decode($sample->factors, true) ?: []; - if (!empty($factors)) { - // 取第一条因子作为说明文本(前端展示不变:价格 + 小字) - $factor_item_name = $factors[0]['factor_item_name'] ?? ''; + if ($sample && $sample->factors) { + $factors = json_decode($sample->factors, true) ?: []; + if (!empty($factors)) { + // 取第一条因子作为说明文本(前端展示不变:价格 + 小字) + $factor_item_name = $factors[0]['factor_item_name'] ?? ''; + } } return [