update
This commit is contained in:
parent
5ddeda8912
commit
b3fb80f05b
@ -102,6 +102,10 @@ class MaterialClassifyLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function detail($params): array
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -322,6 +322,21 @@ function buildTree($items, $parentField, $parentId = 0): array
|
|||||||
return $tree;
|
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
|
function data_unique_code($str): string
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user