12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace app\model;
- use think\Model;
- use think\facade\Db;
- class SysMenu extends Model
- {
- 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();
- }
- }
|