optionAction.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. class optionClassAction extends Action
  3. {
  4. private $pid;
  5. public function getlistAjax()
  6. {
  7. $num = $this->request('num');
  8. $name = $this->request('name');
  9. $key = $this->post('key');
  10. $id = $this->option->getnumtoid($num, $name, false);
  11. $this->option->update("`pid`=1,`name`='行政选项'","`num`='goods'"); //行政选项移动到数据选项下
  12. if(isempt($key)){
  13. $where = "a.`pid`='$id'";
  14. }else{
  15. $where = "1=1 and a.`name` is not null and (a.`name` like '%$key%' or a.`num`='$key') ";
  16. }
  17. $rows = $this->db->getall("select *,(select count(1) from `[Q]option` where pid=a.id)as stotal from `[Q]option` a where $where order by a.`sort`, a.`id`");
  18. echo json_encode(array(
  19. 'totalCount'=> $this->db->count,
  20. 'rows' => $rows,
  21. 'pid' => $id
  22. ));
  23. }
  24. public function getfileAjax()
  25. {
  26. $mtype = $this->request('mtype');
  27. $mid = $this->request('mid');
  28. $rows = m('file')->getfile($mtype, $mid);
  29. echo json_encode($rows);
  30. }
  31. public function gettreedataAjax()
  32. {
  33. $num = $this->get('num');
  34. if($num=='')exit('error;');
  35. if(!contain($num, 'gerenvcard_') && ISMORECOM && $cnum=m('admin')->getcompanynum())$num.='_'.$cnum.'';//多单位时个人通讯不用加单位编号
  36. $pid = $this->option->getnumtoid($num,''.$num.'选项', false);
  37. $rows = $this->option->gettreedata($pid);
  38. $rows = array(
  39. 'rows' => $rows,
  40. 'pid' => $pid
  41. );
  42. $this->returnjson($rows);
  43. }
  44. public function deloptionAjax()
  45. {
  46. $id = (int)$this->post('id','0');
  47. $stable = $this->post('stable');
  48. $delbo = true;
  49. if($delbo)if($this->option->rows("`pid`='$id'")>0)$delbo=false;
  50. if(!$delbo)$this->showreturn('','有下级分类不允许删除',201);
  51. $this->option->delete($id);
  52. if($stable!='')m($stable)->update('`typeid`=0', "`typeid`='$id'");
  53. $this->showreturn();
  54. }
  55. //分类移动
  56. public function movetypeAjax()
  57. {
  58. $id = (int)$this->post('id','0');
  59. $toid = (int)$this->post('toid','0');
  60. $lx = (int)$this->post('lx','0');
  61. $spath = $this->db->getpval('[Q]option','pid','pid', $toid,'],[');
  62. $spath = '['.$spath.']';
  63. if(contain($spath,'['.$id.']')){
  64. echo '不能移动到自己的下级';
  65. }else{
  66. $this->option->update('pid='.$toid.'', $id);
  67. echo 'ok';
  68. }
  69. }
  70. public function downshubefore()
  71. {
  72. $pid = (int)$this->post('pid','0');
  73. $this->pid = $pid;
  74. return 'and `pid`='.$pid.'';
  75. }
  76. public function downshuafter($table, $rows)
  77. {
  78. $db = m($table);
  79. foreach($rows as $k=>$rs){
  80. $dcount = $db->rows('pid='.$rs['id'].'');
  81. if($dcount>0)$rows[$k]['dcount'] = $dcount;
  82. }
  83. $darr = array();
  84. if($this->pid>0){
  85. $this->getdonwds($db,$this->pid);
  86. $darr = $this->downarr;
  87. }
  88. return array(
  89. 'rows' => $rows,
  90. 'darr' => $darr
  91. );
  92. }
  93. private $downarr = array();
  94. private function getdonwds($db,$id)
  95. {
  96. if($id>1){
  97. $rs = $db->getone('`id`='.$id.'','id,pid,name,num');
  98. if($rs){
  99. $this->getdonwds($db, $rs['pid']);
  100. $this->downarr[] = $rs;
  101. }
  102. }
  103. }
  104. }
粤ICP备19079148号