feat: 新增产品分类增/删/改/查接口
This commit is contained in:
@@ -1,2 +1,28 @@
|
||||
<?php
|
||||
// 这是系统自动生成的公共文件
|
||||
|
||||
if (!function_exists('array_to_tree')) {
|
||||
/**
|
||||
* 数组转换为树状结构
|
||||
* @param array $data 数据
|
||||
* @param int $pid 父级ID
|
||||
* @param string $with 转换依据字段
|
||||
* @param int $level 层级
|
||||
* @return array
|
||||
*/
|
||||
function array_to_tree(array $data, int $pid, string $with = 'pid', int $level = 1)
|
||||
{
|
||||
$ret = [];
|
||||
foreach ($data as $item) {
|
||||
if ($item[$with] == $pid) {
|
||||
$item['level'] = $level;
|
||||
$children = array_to_tree($data, $item['id'], $with, $level + 1);
|
||||
if ($children) {
|
||||
$item['children'] = $children;
|
||||
}
|
||||
$ret[] = $item;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user