Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

SystemMenus.php 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\controller\store\system;
  3. use app\controller\store\AuthController;
  4. use app\services\system\SystemMenusServices;
  5. use app\services\system\SystemRoleServices;
  6. use think\facade\App;
  7. /**
  8. * 菜单权限
  9. * Class SystemMenus
  10. * @package app\controller\store\system
  11. */
  12. class SystemMenus extends AuthController
  13. {
  14. /**
  15. * SystemMenus constructor.
  16. * @param App $app
  17. * @param SystemMenusServices $services
  18. */
  19. public function __construct(App $app, SystemMenusServices $services)
  20. {
  21. parent::__construct($app);
  22. $this->services = $services;
  23. $this->request->filter(['addslashes', 'trim']);
  24. }
  25. /**
  26. * 菜单展示列表
  27. * @return mixed
  28. * @throws \think\db\exception\DataNotFoundException
  29. * @throws \think\db\exception\DbException
  30. * @throws \think\db\exception\ModelNotFoundException
  31. */
  32. public function index()
  33. {
  34. $where = $this->request->getMore([
  35. ['is_show', ''],
  36. ['keyword', ''],
  37. ]);
  38. $where['type'] = 2;
  39. // $where['auth_type'] = 1;
  40. return app('json')->success($this->services->getList($where));
  41. }
  42. /**
  43. * 获取子权限
  44. * @param $id
  45. * @return mixed
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\DbException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. */
  50. public function sonMenusList($role_id = 0, $id = 0)
  51. {
  52. if (!$id) {
  53. app('json')->fail('请选择上级菜单');
  54. }
  55. $rules = [];
  56. if ($role_id) {
  57. /** @var SystemRoleServices $systemRoleServices */
  58. $systemRoleServices = app()->make(SystemRoleServices::class);
  59. $role = $systemRoleServices->get((int)$role_id);
  60. $rules = $role && $role['rules'] ? explode(',', $role['rules']) : [];
  61. }
  62. $where['type'] = 2;
  63. $where['auth_type'] = 2;
  64. $where['pid'] = $id;
  65. $menus = $this->services->getList($where);
  66. $checked_rules = [];
  67. foreach ($menus as $item) {
  68. if ($rules && in_array($item['id'] ?? 0, $rules)) {
  69. $checked_rules [] = $item['id'];
  70. }
  71. }
  72. return app('json')->success(compact('menus', 'checked_rules'));
  73. }
  74. }