Customsdeclaration.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. $where = "1=1 ";
  39. if($ename)
  40. {
  41. $where .= " and ename = '$ename'";
  42. }
  43. if($zname)
  44. {
  45. $where .= " and zname = '$zname'";
  46. }
  47. if($bname)
  48. {
  49. $where .= " and bname = '$bname'";
  50. }
  51. //数据排序
  52. $order_str = "px asc";
  53. if(empty($page))
  54. {
  55. $start = 0;
  56. $perpage = 1;
  57. }
  58. else
  59. {
  60. $start = ($page - 1)*$perpage;
  61. }
  62. //取得信息列表
  63. $info_list = $this->customsdeclaration->find_all($where,'id,ename,zname,bname,px',$order_str,$start,$perpage);
  64. $total = $this->customsdeclaration->find_count($where);
  65. $pagenum = ceil($total/$perpage);
  66. $over = $total-($start+$perpage);
  67. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  68. echo json_encode($rows);exit;
  69. }
  70. $this->_Template('customsdeclaration',$this->data);
  71. }
  72. public function _add()
  73. {
  74. $post = $this->input->post(NULL, TRUE);
  75. if(isset($post['ename']))
  76. {
  77. if($this->customsdeclaration->insert($post))
  78. {
  79. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  80. }
  81. else
  82. {
  83. echo json_encode(array('msg'=>'添加失败','success'=>false));exit;
  84. }
  85. }
  86. $this->_Template('customsdeclaration_add',$this->data);
  87. }
  88. //修改
  89. public function _edit($arg_array)
  90. {
  91. $post = $this->input->post(NULL, TRUE);
  92. if(isset($post['ename']))
  93. {
  94. $id = $this->input->post('id',true);
  95. if($this->customsdeclaration->save($post,$id))
  96. {
  97. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  98. }
  99. else
  100. {
  101. echo json_encode(array('msg'=>'修改失败','success'=>false));exit;
  102. }
  103. }
  104. $arg_array = $arg_array[0];
  105. $customsdeclaration = $this->customsdeclaration->read($arg_array);
  106. $this->data['customsdeclaration'] = $customsdeclaration;
  107. $this->_Template('customsdeclaration_edit',$this->data);
  108. }
  109. //删除
  110. public function _del()
  111. {
  112. $post = $this->input->post(NULL, TRUE);
  113. if(isset($post['s']))
  114. {
  115. $id_arr = $this->input->post('s');
  116. $id_arr = explode(',',$id_arr);
  117. if(!$id_arr)
  118. {
  119. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  120. }
  121. //循环删除记录
  122. foreach ($id_arr as $v)
  123. {
  124. $this->customsdeclaration->remove($v);
  125. }
  126. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  127. }
  128. }
  129. }