| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 | <?phpnamespace app\model;use think\Model;use think\facade\Db;class SysMenu extends Model{    protected $pk = 'id';    protected $schema = [        "id" => "int",        "pid" => "int",        "name" => "varchar",        "url" => "varchar",        "type" => "tinyint",        "method" => "tinyint",        "icon" => "varchar",        "sort" => "smallint",        "open" => "tinyint",        "index_button" => "tinyint"    ];    public static function getUserMenuList($rid)    {        if ($rid === 1) {   // 超级管理员            $data = self::field('id, pid, name, url, type, icon')->select();        } else {            $roleModel = new SysRole();            $permission_ids = $roleModel->getpermissionIds($rid);            $data = self::where('id', 'IN', $permission_ids)->field('id, pid, name, url, icon')->select();        }        return list_tree($data);    }    public static function queryButtonPermissionsByRoleid($rid)    {        if ($rid === 1) {   // 超级管理员            $data = self::where('type', 2)->column('url');        } else {            $roleModel = new SysRole();            $permission_ids = $roleModel->getpermissionIds($rid);            $data = self::where('id', 'IN', $permission_ids)->where('type', 2)->column('url');        }        return $data;    }    /**     * 面包屑     */    public static function getBreadCrumb($route)    {        $active =  \app\model\SysMenu::where('url', $route)->find();        $active_pid = 0;        $breadCrumb = [];        if ($active) {            $active_pid = $active->pid;            $result = \app\model\SysMenu::find($active_pid);            // 如果还有上级            if ($result) {                $res = \app\model\SysMenu::find($result->pid);                // 如果还有上级                if ($res) {                    $active_pid = $result->pid;                    $breadCrumb[] = [                        'url'   => $res['url'],                        'title' => $res['name'],                    ];                }                $breadCrumb[] = [                    'url'   => $result['url'],                    'title' => $result['name'],                ];            }            $breadCrumb[] = [                'url'   => $active['url'],                'title' => $active['name'],            ];        } else {            $breadCrumb[] = [                'url'   => null,                'title' => '我的桌面',            ];        }        return [            'active_pid' => $active_pid,            'breadCrumb' => $breadCrumb        ];    }    /**     * 后台首页快捷方式     */    public static function getIndexButton()    {        return self::where('index_button', 1)->where('type', 1)->select();    }        public static function getMenuList()    {        return self::where('type', 1)->select();    }}
 |