Outbound.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. header("Access-Control-Allow-Origin: *");
  3. class Outbound extends Start_Controller {
  4. public function __construct(){
  5. parent::__construct();
  6. $this->load->library('session');
  7. $this->load->_model('Model_outbound','outbound');
  8. $this->load->_model('Model_excel','excel');
  9. $this->load->_model('Model_express','express');
  10. $this->load->_model('Model_express','express');
  11. $this->load->_model('Model_fullorder','fullorder');
  12. $this->load->_model('Model_fullordertt','fullordertt');
  13. $this->load->_model('Model_fullordersmt','fullordersmt');
  14. }
  15. //定义方法的调用规则 获取URI第二段值
  16. public function _remap($arg,$arg_array)
  17. {
  18. if($arg == 'data')//出库页
  19. {
  20. $this->_data();
  21. }
  22. else if($arg == 'del')
  23. {
  24. $this->_del();
  25. }
  26. else if($arg == 'add')
  27. {
  28. $this->_add();
  29. }
  30. else
  31. {
  32. $this->_index();
  33. }
  34. }
  35. public function _index()
  36. {
  37. $post = $this->input->post(NULL, TRUE);
  38. if(isset($post['number']))
  39. {
  40. $where = "gtime = '".date('Ymd',time())."'";
  41. $number = $this->input->post('number',true);
  42. $id = $this->input->post('id',true);
  43. $type = $this->input->post('type',true);
  44. $express = $this->input->post('express',true);
  45. if($id)
  46. {
  47. if($type)
  48. {
  49. $where .= " and type = '$type'";
  50. }
  51. else
  52. {
  53. $uw = '';
  54. $u = $this->user->get_api($id);
  55. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  56. foreach ($u['warehouse'] as $v)
  57. {
  58. $uw .= " type = '$v' or";
  59. }
  60. $uw = rtrim($uw,'or');
  61. $uw = " and (".ltrim($uw,' ').")";
  62. $where .= $uw;
  63. }
  64. }
  65. if(!$number)
  66. {
  67. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  68. }
  69. if(!$type)
  70. {
  71. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  72. }
  73. if(!$express)
  74. {
  75. echo json_encode(array('msg'=>'请选择需要录入的快递!','success'=>false));exit;
  76. }
  77. if(stripos($number,'-') !== false)
  78. {
  79. echo json_encode(array('msg'=>'请扫描正确的运单号!','success'=>false));exit;
  80. }
  81. if(substr($number,0,3) == '788' && substr($number,-4,4) == '0430')//Fedex联邦
  82. {
  83. $number = substr($number,0,12);
  84. }
  85. if(strlen($number) == '34')//联邦杭州超长运单截取
  86. {
  87. $number = substr($number,22,12);
  88. }
  89. $sex = $this->express->read($express);
  90. $ex = array('DHL'=>10,'FEDEX'=>12,'FEDEXGF'=>12,'UPS'=>18,'GES'=>17,'TNT'=>9,'ARAMEX'=>11,'EMS_ZX_ZX_US'=>13);
  91. if(isset($ex[$sex['printcode']]))
  92. {
  93. if(strlen($number) != $ex[$sex['printcode']])
  94. {
  95. echo json_encode(array('msg'=>'运单号错误,此单请重新录入运单号!','success'=>false));exit;
  96. }
  97. }
  98. $yd = $this->fullorder->find_all("waybill = '$number' and library = '2'");
  99. if(isset($yd[0]['number']))
  100. {
  101. $number = $yd[0]['number'];
  102. }
  103. else
  104. {
  105. $yd = $this->fullordersmt->find_all("waybill = '$number'");
  106. if(isset($yd[0]['number']))
  107. {
  108. $number = $yd[0]['number'];
  109. }
  110. else
  111. {
  112. echo json_encode(array('msg'=>'系统中未查到此运单,请确认!','success'=>false));exit;
  113. }
  114. }
  115. $nu = $this->outbound->get_number($number);
  116. if($nu)
  117. {
  118. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  119. }
  120. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'express'=>$express,'gtime'=>date('Ymd',time()),'time'=>time())))
  121. {
  122. $data = $this->outbound->find_count($where);
  123. echo json_encode(array('msg'=>$data,'music'=>'1','success'=>true));exit;
  124. }
  125. else
  126. {
  127. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  128. }
  129. }
  130. }
  131. public function _indexxxxx()
  132. {
  133. $post = $this->input->post(NULL, TRUE);
  134. if(isset($post['number']))
  135. {
  136. $where = "gtime = '".date('Ymd',time())."'";
  137. $number = $this->input->post('number',true);
  138. $id = $this->input->post('id',true);
  139. $type = $this->input->post('type',true);
  140. $express = $this->input->post('express',true);
  141. if($id)
  142. {
  143. if($type)
  144. {
  145. $where .= " and type = '$type'";
  146. }
  147. else
  148. {
  149. $uw = '';
  150. $u = $this->user->get_api($id);
  151. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  152. foreach ($u['warehouse'] as $v)
  153. {
  154. $uw .= " type = '$v' or";
  155. }
  156. $uw = rtrim($uw,'or');
  157. $uw = " and (".ltrim($uw,' ').")";
  158. $where .= $uw;
  159. }
  160. }
  161. if(!$number)
  162. {
  163. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  164. }
  165. if(!$type)
  166. {
  167. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  168. }
  169. if(!$express)
  170. {
  171. echo json_encode(array('msg'=>'请选择需要录入的快递!','success'=>false));exit;
  172. }
  173. $nu = $this->outbound->get_number($number);
  174. if($nu)
  175. {
  176. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  177. }
  178. $wa = $this->outbound->get_waybill($number);
  179. if($wa)
  180. {
  181. echo json_encode(array('msg'=>'错误!此运单号'.date('Ymd',$wa['time']).'已录入!','success'=>false));exit;
  182. }
  183. $jd = $this->outbound->find_all($where,'*','id desc');
  184. if(!isset($jd[0]) || $jd[0]['waybill'] != '')
  185. {
  186. $pd = explode('-',$number);
  187. if(!isset($pd[1]) || !isset($pd[2]))
  188. {
  189. echo json_encode(array('msg'=>'编号不正确,请重试!','success'=>false));exit;
  190. }
  191. if(strlen($pd[1]) == '5' && strlen($pd[2]) == '3')
  192. {
  193. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'express'=>$express,'gtime'=>date('Ymd',time()),'time'=>time())))
  194. {
  195. $data = $this->outbound->find_count($where);
  196. echo json_encode(array('msg'=>$data,'music'=>'1','success'=>true));exit;
  197. }
  198. else
  199. {
  200. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  201. }
  202. }
  203. else
  204. {
  205. echo json_encode(array('msg'=>'编号不正确!','success'=>false));exit;
  206. }
  207. }
  208. else
  209. {
  210. if(stripos($number,'-') !== false)
  211. {
  212. echo json_encode(array('msg'=>'请扫描'.$jd[0]['number'].'对应的运单号!','success'=>false));exit;
  213. }
  214. if(substr($number,0,3) == '788' && substr($number,-4,4) == '0430')//Fedex联邦
  215. {
  216. $number = substr($number,0,12);
  217. }
  218. if(strlen($number) == '34')//联邦杭州超长运单截取
  219. {
  220. $number = substr($number,22,12);
  221. }
  222. $sex = $this->express->read($express);
  223. $ex = array('DHL'=>10,'FEDEX'=>12,'FEDEXGF'=>12,'UPS'=>18,'GES'=>17,'TNT'=>9,'ARAMEX'=>11,'EMS_ZX_ZX_US'=>13);
  224. if(isset($ex[$sex['printcode']]))
  225. {
  226. if(strlen($number) != $ex[$sex['printcode']])
  227. {
  228. echo json_encode(array('msg'=>'运单号错误,此单请重新录入运单号!','success'=>false));exit;
  229. }
  230. }
  231. if($this->outbound->save(array('waybill'=>$number),$jd[0]['id']))
  232. {
  233. $data = $this->outbound->find_count($where);
  234. echo json_encode(array('msg'=>$data,'music'=>'1','success'=>true));exit;
  235. }
  236. else
  237. {
  238. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  239. }
  240. }
  241. }
  242. }
  243. public function _data()
  244. {
  245. if(isset($_GET['fexcel']))
  246. {
  247. $id = $this->input->get('id',true);
  248. $timetk = $this->input->get('timetk',true);
  249. $timetj = $this->input->get('timetj',true);
  250. $library = $this->input->get('library',true);
  251. $type = $this->input->get('type',true);
  252. $number = $this->input->get('number',true);
  253. $waybill = $this->input->get('waybill',true);
  254. $express = $this->input->get('express',true);
  255. $timetk = strtotime($timetk);
  256. $timetj = strtotime($timetj);
  257. $where = "type != 0";
  258. if($timetk && $timetj)
  259. {
  260. $where .= " and time > '$timetk' and time < '$timetj'";
  261. }
  262. if($id)
  263. {
  264. if($type)
  265. {
  266. $where .= " and type = '$type'";
  267. }
  268. else
  269. {
  270. $uw = '';
  271. $u = $this->user->get_api($id);
  272. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  273. foreach ($u['warehouse'] as $v)
  274. {
  275. $uw .= " type = '$v' or";
  276. }
  277. $uw = rtrim($uw,'or');
  278. $uw = " and (".ltrim($uw,' ').")";
  279. $where .= $uw;
  280. }
  281. }
  282. if($number)
  283. {
  284. $where .= " and number = '$number'";
  285. }
  286. if($waybill)
  287. {
  288. $where .= " and waybill = '$waybill'";
  289. }
  290. if($express)
  291. {
  292. $where .= " and express = '$express'";
  293. }
  294. $data = array();
  295. $datafy = array();
  296. $j = 0;
  297. $info_list = $this->outbound->find_all($where,'number,waybill');
  298. foreach ($info_list as $key=>$value)
  299. {
  300. $datafy[] = array($value['number'],$value['waybill']);
  301. if($j == $library-1)
  302. {
  303. $data[] = $datafy;
  304. $j = 0;$datafy = array();
  305. }
  306. else
  307. {
  308. $j++;
  309. }
  310. }
  311. $data[] = $datafy;
  312. //格式化数据
  313. $i = 0;$cpexcel = array();
  314. $title = date('Ymd',time())."发货统计信息"; $td = '';
  315. for($i=0;$i<ceil(count($info_list)/$library);$i++)
  316. {
  317. $td .= "<td>组".($i+1)."</td><td></td>";
  318. }
  319. $titlename = "<table border=1>
  320. <tr>
  321. ".$td."
  322. </tr>
  323. </table>";
  324. $filename = $title.".xls";
  325. $this->excel->get_fz6($data,$titlename,$filename);
  326. }
  327. }
  328. public function _add()
  329. {
  330. $post = $this->input->post(NULL, TRUE);
  331. if(isset($post['number']))
  332. {
  333. $where = "gtime = '".date('Ymd',time())."'";
  334. $number = $this->input->post('number',true);
  335. $waybill = $this->input->post('waybill',true);
  336. $id = $this->input->post('id',true);
  337. $type = $this->input->post('type',true);
  338. $express = $this->input->post('express',true);
  339. $time = $this->input->post('time',true);
  340. $time = strtotime($time);
  341. if($id)
  342. {
  343. if($type)
  344. {
  345. $where .= " and type = '$type'";
  346. }
  347. else
  348. {
  349. $uw = '';
  350. $u = $this->user->get_api($id);
  351. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  352. foreach ($u['warehouse'] as $v)
  353. {
  354. $uw .= " type = '$v' or";
  355. }
  356. $uw = rtrim($uw,'or');
  357. $uw = " and (".ltrim($uw,' ').")";
  358. $where .= $uw;
  359. }
  360. }
  361. if(!$number)
  362. {
  363. echo json_encode(array('msg'=>'编号不能为空!','success'=>false));exit;
  364. }
  365. if(!$waybill)
  366. {
  367. echo json_encode(array('msg'=>'运单号不能为空!','success'=>false));exit;
  368. }
  369. if(!$type)
  370. {
  371. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  372. }
  373. if(!$express)
  374. {
  375. echo json_encode(array('msg'=>'请选择需要录入的快递!','success'=>false));exit;
  376. }
  377. $nu = $this->outbound->get_number($number);
  378. if($nu)
  379. {
  380. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  381. }
  382. $wa = $this->outbound->get_waybill($waybill);
  383. if($wa)
  384. {
  385. echo json_encode(array('msg'=>'错误!此运单号'.date('Ymd',$wa['time']).'已录入!','success'=>false));exit;
  386. }
  387. $sex = $this->express->read($express);
  388. $ex = array('DHL'=>10,'FEDEX'=>12,'FEDEXGF'=>12,'UPS'=>18,'GES'=>17,'TNT'=>9,'ARAMEX'=>11,'EMS_ZX_ZX_US'=>13);
  389. if(isset($ex[$sex['printcode']]))
  390. {
  391. if(strlen($waybill) != $ex[$sex['printcode']])
  392. {
  393. echo json_encode(array('msg'=>'运单号错误,此单请重新录入运单号!','success'=>false));exit;
  394. }
  395. }
  396. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'waybill'=>$waybill,'express'=>$express,'gtime'=>date('Ymd',$time),'time'=>$time+1)))
  397. {
  398. echo json_encode(array('msg'=>'添加成功!','success'=>true));exit;
  399. }
  400. }
  401. }
  402. public function _del()
  403. {
  404. $post = $this->input->post(NULL, TRUE);
  405. if(isset($post['delarr']))
  406. {
  407. $id_arr = $this->input->post('delarr');
  408. $id_arr = explode(',',rtrim($id_arr,','));
  409. if(!$id_arr)
  410. {
  411. echo json_encode(array('msg'=>'未选择需要删除的内容!','success'=>false));exit;
  412. }
  413. //循环删除记录
  414. $a=0;
  415. foreach ($id_arr as $v)
  416. {
  417. if($this->outbound->remove($v))
  418. {
  419. $a++;
  420. }
  421. }
  422. if($a == count($id_arr))
  423. {
  424. $data = $this->outbound->find_count("gtime = '".date('Ymd',time())."'");
  425. echo json_encode(array('del'=>$id_arr,'data'=>$data,'msg'=>'删除成功!','success'=>true));
  426. }
  427. else
  428. {
  429. echo json_encode(array('del'=>$id_arr,'msg'=>'部分记录删除失败,请查询确认!','success'=>true));
  430. }
  431. }
  432. }
  433. public function _ex()
  434. {
  435. }
  436. }