Customs.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Customs extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_customs','customs');
  7. $this->load->_model('Model_country','country');
  8. $this->load->_model('Model_express','express');
  9. $this->load->_model('Model_detailed','detailed');
  10. }
  11. //定义方法的调用规则 获取URI第二段值
  12. public function _remap($arg,$arg_array)
  13. {
  14. if($arg == 'add')//添加
  15. {
  16. $this->_add();
  17. }
  18. else if($arg == 'edit')//修改
  19. {
  20. $this->_edit($arg_array);
  21. }
  22. else if($arg == 'del')//修改
  23. {
  24. $this->_del();
  25. }
  26. else if($arg == 'detailed')//修改
  27. {
  28. $this->_detailed();
  29. }
  30. else
  31. {
  32. $this->_index();
  33. }
  34. }
  35. //管理
  36. public function _index()
  37. {
  38. $post = $this->input->post(NULL, TRUE);
  39. if(isset($post['page']))
  40. {
  41. $page = $this->input->post('page',true);
  42. $perpage = $this->input->post('perpage',true);
  43. $country = $this->input->post('country',true);
  44. $express = $this->input->post('express',true);
  45. $where = "1=1 ";
  46. if($country)
  47. {
  48. $where .= " and country = '$country'";
  49. }
  50. if($express)
  51. {
  52. $where .= " and express = '$express'";
  53. }
  54. //数据排序
  55. $order_str = "id asc";
  56. if(empty($page))
  57. {
  58. $start = 0;
  59. $perpage = 1;
  60. }
  61. else
  62. {
  63. $start = ($page - 1)*$perpage;
  64. }
  65. //取得信息列表
  66. $info_list = $this->customs->find_all($where,'id,express,country',$order_str,$start,$perpage);
  67. foreach ($info_list as $key=>$value)
  68. {
  69. $country = $this->country->read($value['country']);
  70. $info_list[$key]['country'] = $country['name'];
  71. $express = $this->express->read($value['express']);
  72. $info_list[$key]['express'] = $express['title'];
  73. }
  74. $total = $this->customs->find_count($where);
  75. $pagenum = ceil($total/$perpage);
  76. $over = $total-($start+$perpage);
  77. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  78. echo json_encode($rows);exit;
  79. }
  80. $country = $this->country->find_all();
  81. $this->data['country'] = $country;
  82. $express = $this->express->find_all();
  83. $this->data['express'] = $express;
  84. $this->_Template('customs',$this->data);
  85. }
  86. //添加
  87. public function _add()
  88. {
  89. $post = $this->input->post(NULL, TRUE);
  90. if(isset($post['express']))
  91. {
  92. $post['express'] = $this->input->post('express',true);
  93. $detailedrows = $this->input->post('detailed',true);
  94. //添加detailed信息开始
  95. if($detailedrows != NULL)
  96. {
  97. $dnum = array();
  98. $detaileddata = explode('|',rtrim($detailedrows,'|'));
  99. foreach ($detaileddata as $k=>$v)
  100. {
  101. $rows = explode(',',rtrim($v,','));
  102. $detailedpost['lowerlimit'] = $rows[0];
  103. $detailedpost['includelower'] = $rows[1];
  104. $detailedpost['upperlimit'] = $rows[2];
  105. $detailedpost['includeupper'] = $rows[3];
  106. $detailedpost['calculatemethod'] = $rows[4];
  107. $detailedpost['customsval'] = $rows[5];
  108. $detailedpost['time'] = time().rand(1000,9999);
  109. if($this->detailed->insert($detailedpost))
  110. {
  111. $dnum[] = $detailedpost['time'];
  112. }
  113. }
  114. $post['detailed'] = "|";
  115. foreach ($dnum as $k=>$v)
  116. {
  117. $ddata = $this->detailed->get_time($v);
  118. $post['detailed'] = $post['detailed'].$ddata['id']."|";
  119. }
  120. }
  121. //添加detailed信息结束
  122. $countryck = $this->input->post('country',true);
  123. if($countryck)
  124. {
  125. $countryck = explode(',',rtrim($countryck,','));
  126. foreach ($countryck as $key=>$value)
  127. {
  128. $post['country'] = $value;
  129. $this->customs->insert($post);
  130. }
  131. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  132. }
  133. else
  134. {
  135. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  136. }
  137. }
  138. $country = $this->country->find_all();
  139. $this->data['country'] = $country;
  140. $express = $this->express->find_all();
  141. $this->data['express'] = $express;
  142. $this->_Template('customs_add',$this->data);
  143. }
  144. //修改
  145. public function _edit($arg_array)
  146. {
  147. $post = $this->input->post(NULL, TRUE);
  148. if(isset($post['id']))
  149. {
  150. $id = $this->input->post('id',true);
  151. $post['express'] = $this->input->post('express',true);
  152. $post['country'] = $this->input->post('country',true);
  153. $detailedrows = $this->input->post('detailed',true);
  154. $customs = $this->customs->read($id);
  155. $detaileddata="";
  156. if($detailedrows != NULL)
  157. {
  158. $dnum = array();
  159. $rw = explode('|',rtrim($detailedrows,'|'));
  160. foreach ($rw as $k=>$v)
  161. {
  162. $rows = explode(',',rtrim($v,','));
  163. $detailedpost['lowerlimit'] = $rows[0];
  164. $detailedpost['includelower'] = $rows[1];
  165. $detailedpost['upperlimit'] = $rows[2];
  166. $detailedpost['includeupper'] = $rows[3];
  167. $detailedpost['calculatemethod'] = $rows[4];
  168. $detailedpost['customsval'] = $rows[5];
  169. $detailedpost['time'] = time().rand(1000,9999);
  170. if($this->detailed->insert($detailedpost))
  171. {
  172. $dnum[] = $detailedpost['time'];
  173. }
  174. }
  175. foreach ($dnum as $k=>$v)
  176. {
  177. $ddata = $this->detailed->get_time($v);
  178. $detaileddata = $detaileddata.$ddata['id']."|";
  179. }
  180. }
  181. if($customs['detailed'] == "")
  182. {
  183. $customs['detailed'] = "|";
  184. }
  185. $post['detailed'] = $customs['detailed'].$detaileddata;
  186. if($this->customs->save($post,$id))
  187. {
  188. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  189. }
  190. else
  191. {
  192. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  193. }
  194. }
  195. $arg_array = $arg_array[0];
  196. $customs = $this->customs->read($arg_array);
  197. $this->data['customs'] = $customs;
  198. $country = $this->country->find_all();
  199. $this->data['country'] = $country;
  200. $express = $this->express->find_all();
  201. $this->data['express'] = $express;
  202. $rows = array();
  203. if($customs['detailed'])
  204. {
  205. $detailed = $customs['detailed'];
  206. $detailed = explode('|',trim($detailed,'|'));
  207. foreach ($detailed as $k=>$v)
  208. {
  209. $rw = $this->detailed->read($v);
  210. if($rw['calculatemethod'] == 1)
  211. {
  212. $wr = array('title'=>"按总价");
  213. }
  214. else
  215. {
  216. $wr = array('title'=>"按单价");
  217. }
  218. $rw = array_merge($rw,$wr);
  219. $rows[] = $rw;
  220. }
  221. }
  222. $this->data['rows'] = $rows;
  223. $this->_Template('customs_edit',$this->data);
  224. }
  225. //删除
  226. public function _del()
  227. {
  228. $post = $this->input->post(NULL, TRUE);
  229. if(isset($post['s']))
  230. {
  231. $id_arr = $this->input->post('s');
  232. $id_arr = explode(',',$id_arr);
  233. if(!$id_arr)
  234. {
  235. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  236. }
  237. //循环删除记录
  238. foreach ($id_arr as $v)
  239. {
  240. $this->customs->remove($v);
  241. }
  242. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  243. }
  244. }
  245. //修改数据
  246. public function _detailed()
  247. {
  248. $post = $this->input->post(NULL, TRUE);
  249. if(isset($post['s']))
  250. {
  251. $s = $this->input->post('s');
  252. $id= $this->input->post('id');
  253. $customs = $this->customs->read($id);
  254. $detailed = str_replace('|'.$s.'|','|',$customs['detailed']);
  255. if($detailed == "|")
  256. {
  257. $detailed = "";
  258. }
  259. if($this->customs->save(array('detailed'=>$detailed),$id))//写入删除后的数据
  260. {
  261. echo json_encode(array('success'=>true));exit;
  262. }
  263. else
  264. {
  265. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  266. }
  267. }
  268. }
  269. }