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/SystemService.php
<?php


namespace Modules\System\Service;


use App\Service\MyService;
use Expand\Addon\Addon;
use Modules\System\Models\Attr;
use Modules\System\Models\DiyPage;
use Modules\System\Models\Menu;
use Modules\System\Models\Region;
use Modules\System\Models\Role;

class SystemService extends MyService
{

    /**
     * 获取地区列表
     * @param $pid
     * @return mixed
     */
    public function regions($pid = 0)
    {
        return Region::where('pid', $pid)->get();
    }

    /**
     * 插件添加到菜单
     * @param $name
     * @param $homePath
     * @return bool
     */
    public function addonToMenu($name, $homePath): bool
    {

        $addonMenu = Menu::where('title', '系统插件')->first();

        if (!$addonMenu) {

            $addonMenu = new Menu();

            $addonMenu->store([
                'pid' => 0,
                'title' => '系统插件',
                'url' => '',
                'icon' => 'fa fa-bars',
                'target' => '_self',
                'sort' => '0',
            ]);
        }

        $data = [
            'pid' => $addonMenu->id,
            'title' => $name,
            'url' => $homePath,
            'icon' => 'fa fa-bars',
            'target' => '_self',
            'sort' => '0',
        ];

        return (new Menu())->store($data);
    }

    /**
     * 删除插件菜单
     * @param $homePath
     * @return mixed
     */
    public function addonRemoveForMenu($homePath)
    {
        return Menu::where([
            ['url', '=', $homePath],
        ])->delete();
    }

    /**
     * 获取系统辅助属性
     * @param string $type
     * @return array
     */
    public function attributes(string $type = ''): array
    {
        if ($type) {

            return Attr::where('type', $type)->get()->toArray();
        }

        return Attr::get()->toArray();
    }

    /**
     * 获取系统是否安装某个插件
     * @param $ident
     * @return bool
     */
    public function addonEnabled($ident): bool
    {
        $addon = new Addon(app(), $ident);
        return $addon->isEnabled();
    }

    /**
     * 通过地址获取单个页面
     * @param $path
     * @return mixed
     */
    public function diyPage($path)
    {
        return DiyPage::where('page_path', $path)->where('lang', current_lang())->first();
    }

    /**
     * 获取所有页面
     * @return mixed
     */
    public function diyPages()
    {
        return DiyPage::where('lang', current_lang())->get();
    }


    /**
     * @param $id
     * @return array|mixed
     */
    public function getRoleNodes($id)
    {
        $role = Role::find($id);

        return $role ? json_decode($role->role_node, true) : [];
    }
}