HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot//my.esfyn.top/Modules/System/Service/MenuService.php
<?php


namespace Modules\System\Service;


use Modules\System\Models\Menu;

class MenuService
{

    public function menuTree($menus = [], $pid = 0, $prefix = '')
    {
        $menus = $menus ?: Menu::toTree();

        if (isset($menus[$pid]) && is_array($menus[$pid])) {

            collect($menus[$pid])->each(function ($item) use (&$result, $menus, $prefix) {
                $result[] = ['id' => $item['id'], 'title' => $prefix . $item['title']];
                $child = $this->menuTree($menus, $item['id'], "{$prefix}__");
                if (is_array($child)) {
                    $result = array_merge($result, $child);
                }
            });

            return $result;
        }

    }

    /**
     * 获取管理员菜单
     * @return mixed
     */
    public function leftMenu()
    {
        $roleId = system_admin_role_id();
        if ($roleId !== 1) {
            $roleNodes = app('system')->getRoleNodes(system_admin_role_id());
            foreach ($roleNodes as &$node) {
                $node = "/". ltrim($node, "/");
            }
            //兼容以往版本
            $roleNodes[] = '/user/admin/';
            $menus = Menu::where('status', 1)->whereIn('url', $roleNodes ?: ['-'])
                ->orWhere('url', '')
                ->orderBy('sort', 'asc')->get();
        } else {
            $menus = Menu::where('status', 1)->orderBy('sort', 'asc')->get();
        }

        collect($menus)->each(function ($item) use (&$result) {
            $result[$item['pid']][] = $item;
        });

        return $result;
    }


}