RoleController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\controller\auth;
  15. use app\adminapi\{
  16. logic\auth\RoleLogic,
  17. lists\auth\RoleLists,
  18. validate\auth\RoleValidate,
  19. controller\BaseAdminController
  20. };
  21. /**
  22. * 角色控制器
  23. * Class RoleController
  24. * @package app\adminapi\controller\auth
  25. */
  26. class RoleController extends BaseAdminController
  27. {
  28. /**
  29. * @notes 查看角色列表
  30. * @return \think\response\Json
  31. * @author 段誉
  32. * @date 2021/12/29 11:49
  33. */
  34. public function lists()
  35. {
  36. return $this->dataLists(new RoleLists());
  37. }
  38. /**
  39. * @notes 添加权限
  40. * @return \think\response\Json
  41. * @author 段誉
  42. * @date 2021/12/29 11:49
  43. */
  44. public function add()
  45. {
  46. $params = (new RoleValidate())->post()->goCheck('add');
  47. $res = RoleLogic::add($params);
  48. if (true === $res) {
  49. return $this->success('添加成功', [], 1, 1);
  50. }
  51. return $this->fail(RoleLogic::getError());
  52. }
  53. /**
  54. * @notes 编辑角色
  55. * @return \think\response\Json
  56. * @author 段誉
  57. * @date 2021/12/29 14:18
  58. */
  59. public function edit()
  60. {
  61. $params = (new RoleValidate())->post()->goCheck('edit');
  62. $res = RoleLogic::edit($params);
  63. if (true === $res) {
  64. return $this->success('编辑成功', [], 1, 1);
  65. }
  66. return $this->fail(RoleLogic::getError());
  67. }
  68. /**
  69. * @notes 删除角色
  70. * @return \think\response\Json
  71. * @author 段誉
  72. * @date 2021/12/29 14:18
  73. */
  74. public function delete()
  75. {
  76. $params = (new RoleValidate())->post()->goCheck('del');
  77. RoleLogic::delete($params['id']);
  78. return $this->success('删除成功', [], 1, 1);
  79. }
  80. /**
  81. * @notes 查看角色详情
  82. * @return \think\response\Json
  83. * @throws \think\db\exception\DataNotFoundException
  84. * @throws \think\db\exception\DbException
  85. * @throws \think\db\exception\ModelNotFoundException
  86. * @author 段誉
  87. * @date 2021/12/29 14:18
  88. */
  89. public function detail()
  90. {
  91. $params = (new RoleValidate())->goCheck('detail');
  92. $detail = RoleLogic::detail($params['id']);
  93. return $this->data($detail);
  94. }
  95. /**
  96. * @notes 获取角色数据
  97. * @return \think\response\Json
  98. * @throws \think\db\exception\DataNotFoundException
  99. * @throws \think\db\exception\DbException
  100. * @throws \think\db\exception\ModelNotFoundException
  101. * @author 段誉
  102. * @date 2022/10/13 10:39
  103. */
  104. public function all()
  105. {
  106. $result = RoleLogic::getAllData();
  107. return $this->data($result);
  108. }
  109. }