drag-create-api/app/admin/logic/Code/CodeModuleCategory.php

73 lines
3.0 KiB
PHP

<?php
namespace app\admin\logic\Code;
use app\common\model\Code\CodeModuleCategory as ModelCodeModuleCategory;
use app\common\exception\Tool;
use app\common\arw\adjfut\src\Traverse;
class CodeModuleCategory
{
/**
* 构建代码块类目树形结构数据
*
* @param array $module_category_guids 主类目guid数组
* @return array
* @date 2023-07-05
* @author xjh
* @since 1.0.0
*/
public static function buildTreeData(array $module_category_guids): array
{
if (!$module_category_guids) {
return [];
}
$tree_data = [];
$data = ModelCodeModuleCategory::alias('cmc')
->whereOr([
['cmc.code_module_category_guid', 'in', $module_category_guids],
['cmc.code_module_category_parent_guid', 'in', $module_category_guids],
])->field([
'cmc.code_module_category_id',
'cmc.code_module_category_guid',
'cmc.customer_guid',
'cmc.code_module_category_audit',
'cmc.code_module_category_sort',
'cmc.code_module_category_parent_guid',
'cmc.code_module_category_name',
'cmc.code_module_category_audit',
'cmc.code_module_category_global_mode',
'cmc.code_module_category_library_type',
'cmc.code_module_category_ps',
'cmcp.code_module_category_name' => "code_module_category_parent_name",
'cust.customer_name',
])
->leftjoin('code_module_category cmcp', 'cmc.code_module_category_parent_guid = cmcp.code_module_category_guid')
->leftjoin('customer cust', 'cmc.customer_guid = cust.customer_guid')
->order('code_module_category_sort')
->select()
->toArray();
$Traverse = new Traverse('code_module_category_guid', 'code_module_category_parent_guid');
$tree_data = $Traverse->tree($data, ModelCodeModuleCategory::MASTER_DEFAULT, function ($v) {
return [
'code_module_category_name' => $v['code_module_category_name'],
'code_module_category_parent_name' => $v['code_module_category_parent_name'],
'code_module_category_guid' => $v['code_module_category_guid'],
'code_module_category_parent_guid' => $v['code_module_category_parent_guid'],
'code_module_category_sort' => $v['code_module_category_sort'],
'code_module_category_ps' => $v['code_module_category_ps'],
'code_module_category_global_mode' => $v['code_module_category_global_mode'],
'code_module_category_audit' => $v['code_module_category_audit'],
'code_module_category_library_type' => $v['code_module_category_library_type'],
'customer_guid' => $v['customer_guid'],
'customer_name' => $v['customer_name'],
];
});
return $tree_data;
}
}