This commit is contained in:
weiz 2024-01-05 16:02:47 +08:00
parent 5ddeda8912
commit b3fb80f05b
2 changed files with 20 additions and 1 deletions

View File

@ -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;
}
}

View File

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