Role.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\sys;
  12. use app\dict\sys\RoleStatusDict;
  13. use app\service\admin\sys\RoleService;
  14. use core\base\BaseAdminController;
  15. use think\db\exception\DbException;
  16. use think\Response;
  17. class Role extends BaseAdminController
  18. {
  19. public function lists()
  20. {
  21. $data = $this->request->params([
  22. ['role_name', ''],
  23. ]);
  24. $list = (new RoleService())->getPage($data);
  25. return success($list);
  26. }
  27. /**
  28. * 用户组详情
  29. * @param $role_id
  30. * @return Response
  31. */
  32. public function info($role_id)
  33. {
  34. return success((new RoleService())->getInfo($role_id));
  35. }
  36. /**
  37. * 获取全部权限
  38. * @return Response
  39. */
  40. public function all()
  41. {
  42. return success((new RoleService())->getAll());
  43. }
  44. /**
  45. * 新增用户组
  46. * @return Response
  47. */
  48. public function add()
  49. {
  50. $data = $this->request->params([
  51. ['role_name', ''],
  52. ['rules', []],
  53. ['status', RoleStatusDict::ON],
  54. ]);
  55. $this->validate($data, 'app\validate\sys\Role.add');
  56. (new RoleService())->add($data);
  57. return success('ADD_SUCCESS');
  58. }
  59. /**
  60. * 更新用户组
  61. */
  62. public function edit($role_id)
  63. {
  64. $data = $this->request->params([
  65. ['role_name', ''],
  66. ['rules', []],
  67. ['status', RoleStatusDict::ON],
  68. ]);
  69. $this->validate($data, 'app\validate\sys\Role.edit');
  70. (new RoleService())->edit($role_id, $data);
  71. return success('EDIT_SUCCESS');
  72. }
  73. /**
  74. * 删除单个用户组
  75. * @param $role_id
  76. * @return Response
  77. * @throws DbException
  78. */
  79. public function del($role_id)
  80. {
  81. (new RoleService())->del($role_id);
  82. return success('DELETE_SUCCESS');
  83. }
  84. }