Menu.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\cxinv\controller;
  3. use app\cxinv\model\AdminMenu;
  4. use app\cxinv\model\UserRole;
  5. use think\App;
  6. use think\facade\Validate;
  7. class Menu extends Base{
  8. protected $noLogin=[
  9. "GetMenuAction" , //功能权限集合 工单调用
  10. ];
  11. public function __construct(App $app) {
  12. parent::__construct($app);
  13. $this->model=new AdminMenu();
  14. }
  15. //获取菜单
  16. public function list(){
  17. $param = $this->request->param(["relaComNo"=>"","level"=>""],"post","trim");
  18. $condition = [
  19. ['status','=',1],
  20. ['is_display','=',1],
  21. ['is_del','=',0]
  22. ];
  23. $action = UserRole::getAllAction($this->uid,$param['relaComNo'],$this->level);
  24. if(isset($param['level']) && $param['level'] !== '') $condition[] = ['level','in',[0,$param['level']]];
  25. else {
  26. if($this->level == 1) $condition[] = ['level','in',[0,1,2]];
  27. else $condition[] = ['level','in',[0,$this->level]];
  28. }
  29. $list=$this->model->GetMenuByActionArr($action,$condition);
  30. return success("获取成功",$list);
  31. }
  32. //创建\编辑菜单
  33. public function create(){
  34. $param=$this->request->param(["name"=>"","url"=>"","route"=>"","pid"=>"","level"=>"","img"=>"","is_display"=>"",
  35. "weight"=>"","private"=>"","menu_api"=>"",'id'=>0],"post","trim");
  36. $valid = Validate::rule([
  37. "name|菜单名称"=>"require|max:255",
  38. "url|菜单路由"=>"max:255",
  39. "route|菜单地址"=>"max:255",
  40. "pid|父级id"=>"require|number|egt:0",
  41. "id|菜单id"=>"number|egt:0",
  42. "level|菜单路由"=>"require|number|egt:0",
  43. "is_display|菜单是否显示"=>"require|number|in:0,1",
  44. "weight|菜单排序权重"=>"require|number",
  45. "private|菜单是否私有"=>"require|number|in:0,1",
  46. "img|菜单图标"=>"max:255",
  47. ]);
  48. if(!$valid->check($param)) return error($valid->getError());
  49. $menu=$this->model->findOrEmpty($param['id']);
  50. if($param['id']>0){
  51. if($menu->isEmpty()) return error("菜单不存在");
  52. }
  53. $menu->menu_name = $param['name'];
  54. $menu->menu_url = $param['url'];
  55. $menu->menu_route = $param['route'];
  56. $menu->menu_img = $param['img'];
  57. $menu->pid = $param['pid'];
  58. $menu->is_display = $param['is_display'];
  59. $menu->is_private = $param['private'];
  60. $menu->level = $param['level'];
  61. $menu->weight = $param['weight'];
  62. $menu->menu_api = $param['menu_api'];
  63. $save= $menu->save();
  64. if($save==false) return error("保存失败");
  65. return success('保存成功');
  66. }
  67. public function status(){
  68. $param=$this->request->param(["id"=>0,"status"=>1],"post","trim");
  69. $valid = Validate::rule([
  70. "id|菜单id"=>"require|number|gt:0",
  71. "status|状态"=>"require|number|in:0,1",
  72. ]);
  73. if(!$valid->check($param)) return error($valid->getError());
  74. $menu=$this->model->findOrEmpty($param['id']);
  75. if($menu->isEmpty()) return error("菜单不存在");
  76. $menu->status = $param['status'];
  77. $save= $menu->save();
  78. if($save==false) return error("保存失败");
  79. return success('保存成功');
  80. }
  81. //获取功能权限集合
  82. public function GetMenuAction(){
  83. $param = $this->request->param(["level"=>""],"post","trim");
  84. $list=$this->model->GetMenuActionTree();
  85. return success('获取成功',$list);
  86. }
  87. }