dbname ='auth_rule'; } public function index(){ $data=I(); if(isset($data['list'])){ $menu = M('auth_rule'); $count= $menu->count(id);// 查询满足要求的总记录数 $list = $menu->where('types=1')->field('id,title,name,level,pid,status')->select(); $info = array( 'totalRow' => $count, 'pageSize' => $count,//分页时不传 'list' => $list, ); echo json_encode($info); }else{ $this->display(); } } public function add(){ $data=I(); $menu=M('auth_rule'); if(isset($data['pid'])){ $pid=$menu->field('id')->where(array('title'=> $data['pid']))->select(); $name=$data['menuname']; $url=$data['pageurl']; $lv=$data['lv']; $statu=$data['status']; $add=array( 'title'=> $name, 'pid'=> $pid[0]['id'], 'name'=> $url, 'level'=> $lv, 'status'=> $statu, 'types'=>1 ); if ($pid[0]['id']=='83') { $add['system_type']=2; } $res = $menu->add($add); if($res){ //日志开始 $filename_log = "/var/www/html/jdxf/log/config_log".date("Y-m-d").".log"; $data_log ="\r\n".'['.date("Y-m-d H:i:s").']操作人员手机号:'.session('phone_login').'---菜单管理(sp_auth_rule)r\n'; $data_log1 ='添加数据:'.json_encode($add)."\r\n"; file_put_contents($filename_log, $data_log, FILE_APPEND|LOCK_EX); file_put_contents($filename_log, $data_log1, FILE_APPEND|LOCK_EX); //日志结束 $this->mtReturn(200,'菜单新增成功'); }else{ $this->mtReturn(300,'菜单新增成功'); } }else{ $pidlist=$menu->field('id,title,pid')->where('types=1')->select();//二维数组 $this->assign('pidlist',$pidlist); $this->assign('action','/home/Menu/add'); $this->display(); } } public function edit(){ $data=I(); if (session('power')==2){ echo json_encode(array('statusCode'=>300,'message'=>'本账号没有该权限,如需开通请联系管理员')); // $this->mtReturn(300,'本账号没有该权限,如需开通请联系管理员',1); }else { $menu=M('auth_rule'); if(isset($data['menuid'])){ $id =$data['menuid']; $where='id='.$id; $pid=$data['pid']; $name=$data['menuname']; $url=$data['pageurl']; $lv=$data['lv']; $statu=$data['status']; $data=array( 'title'=> $name, 'pid'=> $pid, 'name'=> $url, 'level'=> $lv, 'status'=> $statu ); if ($pid=='83') { $data['system_type']=2; } else{ $data['system_type']=1; } $wx=M()->query("SELECT * FROM sp_auth_rule where id='".$id."'"); $res = $menu->where($where)->save($data); if($res){ //日志代码开始 $data_log ="\r\n".'['.date("Y-m-d H:i:s").']操作人员手机号:'.session('phone_login').'---菜单管理修改(sp_auth_rule表)---ID:'.$id."\r\n"; $data_log1 ='修改前数据:'.json_encode($wx)."\r\n"; $data_log2 ='修改的数据:'.json_encode($data)."\r\n"; $filename_log = "/var/www/html/jdxf/log/config_log".date("Y-m-d").".log"; file_put_contents($filename_log, $data_log, FILE_APPEND|LOCK_EX); file_put_contents($filename_log, $data_log1, FILE_APPEND|LOCK_EX); file_put_contents($filename_log, $data_log2, FILE_APPEND|LOCK_EX); //日志代码结束 echo json_encode($this->mtReturn(200,'菜单编辑成功')); }else{ echo json_encode(array('statusCode'=>300,'message'=>'修改失败')); } }else{ $id=I('id'); $pidlist=$menu->field('id,title as menuname')->where('types=1')->select();//二维数组 $this->assign('pidlist',$pidlist); $where='id='.$id; $res_menu = $menu->field('id,title as menuname,name as pageurl,pid,level as Lv,status')->where($where)->select();//二维数组 //dump($list); $this->assign('res_menu',$res_menu[0]); $this->assign('action','/home/Menu/edit'); $this->display(); } } } }