|
@@ -71,6 +71,26 @@ class Category
|
|
|
}
|
|
|
$result = $list->toArray();
|
|
|
$result['render'] = $list->render();
|
|
|
+
|
|
|
+ // 第一步拿到列表中的id
|
|
|
+ // 第二步in_array 求count
|
|
|
+ // 第三步把count填充到列表页中
|
|
|
+ $pids = array_column($result['data'], 'id');
|
|
|
+ if ($pids) {
|
|
|
+ $idCountResult = $this->model->getChildCountInPids(['pid' => $pids]);
|
|
|
+ $idCountResult = $idCountResult->toArray();
|
|
|
+
|
|
|
+ $idCounts = [];
|
|
|
+ foreach ($idCountResult as $countResult) {
|
|
|
+ $idCounts[$countResult['pid']] = $countResult['count'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($result['data']) {
|
|
|
+ foreach ($result['data'] as $k => $value) {
|
|
|
+ $result['data'][$k]['childCount'] = $idCounts[$value['id']] ?? 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return $result;
|
|
|
}
|
|
|
|