feat: 新增产品分类增/删/改/查接口

This commit is contained in:
2025-02-11 16:30:58 +08:00
parent 1b220392d4
commit c0b2c5c89d
5 changed files with 308 additions and 1 deletions

View File

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