Role.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 Add()
  27. {
  28. $param = $this->request->only(['name','level','remark','action_data'],'post');
  29. $val= Validate::rule(Config::get('validate_rules.RoleAdd'));
  30. if(!$val->check($param)) throw new ValidateException($val->getError());
  31. return RoleLogic::Add($param);
  32. }
  33. //获取角色详情
  34. public function Read()
  35. {
  36. $id=$this->request->post('id/d',0);
  37. return RoleLogic::Read($id);
  38. }
  39. //编辑角色
  40. public function Edit()
  41. {
  42. $param = $this->request->only(['id','name','level','remark','action_data'],'post');
  43. $val= Validate::rule(array_merge(Config::get('validate_rules.RoleAdd'),['id'=>'require|number|gt:0']));
  44. if(!$val->check($param)) throw new ValidateException($val->getError());
  45. return RoleLogic::Edit($param);
  46. }
  47. //删除角色
  48. public function Delete()
  49. {
  50. $id = $this->request->post('id/d', 0);
  51. return RoleLogic::Delete($id);
  52. }
  53. //启禁用角色
  54. public function Status()
  55. {
  56. $param = $this->request->only(['id', 'status'], 'post');
  57. $val = Validate::rule(Config::get('validate_rules.status'));
  58. if (!$val->check($param)) throw new ValidateException($val->getError());
  59. return RoleLogic::Status($param);
  60. }
  61. }