SystemMenus.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\store\system;
  12. use app\controller\store\AuthController;
  13. use app\services\system\SystemMenusServices;
  14. use app\services\system\SystemRoleServices;
  15. use crmeb\services\CacheService;
  16. use think\facade\App;
  17. /**
  18. * 菜单权限
  19. * Class SystemMenus
  20. * @package app\controller\store\system
  21. */
  22. class SystemMenus extends AuthController
  23. {
  24. /**
  25. * SystemMenus constructor.
  26. * @param App $app
  27. * @param SystemMenusServices $services
  28. */
  29. public function __construct(App $app, SystemMenusServices $services)
  30. {
  31. parent::__construct($app);
  32. $this->services = $services;
  33. $this->request->filter(['addslashes', 'trim']);
  34. }
  35. /**
  36. * 菜单展示列表
  37. * @return mixed
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\DbException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. */
  42. public function index()
  43. {
  44. $where = $this->request->getMore([
  45. ['is_show', ''],
  46. ['keyword', ''],
  47. ]);
  48. $where['type'] = 2;
  49. return app('json')->success($this->services->getList($where));
  50. }
  51. /**
  52. * 菜单展示列表
  53. * @return mixed
  54. * @throws \think\db\exception\DataNotFoundException
  55. * @throws \think\db\exception\DbException
  56. * @throws \think\db\exception\ModelNotFoundException
  57. */
  58. public function cashierMenusList()
  59. {
  60. $where = $this->request->getMore([
  61. ['is_show', ''],
  62. ['keyword', ''],
  63. ]);
  64. $where['type'] = 3;
  65. return app('json')->success($this->services->getList($where));
  66. }
  67. /**
  68. * 获取子权限
  69. * @param $id
  70. * @return mixed
  71. * @throws \think\db\exception\DataNotFoundException
  72. * @throws \think\db\exception\DbException
  73. * @throws \think\db\exception\ModelNotFoundException
  74. */
  75. public function sonMenusList($role_id = 0, $id = 0)
  76. {
  77. if (!$id) {
  78. app('json')->fail('请选择上级菜单');
  79. }
  80. $rules = [];
  81. if ($role_id) {
  82. /** @var SystemRoleServices $systemRoleServices */
  83. $systemRoleServices = app()->make(SystemRoleServices::class);
  84. $role = $systemRoleServices->get((int)$role_id);
  85. $rules = $role && $role['rules'] ? explode(',', $role['rules']) : [];
  86. }
  87. $where['type'] = 2;
  88. $where['auth_type'] = 2;
  89. $where['pid'] = $id;
  90. $menus = $this->services->getList($where);
  91. $checked_rules = [];
  92. foreach ($menus as $item) {
  93. if ($rules && in_array($item['id'] ?? 0, $rules)) {
  94. $checked_rules [] = $item['id'];
  95. }
  96. }
  97. return app('json')->success(compact('menus', 'checked_rules'));
  98. }
  99. }