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