Role.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace app\admin\controller\role;
  3. use app\admin\controller\BaseController;
  4. use app\admin\server\role\RoleServer;
  5. class Role extends BaseController
  6. {
  7. /**
  8. * Notes:获取角色列表
  9. * @return \support\Response
  10. * User: ZQ
  11. * Date: 2022/9/13
  12. */
  13. public function getRoleList()
  14. {
  15. [$page, $limit] = $this->getPage();
  16. $keywords = $this->request->get('keywords');
  17. $result = RoleServer::getRoleList($page, $limit, $keywords);
  18. return json_success($result, '成功');
  19. }
  20. /**
  21. * Notes:获取所有角色
  22. * @return \support\Response
  23. * User: ZQ
  24. * Date: 2022/9/19
  25. */
  26. public function getRoleAll()
  27. {
  28. $result = RoleServer::getRoleAll();
  29. return json_success($result, '成功');
  30. }
  31. /**
  32. * Notes:修改角色
  33. * @return \support\Response
  34. * User: ZQ
  35. * Date: 2022/9/13
  36. */
  37. public function updateRole()
  38. {
  39. $role_id = $this->request->post('role_id');
  40. $role_name = $this->request->post('role_name','');
  41. $role_rules = $this->request->post('role_rules','');
  42. $role_info = $this->request->post('role_info','');
  43. $role_is_show = $this->request->post('role_is_show');
  44. $this->validateCheck('role\RoleValidate', ['role_id' => $role_id, 'role_name' => $role_name, 'role_rules' => $role_rules], 'update');
  45. $result = RoleServer::updateRole($role_id, $role_name, $role_rules, $role_info, $role_is_show);
  46. return json_success($result, '修改成功');
  47. }
  48. /**
  49. * Notes:删除角色
  50. * @return \support\Response
  51. * User: ZQ
  52. * Date: 2022/9/13
  53. */
  54. public function delRole()
  55. {
  56. $role_id = $this->request->get('role_id');
  57. $this->validateCheck('role\RoleValidate', ['role_id' => $role_id], 'info');
  58. $result = RoleServer::delRole($role_id);
  59. if ($result){
  60. return json_success($result, '删除成功');
  61. }else{
  62. throw new \Exception('删除失败!');
  63. }
  64. }
  65. /**
  66. * Notes:添加角色
  67. * @return \support\Response
  68. * User: ZQ
  69. * Date: 2022/9/13
  70. */
  71. public function addRole()
  72. {
  73. $role_name = $this->request->post('role_name');
  74. $role_rules = $this->request->post('role_rules','');
  75. $role_info = $this->request->post('role_info','');
  76. $role_is_show = $this->request->post('role_is_show');
  77. $this->validateCheck('role\RoleValidate', ['role_name' => $role_name, 'role_rules' => $role_rules, 'role_is_show' => $role_is_show], 'create');
  78. $result = RoleServer::insertRole($role_name, $role_rules, $role_info, $role_is_show);
  79. return json_success($result, '添加成功');
  80. }
  81. /**
  82. * Notes:查询角色详情
  83. * @return \support\Response
  84. * User: ZQ
  85. * Date: 2022/9/13
  86. */
  87. public function roleInfo()
  88. {
  89. $role_id = $this->request->get('role_id');
  90. $this->validateCheck('role\RoleValidate', ['role_id' => $role_id], 'info');
  91. $result = RoleServer::roleInfo($role_id);
  92. return json_success($result, '成功');
  93. }
  94. /**
  95. * Notes:角色启用禁用
  96. * @return \support\Response
  97. * User: ZQ
  98. * Date: 2022/9/13
  99. */
  100. public function updateStatus()
  101. {
  102. $role_id = $this->request->get('role_id');
  103. $role_is_show = $this->request->get('role_is_show');
  104. $this->validateCheck('role\RoleValidate', ['role_id' => $role_id], 'info');
  105. $result = RoleServer::updateStatus($role_id, $role_is_show);
  106. return json_success($result, '修改成功');
  107. }
  108. }