Express.php 12 KB

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