Express.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Express extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_express','express');
  7. $this->load->_model('Model_service','service');
  8. $this->load->_model('Model_typeclass','typeclass');
  9. $this->load->_model('Model_describecode','describecode');
  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 == 'rows')//获取数据
  27. {
  28. $this->_rows();
  29. }
  30. else if($arg == 'describecode')//修改describecode数据
  31. {
  32. $this->_describecode();
  33. }
  34. else if($arg == 'packing')//修改packing数据
  35. {
  36. $this->_packing();
  37. }
  38. else if($arg == 'read')
  39. {
  40. $this->_read();
  41. }
  42. else
  43. {
  44. $this->_index();
  45. }
  46. }
  47. //管理
  48. public function _index()
  49. {
  50. $post = $this->input->post(NULL, TRUE);
  51. if(isset($post['page']))
  52. {
  53. $page = $this->input->post('page',true);
  54. $perpage = $this->input->post('perpage',true);
  55. $servicename = $this->input->post('servicename',true);
  56. $off = $this->input->post('off',true);
  57. $where = "1=1 ";
  58. if($servicename)
  59. {
  60. $where .= " and servicename like '%$servicename%'";
  61. }
  62. if($off != '')
  63. {
  64. $where .= " and off = '$off'";
  65. }
  66. //数据排序
  67. $order_str = "idsort desc";
  68. if(empty($page))
  69. {
  70. $start = 0;
  71. $perpage = 1;
  72. }
  73. else
  74. {
  75. $start = ($page - 1)*$perpage;
  76. }
  77. //取得信息列表
  78. $info_list = $this->express->find_all($where,'id,servicename,title,url,iscode,aecode,printcode,cxcode,type,out,addresssize,yjtime,off,idsort',$order_str,$start,$perpage);
  79. foreach ($info_list as $k=>$v)
  80. {
  81. if($v['type'] == '1')
  82. {
  83. $info_list[$k]['type'] = '运单';
  84. }
  85. else if($v['type'] == '2')
  86. {
  87. $info_list[$k]['type'] = '发货单';
  88. }
  89. else if($v['type'] == '3')
  90. {
  91. $info_list[$k]['type'] = '不打印单据';
  92. }
  93. if($v['out'] == '1')
  94. {
  95. $info_list[$k]['out'] = '运单';
  96. }
  97. else if($v['out'] == '2')
  98. {
  99. $info_list[$k]['out'] = '发货单';
  100. }
  101. else if($v['out'] == '3')
  102. {
  103. $info_list[$k]['out'] = '运单+发货单';
  104. }
  105. if($v['off'] == '0')
  106. {
  107. $info_list[$k]['off'] = '显示';
  108. }
  109. else if($v['off'] == '1')
  110. {
  111. $info_list[$k]['off'] = '隐藏';
  112. }
  113. }
  114. //格式化数据
  115. $total = $this->express->find_count($where);
  116. $pagenum = ceil($total/$perpage);
  117. $over = $total-($start+$perpage);
  118. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  119. echo json_encode($rows);exit;
  120. }
  121. $class = $this->service->find_all();
  122. $this->data['class'] = $class;
  123. $this->_Template('express',$this->data);
  124. }
  125. //添加
  126. public function _add()
  127. {
  128. $post = $this->input->post(NULL, TRUE);
  129. if(isset($post['title']))
  130. {
  131. $post['title'] = $this->input->post('title',true);
  132. $post['service'] = $this->input->post('service',true);
  133. $post['servicecode'] = $this->input->post('servicecode',true);
  134. $post['servicetitle'] = $this->input->post('servicetitle',true);
  135. $post['servicename'] = $this->input->post('servicename',true);
  136. //$post['account'] = $this->input->post('account',true);
  137. //$post['billweight'] = $this->input->post('billweight',true);
  138. //$post['often'] = $this->input->post('often',true);
  139. $post['url'] = $this->input->post('url',true);
  140. $post['type'] = $this->input->post('type',true);
  141. $post['ioss'] = $this->input->post('ioss',true);
  142. //$post['freight'] = $this->input->post('freight',true);
  143. //$post['ordername'] = $this->input->post('ordername',true);
  144. //$post['slip'] = $this->input->post('slip',true);
  145. //$post['deliver'] = $this->input->post('deliver',true);
  146. $packing = $this->input->post('packing',true);
  147. $describecode = $this->input->post('describecode',true);
  148. if($packing != NULL)
  149. {
  150. $pnum = array();
  151. $packingdata = explode('|',rtrim($packing,'|'));
  152. foreach ($packingdata as $k=>$v)
  153. {
  154. $rows = explode(',',rtrim($v,','));
  155. $packingpost['classid'] = 1;
  156. $packingpost['model'] = $rows[0];
  157. $packingpost['weightend'] = $rows[1];
  158. $packingpost['weight'] = $rows[2];
  159. $packingpost['time'] = time().rand(1000,9999);
  160. if($this->packing->insert($packingpost))
  161. {
  162. $pnum[] = $packingpost['time'];
  163. }
  164. }
  165. $post['packing'] = "|";
  166. foreach ($pnum as $k=>$v)
  167. {
  168. $pdata = $this->packing->get_time($v);
  169. $post['packing'] = $post['packing'].$pdata['id']."|";
  170. }
  171. }
  172. if($describecode != NULL)
  173. {
  174. $dnum = array();
  175. $describecodedata = explode('|',rtrim($describecode,'|'));
  176. foreach ($describecodedata as $k=>$v)
  177. {
  178. $rows = explode(',',rtrim($v,','));
  179. $describecodepost['product'] = $rows[0];
  180. $describecodepost['expresscode'] = $rows[1];
  181. $describecodepost['time'] = time().rand(1000,9999);
  182. if($this->describecode->insert($describecodepost))
  183. {
  184. $dnum[] = $describecodepost['time'];
  185. }
  186. }
  187. $post['describecode'] = "|";
  188. foreach ($dnum as $k=>$v)
  189. {
  190. $ddata = $this->describecode->get_time($v);
  191. $post['describecode'] = $post['describecode'].$ddata['id']."|";
  192. }
  193. }
  194. if($this->express->insert($post))
  195. {
  196. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  197. }
  198. else
  199. {
  200. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  201. }
  202. }
  203. $class = $this->service->find_all("1=1",'*','title asc');
  204. $this->data['class'] = $class;
  205. $this->_Template('express_add',$this->data);
  206. }
  207. //修改
  208. public function _edit($arg_array)
  209. {
  210. $post = $this->input->post(NULL, TRUE);
  211. if(isset($post['id']))
  212. {
  213. $id = $this->input->post('id',true);
  214. $post['title'] = $this->input->post('title',true);
  215. $post['service'] = $this->input->post('service',true);
  216. $post['servicecode'] = $this->input->post('servicecode',true);
  217. $post['servicetitle'] = $this->input->post('servicetitle',true);
  218. $post['servicename'] = $this->input->post('servicename',true);
  219. //$post['account'] = $this->input->post('account',true);
  220. $post['billweight'] = $this->input->post('billweight',true);
  221. $post['often'] = $this->input->post('often',true);
  222. $post['url'] = $this->input->post('url',true);
  223. $post['type'] = $this->input->post('type',true);
  224. $post['freight'] = $this->input->post('freight',true);
  225. $post['ordername'] = $this->input->post('ordername',true);
  226. $post['slip'] = $this->input->post('slip',true);
  227. $post['deliver'] = $this->input->post('deliver',true);
  228. $post['ioss'] = $this->input->post('ioss',true);
  229. $packingsun = $this->input->post('packing',true);
  230. $describecodesun = $this->input->post('describecode',true);
  231. $express = $this->express->read($id);
  232. $packingmoon="";$describecodemoon="";
  233. if($packingsun != NULL)
  234. {
  235. $pnum = array();
  236. $packingdata = explode('|',rtrim($packingsun,'|'));
  237. foreach ($packingdata as $k=>$v)
  238. {
  239. $rows = explode(',',rtrim($v,','));
  240. $packingpost['classid'] = 1;
  241. $packingpost['model'] = $rows[0];
  242. $packingpost['weightend'] = $rows[1];
  243. $packingpost['weight'] = $rows[2];
  244. $packingpost['time'] = time().rand(1000,9999);
  245. if($this->packing->insert($packingpost))
  246. {
  247. $pnum[] = $packingpost['time'];
  248. }
  249. }
  250. foreach ($pnum as $k=>$v)
  251. {
  252. $pdata = $this->packing->get_time($v);
  253. $packingmoon = $packingmoon.$pdata['id']."|";
  254. }
  255. }
  256. if($describecodesun != NULL)
  257. {
  258. $dnum = array();
  259. $describecodedata = explode('|',rtrim($describecodesun,'|'));
  260. foreach ($describecodedata as $k=>$v)
  261. {
  262. $rows = explode(',',rtrim($v,','));
  263. $describecodepost['product'] = $rows[0];
  264. $describecodepost['expresscode'] = $rows[1];
  265. $describecodepost['time'] = time().rand(1000,9999);
  266. if($this->describecode->insert($describecodepost))
  267. {
  268. $dnum[] = $describecodepost['time'];
  269. }
  270. }
  271. foreach ($dnum as $k=>$v)
  272. {
  273. $ddata = $this->describecode->get_time($v);
  274. $describecodemoon = $describecodemoon.$ddata['id']."|";
  275. }
  276. }
  277. $post['packing'] = $express['packing'].$packingmoon;
  278. $post['describecode'] = $express['describecode'].$describecodemoon;
  279. if($this->express->save($post,$id))
  280. {
  281. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  282. }
  283. else
  284. {
  285. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  286. }
  287. }
  288. $arg_array = $arg_array[0];
  289. $express = $this->express->read($arg_array);
  290. $class = $this->service->find_all("1=1",'*','title asc');
  291. $this->data['class'] = $class;
  292. $this->data['express'] = $express;
  293. $pdata = array();$ddata = array();
  294. if($express['packing'])
  295. {
  296. $packing = $express['packing'];
  297. $packing = explode('|',trim($packing,'|'));
  298. foreach ($packing as $k=>$v)
  299. {
  300. $pdata[] = $this->packing->read($v);
  301. }
  302. }
  303. if($express['describecode'])
  304. {
  305. $describecode = $express['describecode'];
  306. $describecode = explode('|',trim($describecode,'|'));
  307. foreach ($describecode as $k=>$v)
  308. {
  309. $ddata[] = $this->describecode->read($v);
  310. }
  311. foreach ($ddata as $k=>$v)
  312. {
  313. $sdata = $this->typeclass->read($v['product']);
  314. $ddata[$k]['producttitle'] = $sdata['title'];
  315. }
  316. }
  317. $this->data['pdata'] = $pdata;
  318. $this->data['ddata'] = $ddata;
  319. $this->_Template('express_edit',$this->data);
  320. }
  321. //删除
  322. public function _del()
  323. {
  324. $post = $this->input->post(NULL, TRUE);
  325. if(isset($post['s']))
  326. {
  327. $id_arr = $this->input->post('s');
  328. $id_arr = explode(',',$id_arr);
  329. if(!$id_arr)
  330. {
  331. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  332. }
  333. //循环删除记录
  334. foreach ($id_arr as $v)
  335. {
  336. $this->express->remove($v);
  337. }
  338. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  339. }
  340. }
  341. //修改数据
  342. public function _describecode()
  343. {
  344. $post = $this->input->post(NULL, TRUE);
  345. if(isset($post['s']))
  346. {
  347. $s = $this->input->post('s');
  348. $id= $this->input->post('id');
  349. $express = $this->express->read($id);
  350. $describecode = str_replace('|'.$s.'|','|',$express['describecode']);
  351. if($describecode == "|")
  352. {
  353. $describecode = "";
  354. }
  355. if($this->express->save(array('describecode'=>$describecode),$id))//写入删除后的数据
  356. {
  357. echo json_encode(array('success'=>true));exit;
  358. }
  359. else
  360. {
  361. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  362. }
  363. }
  364. }
  365. //修改数据
  366. public function _packing()
  367. {
  368. $post = $this->input->post(NULL, TRUE);
  369. if(isset($post['s']))
  370. {
  371. $s = $this->input->post('s');
  372. $id= $this->input->post('id');
  373. $express = $this->express->read($id);
  374. $packing = str_replace('|'.$s.'|','|',$express['packing']);
  375. if($packing == "|")
  376. {
  377. $packing = "";
  378. }
  379. if($this->express->save(array('packing'=>$packing),$id))//写入删除后的数据
  380. {
  381. echo json_encode(array('success'=>true));exit;
  382. }
  383. else
  384. {
  385. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  386. }
  387. }
  388. }
  389. public function _read()
  390. {
  391. $post = $this->input->post(NULL, TRUE);
  392. if(isset($post['id']))
  393. {
  394. $id = $this->input->post('id');
  395. $data = $this->express->read($id);
  396. if(isset($data['id']) && $data['xxts'] != '')
  397. {
  398. echo json_encode(array('msg'=>$data['xxts'],'success'=>true));exit;
  399. }
  400. else
  401. {
  402. echo json_encode(array('success'=>false));exit;
  403. }
  404. }
  405. }
  406. }