master
cody 4 months ago
parent 1e9c6b8fa6
commit f405290aaf

@ -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 [

Loading…
Cancel
Save