Role.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018-2020 rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | [ 权限管理 ]
  8. // +----------------------------------------------------------------------
  9. // | Date: 2020-08-31 20:43
  10. // +----------------------------------------------------------------------
  11. namespace app\system\controller;
  12. use app\BaseController;
  13. use app\model\system\AdminRole;
  14. use app\model\system\RolePath;
  15. use app\Request;
  16. use library\services\UtilService;
  17. class Role extends BaseController
  18. {
  19. /**
  20. * 列表数据
  21. * @return mixed
  22. */
  23. public function list()
  24. {
  25. $listAr = (new AdminRole)->getRoleData();
  26. $result = [];
  27. foreach ($listAr as $v) {
  28. $d = [];
  29. $d['name'] = $v['name'];
  30. $d['status'] = $v['status'];
  31. $d['is_system'] = $v['is_system'];
  32. $d['id'] = $v['id'];
  33. $result[] = $d;
  34. }
  35. return app('json')->success($result);
  36. }
  37. /**
  38. * 保存角色数据
  39. * @param Request $request
  40. * @return mixed
  41. */
  42. public function save(Request $request)
  43. {
  44. $post = UtilService::getMore([
  45. ['id', '0'],
  46. ['name', '', 'empty', '请输入角色名'],
  47. ['status', 0],
  48. ], $request);
  49. $bool = (new AdminRole)->saveRole($post);
  50. return $bool ? app('json')->success("操作成功", []) : app('json')->fail(AdminRole::getErrorInfo());
  51. }
  52. /**
  53. * 删除数据
  54. * @param Request $request
  55. * @return mixed
  56. */
  57. public function del(Request $request)
  58. {
  59. [$id] = UtilService::getMore(
  60. [
  61. ['id', '0'],
  62. ],
  63. $request, true
  64. );
  65. if(in_array(strval($id),["1","53","54","55"])){
  66. return app("json")->fail("当前角色不能删除");
  67. }
  68. AdminRole::del($id);
  69. return app('json')->success("删除成功", []);
  70. }
  71. /**
  72. * 配置管理
  73. * @return mixed
  74. * @throws \think\db\exception\DataNotFoundException
  75. * @throws \think\db\exception\DbException
  76. * @throws \think\db\exception\ModelNotFoundException
  77. */
  78. public function setingList()
  79. {
  80. $post = UtilService::getMore([
  81. ['id', '0'],
  82. ]);
  83. $rolePath = new RolePath;
  84. $rolePath->getAll();
  85. $listAr = $rolePath->getRoleData();
  86. $rData = AdminRole::where('id', $post['id'])->find();
  87. $rAr = [];
  88. $rAr['data'] = $listAr;
  89. $rAr['seting'] = empty($rData) ? [] : json_decode($rData['module'], true);
  90. return app('json')->success($rAr);
  91. }
  92. /**
  93. * 保存配置
  94. * @param Request $request
  95. * @return mixed
  96. */
  97. public function setingSave(Request $request)
  98. {
  99. $post = UtilService::getMore([
  100. ['id', '0'],
  101. ['data', '', 'empty', '请输入参数'],
  102. ]);
  103. $iAr = [];
  104. foreach ($post['data'] as $k => $v) {
  105. if (!empty($v)) $iAr[$k] = true;
  106. }
  107. AdminRole::where('id', $post['id'])->save(['module' => json_encode($iAr)]);
  108. return app('json')->success("保存数据成功", []);
  109. }
  110. }