optionAction.php 3.0 KB

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