Role.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\logic\RoleLogic;
  4. use app\BaseController;
  5. use think\exception\ValidateException;
  6. use think\facade\Config;
  7. use think\facade\Validate;
  8. //角色
  9. class Role extends BaseController
  10. {
  11. //获取角色列表
  12. public function list()
  13. {
  14. $param = $this->request->only([
  15. 'page'=>1,
  16. 'size'=>10,
  17. 'name'=>'',
  18. 'level'=>'',
  19. 'status'=>''
  20. ],'post');
  21. $val= Validate::rule(array_merge(Config::get('validate_rules.common'),Config::get('validate_rules.roleList')));
  22. if(!$val->check($param)) throw new ValidateException($val->getError());
  23. return RoleLogic::list($param);
  24. }
  25. //获取全部角色
  26. public function all()
  27. {
  28. $keyword = $this->request->post('keyword', '');
  29. return RoleLogic::all($keyword);
  30. }
  31. //添加角色
  32. public function add()
  33. {
  34. $param = $this->request->only(['name','level','remark','action_data'],'post');
  35. $val= Validate::rule(Config::get('validate_rules.RoleAdd'));
  36. if(!$val->check($param)) throw new ValidateException($val->getError());
  37. return RoleLogic::add($param);
  38. }
  39. //获取角色详情
  40. public function read()
  41. {
  42. $id=$this->request->post('id/d',0);
  43. return RoleLogic::read($id);
  44. }
  45. //编辑角色
  46. public function edit()
  47. {
  48. $param = $this->request->only(['id','name','level','remark','action_data'],'post');
  49. $val= Validate::rule(array_merge(Config::get('validate_rules.RoleAdd'),['id'=>'require|number|gt:0']));
  50. if(!$val->check($param)) throw new ValidateException($val->getError());
  51. return RoleLogic::edit($param);
  52. }
  53. //删除角色
  54. public function delete()
  55. {
  56. $id = $this->request->post('id/d', 0);
  57. return RoleLogic::delete($id);
  58. }
  59. //启禁用角色
  60. public function status()
  61. {
  62. $param = $this->request->only(['id', 'status'], 'post');
  63. $val = Validate::rule(Config::get('validate_rules.status'));
  64. if (!$val->check($param)) throw new ValidateException($val->getError());
  65. return RoleLogic::status($param);
  66. }
  67. }