123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace app\cxinv\controller;
- use app\cxinv\model\AdminMenu;
- use app\cxinv\model\UserRole;
- use think\App;
- use think\facade\Validate;
- class Menu extends Base{
- protected $noLogin=[
- "GetMenuAction" , //功能权限集合 工单调用
- ];
- public function __construct(App $app) {
- parent::__construct($app);
- $this->model=new AdminMenu();
- }
- //获取菜单
- public function list(){
- $param = $this->request->param(["relaComNo"=>"","level"=>""],"post","trim");
- $condition = [
- ['status','=',1],
- ['is_display','=',1],
- ['is_del','=',0]
- ];
- $action = UserRole::getAllAction($this->uid,$param['relaComNo'],$this->level);
- if(isset($param['level']) && $param['level'] !== '') $condition[] = ['level','in',[0,$param['level']]];
- else {
- if($this->level == 1) $condition[] = ['level','in',[0,1,2]];
- else $condition[] = ['level','in',[0,$this->level]];
- }
- $list=$this->model->GetMenuByActionArr($action,$condition);
- return success("获取成功",$list);
- }
- //创建\编辑菜单
- public function create(){
- $param=$this->request->param(["name"=>"","url"=>"","route"=>"","pid"=>"","level"=>"","img"=>"","is_display"=>"",
- "weight"=>"","private"=>"","menu_api"=>"",'id'=>0],"post","trim");
- $valid = Validate::rule([
- "name|菜单名称"=>"require|max:255",
- "url|菜单路由"=>"max:255",
- "route|菜单地址"=>"max:255",
- "pid|父级id"=>"require|number|egt:0",
- "id|菜单id"=>"number|egt:0",
- "level|菜单路由"=>"require|number|egt:0",
- "is_display|菜单是否显示"=>"require|number|in:0,1",
- "weight|菜单排序权重"=>"require|number",
- "private|菜单是否私有"=>"require|number|in:0,1",
- "img|菜单图标"=>"max:255",
- ]);
- if(!$valid->check($param)) return error($valid->getError());
- $menu=$this->model->findOrEmpty($param['id']);
- if($param['id']>0){
- if($menu->isEmpty()) return error("菜单不存在");
- }
- $menu->menu_name = $param['name'];
- $menu->menu_url = $param['url'];
- $menu->menu_route = $param['route'];
- $menu->menu_img = $param['img'];
- $menu->pid = $param['pid'];
- $menu->is_display = $param['is_display'];
- $menu->is_private = $param['private'];
- $menu->level = $param['level'];
- $menu->weight = $param['weight'];
- $menu->menu_api = $param['menu_api'];
- $save= $menu->save();
- if($save==false) return error("保存失败");
- return success('保存成功');
- }
- public function status(){
- $param=$this->request->param(["id"=>0,"status"=>1],"post","trim");
- $valid = Validate::rule([
- "id|菜单id"=>"require|number|gt:0",
- "status|状态"=>"require|number|in:0,1",
- ]);
- if(!$valid->check($param)) return error($valid->getError());
- $menu=$this->model->findOrEmpty($param['id']);
- if($menu->isEmpty()) return error("菜单不存在");
- $menu->status = $param['status'];
- $save= $menu->save();
- if($save==false) return error("保存失败");
- return success('保存成功');
- }
- //获取功能权限集合
- public function GetMenuAction(){
- $param = $this->request->param(["level"=>""],"post","trim");
- $list=$this->model->GetMenuActionTree();
- return success('获取成功',$list);
- }
- }
|