menuAction.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. class menuClassAction extends Action
  3. {
  4. public function dataAjax()
  5. {
  6. $this->rows = array();
  7. $type = $this->get('type');
  8. $where = '';
  9. //权限那来的
  10. if($type != ''){
  11. $where = 'and `status`=1 and `ispir`=1 and `type`=0';
  12. if($type=='view')$where = 'and `status`=1 and `type`=0';
  13. }else{
  14. $this->updatepirss();
  15. }
  16. $this->alldata = $this->db->getall('select *,(select count(1)from `[Q]menu` where `pid`=a.id '.$where.')stotal from `[Q]menu` a where 1=1 '.$where.' order by `sort`');
  17. $this->getmenu(0, 1, 1);
  18. echo json_encode(array(
  19. 'totalCount'=> 0,
  20. 'rows' => $this->rows
  21. ));
  22. }
  23. private function getmenu($pid, $oi, $zt)
  24. {
  25. $downid = '';
  26. foreach($this->alldata as $k=>$rs){
  27. if($pid==$rs['pid']){
  28. $downid.=','.$rs['id'].'';
  29. $rs['level'] = $oi;
  30. $zthui = $rs['status'];
  31. if($zt==0){
  32. $rs['ishui']=1;
  33. $zthui = 0;
  34. }
  35. //if($oi>1)$rs['trstyle']='display:none;';
  36. $this->rows[] = $rs;
  37. $len = count($this->rows)-1;
  38. $sidss = $this->getmenu($rs['id'], $oi+1, $zthui);
  39. //if($sidss)$this->rows[$len]['downallid'] = substr($sidss,1);
  40. }
  41. }
  42. return $downid;
  43. }
  44. //下级需要验证,那上级也必须验证的
  45. private function updatepirss()
  46. {
  47. $rows = $this->db->getall('select `pid` from `[Q]menu` where `pid`>0 and `ispir`=1 group by `pid`');
  48. $sid = '0';
  49. foreach($rows as $k=>$rs)$sid.=','.$rs['pid'].'';
  50. if($sid!='')m('menu')->update('`ispir`=1', "`id` in($sid)");
  51. }
  52. /**
  53. * 菜单管理获取菜单
  54. */
  55. public function getdataAjax()
  56. {
  57. $pvalue = (int)$this->get('pvalue','0');
  58. $level = (int)$this->get('level','1');
  59. $rows = $this->db->getall('select *,(select count(1)from `[Q]menu` where `pid`=a.id )stotal from `[Q]menu` a where `pid`='.$pvalue.' order by `sort`');
  60. foreach($rows as $k=>$rs)$rows[$k]['level'] = $level;
  61. echo json_encode(array(
  62. 'totalCount'=> 0,
  63. 'rows' => $rows
  64. ));
  65. }
  66. public function delmenuAjax()
  67. {
  68. $id = (int)$this->post('id');
  69. if(m('menu')->rows('pid='.$id.'')>0)return returnerror('有下级菜单不能删除');
  70. m('menu')->delete($id);
  71. return returnsuccess();
  72. }
  73. }