Action.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use app\admin\logic\ActionLogic;
  5. use app\model\ActionModel;
  6. use app\model\AdminMenuModel;
  7. use app\model\CommonModel;
  8. use think\exception\ValidateException;
  9. use think\facade\Config;
  10. use think\facade\Validate;
  11. //功能权限
  12. class Action extends BaseController
  13. {
  14. //获取权限列表
  15. public function list()
  16. {
  17. $menuid = $this->request->post('menuid', 0);
  18. return ActionLogic::list($menuid);
  19. }
  20. //添加权限
  21. public function add()
  22. {
  23. $param = $this->request->only(['menuid', 'action_code', 'status' => CommonModel::$status_normal], 'post');
  24. $val = Validate::rule(Config::get('validate_rules.actionAdd'));
  25. if (!$val->check($param)) throw new ValidateException($val->getError());
  26. return ActionLogic::add($param);
  27. }
  28. // //获取权限详情
  29. // public function Read()
  30. // {
  31. // $id = $this->request->post('id/d', 0);
  32. //
  33. // return ActionLogic::read($id);
  34. // }
  35. //编辑权限
  36. public function edit()
  37. {
  38. $param = $this->request->only(['id', 'action_code'], 'post');
  39. $val = Validate::rule([
  40. 'id' => 'require|number|gt:0',
  41. 'action_code|按钮编码' => 'require',
  42. ]);
  43. if (!$val->check($param)) throw new ValidateException($val->getError());
  44. return ActionLogic::edit($param);
  45. }
  46. //删除权限
  47. public function delete()
  48. {
  49. $id = $this->request->post('id/d', 0);
  50. return ActionLogic::delete($id);
  51. }
  52. //启禁用权限
  53. public function status()
  54. {
  55. $param = $this->request->only(['id', 'status'], 'post');
  56. $val = Validate::rule(Config::get('validate_rules.status'));
  57. if (!$val->check($param)) throw new ValidateException($val->getError());
  58. return ActionLogic::status($param);
  59. }
  60. //获取所有菜单下的所有按钮
  61. public function index()
  62. {
  63. $list = AdminMenuModel::field('id,menu_name,menu_type,menu_img,menu_route,menu_url,status,weight,addtime,is_private private')
  64. ->where(['pid' => 0, 'is_show' => AdminMenuModel::$show])
  65. ->append(['child'])
  66. ->withAttr('child', function ($val, $data) {
  67. return AdminMenuModel::field('id,menu_name,menu_type,menu_img,menu_route,menu_url,status,weight,addtime,is_private private,pid')
  68. ->where(['pid' => $data['id'], 'is_show' => AdminMenuModel::$show])
  69. ->append(['action'])
  70. ->withAttr('action', function ($v, $d) {
  71. return ActionModel::alias('a')
  72. ->leftJoin('action_list l', 'a.action_code=l.action_code')
  73. ->field('a.*,action_name')
  74. ->where(['a.menuid' => $d['id'], 'a.status' => CommonModel::$status_normal])
  75. ->select()
  76. ->toArray();
  77. })
  78. ->order('weight', 'desc')
  79. ->select()
  80. ->toArray();
  81. })
  82. ->order('weight', 'desc')
  83. ->select()
  84. ->toArray();
  85. return json_show(CommonModel::$success, '获取成功', $list);
  86. }
  87. }