|
|
@@ -154,20 +154,27 @@ class AuxiliaryAccountService extends Service
|
|
|
|
|
|
// 2. 预处理映射表:让所有子 ID 直接指向它的最顶层“祖宗” ID
|
|
|
$childToRoot = [];
|
|
|
+ $grouped = [];
|
|
|
foreach ($fee_type_list as $type) {
|
|
|
$current = $type;
|
|
|
// 向上追溯直到 parent_id 为 0,即找到一级分类
|
|
|
- while ($current['parent_id'] != 0 && isset($idMap[$current['parent_id']])) {
|
|
|
+ while ($current['parent_id'] != 0) {
|
|
|
$current = $idMap[$current['parent_id']];
|
|
|
}
|
|
|
$childToRoot[$type['id']] = [
|
|
|
'id' => $current['id'],
|
|
|
'title' => $current['title']
|
|
|
];
|
|
|
+ if (!isset($grouped[$current['id']])) {
|
|
|
+ $grouped[$current['id']] = [
|
|
|
+ 'first_level_id' => $current['id'],
|
|
|
+ 'first_level_title' => $current['title'],
|
|
|
+ 'details' => []
|
|
|
+ ];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 3. 遍历明细数据进行分组
|
|
|
- $grouped = [];
|
|
|
foreach ($list as $item) {
|
|
|
$feeId = $item['fee_id'];
|
|
|
// 获取该费用对应的一级分类信息
|
|
|
@@ -184,7 +191,6 @@ class AuxiliaryAccountService extends Service
|
|
|
|
|
|
$grouped[$rootId]['details'][] = $item;
|
|
|
}
|
|
|
-
|
|
|
// 4. 重置数组索引并返回
|
|
|
return array_values($grouped);
|
|
|
}
|