diff --git a/app/adminapi/logic/material/MaterialClassifyLogic.php b/app/adminapi/logic/material/MaterialClassifyLogic.php index 13f61fd89..9d10bedd4 100644 --- a/app/adminapi/logic/material/MaterialClassifyLogic.php +++ b/app/adminapi/logic/material/MaterialClassifyLogic.php @@ -102,6 +102,10 @@ class MaterialClassifyLogic extends BaseLogic */ public static function detail($params): array { - return MaterialClassify::field('id,pid,name,create_time')->findOrEmpty($params['id'])->toArray(); + $lists = MaterialClassify::field('id,pid,name')->select()->toArray(); + $ids = getAncestors($params['id'],$lists); + $data = MaterialClassify::field('id,pid,name,create_time')->findOrEmpty($params['id'])->toArray(); + $data['all_pid'] = $ids; + return $data; } } \ No newline at end of file diff --git a/app/common.php b/app/common.php index 0202c678e..163544c69 100755 --- a/app/common.php +++ b/app/common.php @@ -322,6 +322,21 @@ function buildTree($items, $parentField, $parentId = 0): array return $tree; } +function getAncestors($categoryId, $categoryTable): array +{ + $parentIds = []; + foreach ($categoryTable as $item) { + if ($item['id'] == $categoryId && $item['pid'] != 0) { + $parentIds[] = $item['pid']; + // 递归调用自身,将父类ID作为参数传入 + $newParentIds = getAncestors($item['pid'],$categoryTable); + $parentIds = array_merge($parentIds, $newParentIds); + } + } + + return $parentIds ; +} + //数据唯一编码 function data_unique_code($str): string {