Customsdeclaration.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Customsdeclaration extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_customsdeclaration','customsdeclaration');
  7. }
  8. public function _remap($arg,$arg_array)
  9. {
  10. if($arg == 'add')//在库标签
  11. {
  12. $this->_add();
  13. }
  14. else if($arg == 'edit')//在库标签
  15. {
  16. $this->_edit($arg_array);
  17. }
  18. else if($arg == 'del')//在库标签
  19. {
  20. $this->_del();
  21. }
  22. else
  23. {
  24. $this->_index();
  25. }
  26. }
  27. //管理
  28. public function _index()
  29. {
  30. $post = $this->input->post(NULL, TRUE);
  31. if(isset($post['page']))
  32. {
  33. $page = $this->input->post('page',true);
  34. $perpage = $this->input->post('perpage',true);
  35. $ename = $this->input->post('ename',true);
  36. $zname = $this->input->post('zname',true);
  37. $bname = $this->input->post('bname',true);
  38. $is_show = $this->input->post('is_show',true);
  39. $where = "1=1 ";
  40. if($ename)
  41. {
  42. $where .= " and ename = '$ename'";
  43. }
  44. if($zname)
  45. {
  46. $where .= " and zname = '$zname'";
  47. }
  48. if($bname)
  49. {
  50. $where .= " and bname = '$bname'";
  51. }
  52. if($is_show){
  53. $where .= " and is_show = '$is_show' ";
  54. }
  55. //数据排序
  56. $order_str = "px asc";
  57. if(empty($page))
  58. {
  59. $start = 0;
  60. $perpage = 1;
  61. }
  62. else
  63. {
  64. $start = ($page - 1)*$perpage;
  65. }
  66. //取得信息列表
  67. $info_list = $this->customsdeclaration->find_all($where,'id,ename,zname,bname,px,is_show',$order_str,$start,$perpage);
  68. foreach ($info_list as $k => $v)
  69. {
  70. $info_list[$k]['is_show'] = $v['is_show'] == 1 ? '显示' : '隐藏';
  71. }
  72. $total = $this->customsdeclaration->find_count($where);
  73. $pagenum = ceil($total/$perpage);
  74. $over = $total-($start+$perpage);
  75. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  76. echo json_encode($rows);exit;
  77. }
  78. $this->_Template('customsdeclaration',$this->data);
  79. }
  80. public function _add()
  81. {
  82. $post = $this->input->post(NULL, TRUE);
  83. if(isset($post['ename']))
  84. {
  85. if($this->customsdeclaration->insert($post))
  86. {
  87. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  88. }
  89. else
  90. {
  91. echo json_encode(array('msg'=>'添加失败','success'=>false));exit;
  92. }
  93. }
  94. $this->_Template('customsdeclaration_add',$this->data);
  95. }
  96. //修改
  97. public function _edit($arg_array)
  98. {
  99. $post = $this->input->post(NULL, TRUE);
  100. if(isset($post['ename']))
  101. {
  102. $id = $this->input->post('id',true);
  103. if($this->customsdeclaration->save($post,$id))
  104. {
  105. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  106. }
  107. else
  108. {
  109. echo json_encode(array('msg'=>'修改失败','success'=>false));exit;
  110. }
  111. }
  112. $arg_array = $arg_array[0];
  113. $customsdeclaration = $this->customsdeclaration->read($arg_array);
  114. $this->data['customsdeclaration'] = $customsdeclaration;
  115. $this->_Template('customsdeclaration_edit',$this->data);
  116. }
  117. //删除
  118. public function _del()
  119. {
  120. $post = $this->input->post(NULL, TRUE);
  121. if(isset($post['s']))
  122. {
  123. $id_arr = $this->input->post('s');
  124. $id_arr = explode(',',$id_arr);
  125. if(!$id_arr)
  126. {
  127. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  128. }
  129. //循环删除记录
  130. foreach ($id_arr as $v)
  131. {
  132. $this->customsdeclaration->remove($v);
  133. }
  134. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  135. }
  136. }
  137. }