Express.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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($post['sbjz_min']*1 > $post['sbjz']*1){
  195. echo json_encode(array('msg'=>'最低申报价不能大于最高申报价!!!','success'=>false));exit;
  196. }
  197. if($post['shouldmoney_min']*1 > $post['shouldmoney']*1){
  198. echo json_encode(array('msg'=>'最低订单金额不能大于最高订单金额!!!','success'=>false));exit;
  199. }
  200. if($post['weight_limit_min']*1 > $post['weight_limit']*1){
  201. echo json_encode(array('msg'=>'最低快递限重不能大于最高快递限重!!!','success'=>false));exit;
  202. }
  203. if($this->express->insert($post))
  204. {
  205. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  206. }
  207. else
  208. {
  209. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  210. }
  211. }
  212. $class = $this->service->find_all("1=1",'*','title asc');
  213. $this->data['class'] = $class;
  214. $this->_Template('express_add',$this->data);
  215. }
  216. //修改
  217. public function _edit($arg_array)
  218. {
  219. $post = $this->input->post(NULL, TRUE);
  220. if(isset($post['id']))
  221. {
  222. $id = $this->input->post('id',true);
  223. $post['title'] = $this->input->post('title',true);
  224. $post['service'] = $this->input->post('service',true);
  225. $post['servicecode'] = $this->input->post('servicecode',true);
  226. $post['servicetitle'] = $this->input->post('servicetitle',true);
  227. $post['servicename'] = $this->input->post('servicename',true);
  228. //$post['account'] = $this->input->post('account',true);
  229. $post['billweight'] = $this->input->post('billweight',true);
  230. $post['often'] = $this->input->post('often',true);
  231. $post['url'] = $this->input->post('url',true);
  232. $post['type'] = $this->input->post('type',true);
  233. $post['freight'] = $this->input->post('freight',true);
  234. $post['ordername'] = $this->input->post('ordername',true);
  235. $post['slip'] = $this->input->post('slip',true);
  236. $post['deliver'] = $this->input->post('deliver',true);
  237. $post['ioss'] = $this->input->post('ioss',true);
  238. $packingsun = $this->input->post('packing',true);
  239. $describecodesun = $this->input->post('describecode',true);
  240. $express = $this->express->read($id);
  241. $packingmoon="";$describecodemoon="";
  242. if($packingsun != NULL)
  243. {
  244. $pnum = array();
  245. $packingdata = explode('|',rtrim($packingsun,'|'));
  246. foreach ($packingdata as $k=>$v)
  247. {
  248. $rows = explode(',',rtrim($v,','));
  249. $packingpost['classid'] = 1;
  250. $packingpost['model'] = $rows[0];
  251. $packingpost['weightend'] = $rows[1];
  252. $packingpost['weight'] = $rows[2];
  253. $packingpost['time'] = time().rand(1000,9999);
  254. if($this->packing->insert($packingpost))
  255. {
  256. $pnum[] = $packingpost['time'];
  257. }
  258. }
  259. foreach ($pnum as $k=>$v)
  260. {
  261. $pdata = $this->packing->get_time($v);
  262. $packingmoon = $packingmoon.$pdata['id']."|";
  263. }
  264. }
  265. if($describecodesun != NULL)
  266. {
  267. $dnum = array();
  268. $describecodedata = explode('|',rtrim($describecodesun,'|'));
  269. foreach ($describecodedata as $k=>$v)
  270. {
  271. $rows = explode(',',rtrim($v,','));
  272. $describecodepost['product'] = $rows[0];
  273. $describecodepost['expresscode'] = $rows[1];
  274. $describecodepost['time'] = time().rand(1000,9999);
  275. if($this->describecode->insert($describecodepost))
  276. {
  277. $dnum[] = $describecodepost['time'];
  278. }
  279. }
  280. foreach ($dnum as $k=>$v)
  281. {
  282. $ddata = $this->describecode->get_time($v);
  283. $describecodemoon = $describecodemoon.$ddata['id']."|";
  284. }
  285. }
  286. if($post['sbjz_min']*1 > $post['sbjz']*1){
  287. echo json_encode(array('msg'=>'最低申报价不能大于最高申报价!!!','success'=>false));exit;
  288. }
  289. if($post['shouldmoney_min']*1 > $post['shouldmoney']*1){
  290. echo json_encode(array('msg'=>'最低订单金额不能大于最高订单金额!!!','success'=>false));exit;
  291. }
  292. if($post['weight_limit_min']*1 > $post['weight_limit']*1){
  293. echo json_encode(array('msg'=>'最低快递限重不能大于最高快递限重!!!','success'=>false));exit;
  294. }
  295. $post['packing'] = $express['packing'].$packingmoon;
  296. $post['describecode'] = $express['describecode'].$describecodemoon;
  297. if($this->express->save($post,$id))
  298. {
  299. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  300. }
  301. else
  302. {
  303. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  304. }
  305. }
  306. $arg_array = $arg_array[0];
  307. $express = $this->express->read($arg_array);
  308. $class = $this->service->find_all("1=1",'*','title asc');
  309. $this->data['class'] = $class;
  310. $this->data['express'] = $express;
  311. $pdata = array();$ddata = array();
  312. if($express['packing'])
  313. {
  314. $packing = $express['packing'];
  315. $packing = explode('|',trim($packing,'|'));
  316. foreach ($packing as $k=>$v)
  317. {
  318. $pdata[] = $this->packing->read($v);
  319. }
  320. }
  321. if($express['describecode'])
  322. {
  323. $describecode = $express['describecode'];
  324. $describecode = explode('|',trim($describecode,'|'));
  325. foreach ($describecode as $k=>$v)
  326. {
  327. $ddata[] = $this->describecode->read($v);
  328. }
  329. foreach ($ddata as $k=>$v)
  330. {
  331. $sdata = $this->typeclass->read($v['product']);
  332. $ddata[$k]['producttitle'] = $sdata['title'];
  333. }
  334. }
  335. $this->data['pdata'] = $pdata;
  336. $this->data['ddata'] = $ddata;
  337. $this->_Template('express_edit',$this->data);
  338. }
  339. //删除
  340. public function _del()
  341. {
  342. $post = $this->input->post(NULL, TRUE);
  343. if(isset($post['s']))
  344. {
  345. $id_arr = $this->input->post('s');
  346. $id_arr = explode(',',$id_arr);
  347. if(!$id_arr)
  348. {
  349. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  350. }
  351. //循环删除记录
  352. foreach ($id_arr as $v)
  353. {
  354. $this->express->remove($v);
  355. }
  356. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  357. }
  358. }
  359. //修改数据
  360. public function _describecode()
  361. {
  362. $post = $this->input->post(NULL, TRUE);
  363. if(isset($post['s']))
  364. {
  365. $s = $this->input->post('s');
  366. $id= $this->input->post('id');
  367. $express = $this->express->read($id);
  368. $describecode = str_replace('|'.$s.'|','|',$express['describecode']);
  369. if($describecode == "|")
  370. {
  371. $describecode = "";
  372. }
  373. if($this->express->save(array('describecode'=>$describecode),$id))//写入删除后的数据
  374. {
  375. echo json_encode(array('success'=>true));exit;
  376. }
  377. else
  378. {
  379. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  380. }
  381. }
  382. }
  383. //修改数据
  384. public function _packing()
  385. {
  386. $post = $this->input->post(NULL, TRUE);
  387. if(isset($post['s']))
  388. {
  389. $s = $this->input->post('s');
  390. $id= $this->input->post('id');
  391. $express = $this->express->read($id);
  392. $packing = str_replace('|'.$s.'|','|',$express['packing']);
  393. if($packing == "|")
  394. {
  395. $packing = "";
  396. }
  397. if($this->express->save(array('packing'=>$packing),$id))//写入删除后的数据
  398. {
  399. echo json_encode(array('success'=>true));exit;
  400. }
  401. else
  402. {
  403. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  404. }
  405. }
  406. }
  407. public function _read()
  408. {
  409. $post = $this->input->post(NULL, TRUE);
  410. if(isset($post['id']))
  411. {
  412. $id = $this->input->post('id');
  413. $data = $this->express->read($id);
  414. if(isset($data['id']) && $data['xxts'] != '')
  415. {
  416. echo json_encode(array('msg'=>$data['xxts'],'success'=>true));exit;
  417. }
  418. else
  419. {
  420. echo json_encode(array('success'=>false));exit;
  421. }
  422. }
  423. }
  424. }