Systembound.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. header("Access-Control-Allow-Origin: *");
  3. class Systembound 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_shop','shop');
  11. $this->load->_model('Model_warehouse','warehouse');
  12. $this->load->_model('Model_fullorder','fullorder');
  13. $this->load->_model('Model_fullordertt','fullordertt');
  14. $this->load->_model('Model_fullordersmt','fullordersmt');
  15. }
  16. //定义方法的调用规则 获取URI第二段值
  17. public function _remap($arg,$arg_array)
  18. {
  19. if($arg == 'data')
  20. {
  21. $this->_data();
  22. }
  23. else if($arg == 'out')
  24. {
  25. $this->_out();
  26. }
  27. else if($arg == 'del')
  28. {
  29. $this->_del();
  30. }
  31. else if($arg == 'add')
  32. {
  33. $this->_add();
  34. }
  35. else if($arg == 'excel')
  36. {
  37. $this->_excel();
  38. }
  39. else
  40. {
  41. $this->_index();
  42. }
  43. }
  44. public function _index()
  45. {
  46. if(isset($_SESSION['api']))
  47. {
  48. $user = $this->user->get_api($_SESSION['api']);
  49. $usp = $user;
  50. $fgshop = "";$sid = "";$wid="";$wtype="";
  51. $usersp = explode('|',trim($user['shop'],'|'));
  52. $userwh = explode('|',trim($user['warehouse'],'|'));
  53. foreach ($usersp as $value)
  54. {
  55. $fgshop .= " shop = ".$value." or";
  56. $sid .= " id = ".$value." or";
  57. }
  58. foreach ($userwh as $value)
  59. {
  60. $wid .= " id = ".$value." or";
  61. $wtype .= " type = ".$value." or";
  62. }
  63. }
  64. if(isset($_SESSION['api']))
  65. {
  66. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  67. $warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");
  68. $this->data['wlshop'] = $wlshop;
  69. $this->data['warehouse'] = $warehouse;
  70. $this->data['vip'] = $user['vip'];
  71. }
  72. $this->_Template('systembound',$this->data);
  73. }
  74. public function _data()
  75. {
  76. $post = $this->input->post(NULL, TRUE);
  77. if(isset($post['page']))
  78. {
  79. $api = $this->input->post('api',true);
  80. $page = $this->input->post('page',true);
  81. $perpage = $this->input->post('perpage',true);
  82. $number = $this->input->post('number',true);
  83. $waybill = $this->input->post('waybill',true);
  84. $express = $this->input->post('express',true);
  85. $type = $this->input->post('type',true);
  86. $timetk = $this->input->post('timetk',true);
  87. $timetj = $this->input->post('timetj',true);
  88. $timetk = strtotime($timetk);
  89. $timetj = strtotime($timetj);
  90. $where = "type != 0";
  91. if(isset($_SESSION['api']))
  92. {
  93. if($type)
  94. {
  95. $where .= " and type = '$type'";
  96. }
  97. else
  98. {
  99. $uw = '';
  100. $u = $this->user->get_api($_SESSION['api']);
  101. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  102. foreach ($u['warehouse'] as $v)
  103. {
  104. $uw .= " type = '$v' or";
  105. }
  106. $uw = rtrim($uw,'or');
  107. $uw = " and (".ltrim($uw,' ').")";
  108. $where .= $uw;
  109. }
  110. }
  111. if($timetk && $timetj)
  112. {
  113. $where .= " and time > '$timetk' and time < '$timetj'";
  114. }
  115. if($number)
  116. {
  117. $where .= " and number = '$number'";
  118. }
  119. if($waybill)
  120. {
  121. $where .= " and waybill = '$waybill'";
  122. }
  123. if($express)
  124. {
  125. $where .= " and express = '$express'";
  126. }
  127. //数据排序
  128. $order_str = "id desc";
  129. if(empty($page))
  130. {
  131. $start = 0;
  132. $perpage = 1;
  133. }
  134. else
  135. {
  136. $start = ($page - 1)*$perpage;
  137. }
  138. //取得信息列表
  139. $info_list = $this->outbound->find_all($where,'id,type,express,number,waybill,time',$order_str,$start,$perpage);
  140. //格式化数据
  141. foreach ($info_list as $key=>$value)
  142. {
  143. if($value['waybill'] == '0')
  144. {
  145. $info_list[$key]['waybill'] = "无";
  146. }
  147. if($value['express'] == '0')
  148. {
  149. $info_list[$key]['express'] = "无";
  150. }
  151. else
  152. {
  153. $express = $this->express->read($value['express']);
  154. $info_list[$key]['express'] = $express['servicename'];
  155. }
  156. $warehouse = $this->warehouse->read($value['type']);
  157. $info_list[$key]['type'] = $warehouse['title'];
  158. $info_list[$key]['time'] = '<em class="t">'.date('Y-m-d H:i:s',$value['time']).'</em>';
  159. }
  160. $ex = array();
  161. $ed = $this->outbound->find_all($where,'express');
  162. foreach ($ed as $key=>$value)
  163. {
  164. if(isset($ex[$value['express']]))
  165. {
  166. $ex[$value['express']] += 1;
  167. }
  168. else
  169. {
  170. $ex[$value['express']] = 1;
  171. }
  172. }
  173. $exdata = '';
  174. foreach ($ex as $k=>$v)
  175. {
  176. $e = $this->express->read($k);
  177. $exdata .= "<li>".$e['servicename'].":".$v."单</li>";
  178. }
  179. $datacount = $this->outbound->find_count($where." and gtime = '".date('Ymd',time())."'");
  180. $total = $this->outbound->find_count($where);
  181. $pagenum = ceil($total/$perpage);
  182. $over = $total-($start+$perpage);
  183. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'datacount'=>$datacount,'exdata'=>$exdata);
  184. echo json_encode($rows);exit;
  185. }
  186. }
  187. public function _out()
  188. {
  189. $post = $this->input->post(NULL, TRUE);
  190. if(isset($post['number']))
  191. {
  192. $where = "gtime = '".date('Ymd',time())."'";
  193. $number = $this->input->post('number',true);
  194. $type = $this->input->post('type',true);
  195. $express = $this->input->post('express',true);
  196. if($_SESSION['api'])
  197. {
  198. if($type)
  199. {
  200. $where .= " and type = '$type'";
  201. }
  202. else
  203. {
  204. $uw = '';
  205. $u = $this->user->get_api($_SESSION['api']);
  206. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  207. foreach ($u['warehouse'] as $v)
  208. {
  209. $uw .= " type = '$v' or";
  210. }
  211. $uw = rtrim($uw,'or');
  212. $uw = " and (".ltrim($uw,' ').")";
  213. $where .= $uw;
  214. }
  215. }
  216. if(!$number)
  217. {
  218. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  219. }
  220. if(!$type)
  221. {
  222. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  223. }
  224. if(!$express)
  225. {
  226. echo json_encode(array('msg'=>'请选择需要录入的快递!','success'=>false));exit;
  227. }
  228. $sex = $this->express->read($express);
  229. if(stripos($number,'-') === false)
  230. {
  231. if(substr($number,0,3) == '788' && substr($number,-4,4) == '0430')//Fedex联邦
  232. {
  233. $number = substr($number,0,12);
  234. }
  235. if(strlen($number) == '34')//联邦杭州超长运单截取
  236. {
  237. $number = substr($number,22,12);
  238. }
  239. /**
  240. $ex = array('DHL'=>10,'FEDEX'=>12,'FEDEXGF'=>12,'UPS'=>18,'GES'=>17,'TNT'=>9,'ARAMEX'=>11,'EMS_ZX_ZX_US'=>13);
  241. if(isset($ex[$sex['printcode']]))
  242. {
  243. if(strlen($number) != $ex[$sex['printcode']])
  244. {
  245. echo json_encode(array('msg'=>'运单号错误,此单请重新录入运单号!','success'=>false));exit;
  246. }
  247. }
  248. **/
  249. if(strlen($number) == 12 && $sex['printcode'] != 'FEDEX' && $sex['printcode'] != 'FEDEXGF')
  250. {
  251. echo json_encode(array('msg'=>'运单号和快递类型不符!F','success'=>false));exit;
  252. }
  253. if(strlen($number) == 10 && $sex['printcode'] != 'DHL' && $sex['printcode'] != 'DHLUSA')
  254. {
  255. echo json_encode(array('msg'=>'运单号和快递类型不符!D','success'=>false));exit;
  256. }
  257. if(strlen($number) == 18 && $sex['printcode'] != 'UPS')
  258. {
  259. echo json_encode(array('msg'=>'运单号和快递类型不符!U','success'=>false));exit;
  260. }
  261. $yd = $this->fullorder->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  262. if(isset($yd[0]['number']))
  263. {
  264. $number = $yd[0]['number'];
  265. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  266. {
  267. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  268. }
  269. }
  270. else
  271. {
  272. $yd = $this->fullordersmt->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  273. if(isset($yd[0]['number']))
  274. {
  275. $number = $yd[0]['number'];
  276. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  277. {
  278. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  279. }
  280. }
  281. else
  282. {
  283. $yd = $this->fullordertt->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  284. if(isset($yd[0]['number']))
  285. {
  286. $number = $yd[0]['number'];
  287. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  288. {
  289. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  290. }
  291. }
  292. else
  293. {
  294. echo json_encode(array('msg'=>'系统中未查到此运单,请确认!','success'=>false));exit;
  295. }
  296. }
  297. }
  298. /**
  299. if($yd[0]['printtype'] != 1)
  300. {
  301. echo json_encode(array('msg'=>'请扫描正确的运单号!','success'=>false));exit;
  302. }
  303. **/
  304. $nu = $this->outbound->get_number($number);
  305. if($nu)
  306. {
  307. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  308. }
  309. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'express'=>$express,'gtime'=>date('Ymd',time()),'time'=>time())))
  310. {
  311. $data = $this->outbound->find_count($where);
  312. echo json_encode(array('msg'=>$data,'music'=>'1','success'=>true));exit;
  313. }
  314. else
  315. {
  316. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  317. }
  318. }
  319. else
  320. {
  321. $dd = $this->fullorder->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  322. if(isset($dd[0]['number']))
  323. {
  324. if($dd[0]['express'] != $express)
  325. {
  326. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  327. }
  328. }
  329. else
  330. {
  331. $dd = $this->fullordersmt->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  332. if(isset($dd[0]['number']))
  333. {
  334. $number = $dd[0]['number'];
  335. if($dd[0]['express'] != $express)
  336. {
  337. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  338. }
  339. }
  340. else
  341. {
  342. $dd = $this->fullordertt->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  343. if(isset($dd[0]['number']))
  344. {
  345. $number = $dd[0]['number'];
  346. if($dd[0]['express'] != $express)
  347. {
  348. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  349. }
  350. }
  351. else
  352. {
  353. echo json_encode(array('msg'=>'系统中未查到此编号,请确认!','success'=>false));exit;
  354. }
  355. }
  356. }
  357. if($dd[0]['printtype'] != 2)
  358. {
  359. echo json_encode(array('msg'=>'请扫描正确的条码!','success'=>false));exit;
  360. }
  361. $nu = $this->outbound->get_number($number);
  362. if($nu)
  363. {
  364. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  365. }
  366. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'express'=>$express,'gtime'=>date('Ymd',time()),'time'=>time())))
  367. {
  368. $data = $this->outbound->find_count($where);
  369. echo json_encode(array('msg'=>$data,'music'=>'1','success'=>true));exit;
  370. }
  371. else
  372. {
  373. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  374. }
  375. }
  376. }
  377. }
  378. public function _outxxxxxx()
  379. {
  380. $post = $this->input->post(NULL, TRUE);
  381. if(isset($post['number']))
  382. {
  383. $where = "gtime = '".date('Ymd',time())."'";
  384. $number = $this->input->post('number',true);
  385. $id = $this->input->post('id',true);
  386. $type = $this->input->post('type',true);
  387. $express = $this->input->post('express',true);
  388. if($id)
  389. {
  390. if($type)
  391. {
  392. $where .= " and type = '$type'";
  393. }
  394. else
  395. {
  396. $uw = '';
  397. $u = $this->user->get_api($id);
  398. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  399. foreach ($u['warehouse'] as $v)
  400. {
  401. $uw .= " type = '$v' or";
  402. }
  403. $uw = rtrim($uw,'or');
  404. $uw = " and (".ltrim($uw,' ').")";
  405. $where .= $uw;
  406. }
  407. }
  408. if(!$number)
  409. {
  410. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  411. }
  412. if(!$type)
  413. {
  414. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  415. }
  416. if(!$express)
  417. {
  418. echo json_encode(array('msg'=>'请选择需要录入的快递!','success'=>false));exit;
  419. }
  420. $nu = $this->outbound->get_number($number);
  421. if($nu)
  422. {
  423. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  424. }
  425. $wa = $this->outbound->get_waybill($number);
  426. if($wa)
  427. {
  428. echo json_encode(array('msg'=>'错误!此运单号'.date('Ymd',$wa['time']).'已录入!','success'=>false));exit;
  429. }
  430. $jd = $this->outbound->find_all($where,'*','id desc');
  431. if(!isset($jd[0]) || $jd[0]['waybill'] != '')
  432. {
  433. $pd = explode('-',$number);
  434. if(!isset($pd[1]) || !isset($pd[2]))
  435. {
  436. echo json_encode(array('msg'=>'编号不正确,请重试!','success'=>false));exit;
  437. }
  438. if(strlen($pd[1]) == '5' && strlen($pd[2]) == '3')
  439. {
  440. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'express'=>$express,'gtime'=>date('Ymd',time()),'time'=>time())))
  441. {
  442. $data = $this->outbound->find_count($where);
  443. echo json_encode(array('msg'=>$data,'music'=>'1','success'=>true));exit;
  444. }
  445. else
  446. {
  447. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  448. }
  449. }
  450. else
  451. {
  452. echo json_encode(array('msg'=>'编号不正确!','success'=>false));exit;
  453. }
  454. }
  455. else
  456. {
  457. if(stripos($number,'-') !== false)
  458. {
  459. echo json_encode(array('msg'=>'请扫描'.$jd[0]['number'].'对应的运单号!','success'=>false));exit;
  460. }
  461. if(substr($number,0,3) == '788' && substr($number,-4,4) == '0430')//Fedex联邦
  462. {
  463. $number = substr($number,0,12);
  464. }
  465. if(strlen($number) == '34')//联邦杭州超长运单截取
  466. {
  467. $number = substr($number,22,12);
  468. }
  469. $sex = $this->express->read($express);
  470. $ex = array('DHL'=>10,'FEDEX'=>12,'FEDEXGF'=>12,'UPS'=>18,'GES'=>17,'TNT'=>9,'ARAMEX'=>11,'EMS_ZX_ZX_US'=>13);
  471. if(isset($ex[$sex['printcode']]))
  472. {
  473. if(strlen($number) != $ex[$sex['printcode']])
  474. {
  475. echo json_encode(array('msg'=>'运单号错误,此单请重新录入运单号!','success'=>false));exit;
  476. }
  477. }
  478. if($this->outbound->save(array('waybill'=>$number),$jd[0]['id']))
  479. {
  480. $data = $this->outbound->find_count($where);
  481. echo json_encode(array('msg'=>$data,'music'=>'1','success'=>true));exit;
  482. }
  483. else
  484. {
  485. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  486. }
  487. }
  488. }
  489. }
  490. public function _excel()
  491. {
  492. if(isset($_GET['fexcel']))
  493. {
  494. $timetk = $this->input->get('timetk',true);
  495. $timetj = $this->input->get('timetj',true);
  496. $library = $this->input->get('library',true);
  497. $type = $this->input->get('type',true);
  498. $number = $this->input->get('number',true);
  499. $waybill = $this->input->get('waybill',true);
  500. $express = $this->input->get('express',true);
  501. $timetk = strtotime($timetk);
  502. $timetj = strtotime($timetj);
  503. $where = "type != 0";
  504. if($timetk && $timetj)
  505. {
  506. $where .= " and time > '$timetk' and time < '$timetj'";
  507. }
  508. if(isset($_SESSION['api']))
  509. {
  510. if($type)
  511. {
  512. $where .= " and type = '$type'";
  513. }
  514. else
  515. {
  516. $uw = '';
  517. $u = $this->user->get_api($_SESSION['api']);
  518. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  519. foreach ($u['warehouse'] as $v)
  520. {
  521. $uw .= " type = '$v' or";
  522. }
  523. $uw = rtrim($uw,'or');
  524. $uw = " and (".ltrim($uw,' ').")";
  525. $where .= $uw;
  526. }
  527. }
  528. else
  529. {
  530. echo json_encode(array('msg'=>'导出失败,请重新登陆!','success'=>false));exit;
  531. }
  532. if($number)
  533. {
  534. $where .= " and number = '$number'";
  535. }
  536. if($waybill)
  537. {
  538. $where .= " and waybill = '$waybill'";
  539. }
  540. if($express)
  541. {
  542. $where .= " and express = '$express'";
  543. }
  544. $data = array();
  545. $datafy = array();
  546. $j = 0;
  547. $info_list = $this->outbound->find_all($where,'number,waybill');
  548. foreach ($info_list as $key=>$value)
  549. {
  550. $datafy[] = array($value['number'],$value['waybill']);
  551. if($j == $library-1)
  552. {
  553. $data[] = $datafy;
  554. $j = 0;$datafy = array();
  555. }
  556. else
  557. {
  558. $j++;
  559. }
  560. }
  561. $data[] = $datafy;
  562. //格式化数据
  563. $i = 0;$cpexcel = array();
  564. $title = date('Ymd',time())."发货统计信息"; $td = '';
  565. for($i=0;$i<ceil(count($info_list)/$library);$i++)
  566. {
  567. $td .= "<td>组".($i+1)."</td><td></td>";
  568. }
  569. $titlename = "<table border=1>
  570. <tr>
  571. ".$td."
  572. </tr>
  573. </table>";
  574. $filename = $title.".xls";
  575. $this->excel->get_fz6($data,$titlename,$filename);
  576. }
  577. }
  578. public function _add()
  579. {
  580. $post = $this->input->post(NULL, TRUE);
  581. if(isset($post['number']))
  582. {
  583. $where = "gtime = '".date('Ymd',time())."'";
  584. $number = $this->input->post('number',true);
  585. //$waybill = $this->input->post('waybill',true);
  586. $id = $this->input->post('id',true);
  587. $type = $this->input->post('type',true);
  588. $express = $this->input->post('express',true);
  589. $time = $this->input->post('time',true);
  590. $time = strtotime($time);
  591. if($id)
  592. {
  593. if($type)
  594. {
  595. $where .= " and type = '$type'";
  596. }
  597. else
  598. {
  599. $uw = '';
  600. $u = $this->user->get_api($id);
  601. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  602. foreach ($u['warehouse'] as $v)
  603. {
  604. $uw .= " type = '$v' or";
  605. }
  606. $uw = rtrim($uw,'or');
  607. $uw = " and (".ltrim($uw,' ').")";
  608. $where .= $uw;
  609. }
  610. }
  611. /**
  612. if(!$number)
  613. {
  614. echo json_encode(array('msg'=>'编号不能为空!','success'=>false));exit;
  615. }
  616. if(!$waybill)
  617. {
  618. //echo json_encode(array('msg'=>'运单号不能为空!','success'=>false));exit;
  619. }
  620. if(!$type)
  621. {
  622. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  623. }
  624. if(!$express)
  625. {
  626. echo json_encode(array('msg'=>'请选择需要录入的快递!','success'=>false));exit;
  627. }
  628. $nu = $this->outbound->get_number($number);
  629. if($nu)
  630. {
  631. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  632. }
  633. if($waybill)
  634. {
  635. $wa = $this->outbound->get_waybill($waybill);
  636. if($wa)
  637. {
  638. echo json_encode(array('msg'=>'错误!此运单号'.date('Ymd',$wa['time']).'已录入!','success'=>false));exit;
  639. }
  640. $sex = $this->express->read($express);
  641. $ex = array('DHL'=>10,'FEDEX'=>12,'FEDEXGF'=>12,'UPS'=>18,'GES'=>17,'TNT'=>9,'ARAMEX'=>11,'EMS_ZX_ZX_US'=>13);
  642. if(isset($ex[$sex['printcode']]))
  643. {
  644. if(strlen($waybill) != $ex[$sex['printcode']])
  645. {
  646. echo json_encode(array('msg'=>'运单号错误,此单请重新录入运单号!','success'=>false));exit;
  647. }
  648. }
  649. }
  650. **/
  651. if(!$number)
  652. {
  653. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  654. }
  655. if(!$type)
  656. {
  657. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  658. }
  659. if(!$express)
  660. {
  661. echo json_encode(array('msg'=>'请选择需要录入的快递!','success'=>false));exit;
  662. }
  663. $sex = $this->express->read($express);
  664. if(stripos($number,'-') === false)
  665. {
  666. if(substr($number,0,3) == '788' && substr($number,-4,4) == '0430')//Fedex联邦
  667. {
  668. $number = substr($number,0,12);
  669. }
  670. if(strlen($number) == '34')//联邦杭州超长运单截取
  671. {
  672. $number = substr($number,22,12);
  673. }
  674. /**
  675. $ex = array('DHL'=>10,'FEDEX'=>12,'FEDEXGF'=>12,'UPS'=>18,'GES'=>17,'TNT'=>9,'ARAMEX'=>11,'EMS_ZX_ZX_US'=>13);
  676. if(isset($ex[$sex['printcode']]))
  677. {
  678. if(strlen($number) != $ex[$sex['printcode']])
  679. {
  680. echo json_encode(array('msg'=>'运单号错误,此单请重新录入运单号!','success'=>false));exit;
  681. }
  682. }
  683. **/
  684. if(strlen($number) == 12 && $sex['printcode'] != 'FEDEX' && $sex['printcode'] != 'FEDEXGF')
  685. {
  686. echo json_encode(array('msg'=>'运单号和快递类型不符!F','success'=>false));exit;
  687. }
  688. if(strlen($number) == 10 && $sex['printcode'] != 'DHL' && $sex['printcode'] != 'DHLUSA')
  689. {
  690. echo json_encode(array('msg'=>'运单号和快递类型不符!D','success'=>false));exit;
  691. }
  692. if(strlen($number) == 18 && $sex['printcode'] != 'UPS')
  693. {
  694. echo json_encode(array('msg'=>'运单号和快递类型不符!U','success'=>false));exit;
  695. }
  696. $yd = $this->fullorder->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  697. if(isset($yd[0]['number']))
  698. {
  699. $number = $yd[0]['number'];
  700. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  701. {
  702. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  703. }
  704. }
  705. else
  706. {
  707. $yd = $this->fullordersmt->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  708. if(isset($yd[0]['number']))
  709. {
  710. $number = $yd[0]['number'];
  711. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  712. {
  713. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  714. }
  715. if($yd[0]['express'] != 24 && $yd[0]['express'] == 31)
  716. {
  717. echo json_encode(array('msg'=>'请选择杭州联邦快递方式录入','success'=>false));exit;
  718. }
  719. }
  720. else
  721. {
  722. $yd = $this->fullordertt->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  723. if(isset($yd[0]['number']))
  724. {
  725. $number = $yd[0]['number'];
  726. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  727. {
  728. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  729. }
  730. if($yd[0]['express'] != 24 && $yd[0]['express'] == 31)
  731. {
  732. echo json_encode(array('msg'=>'请选择杭州联邦快递方式录入','success'=>false));exit;
  733. }
  734. }
  735. else
  736. {
  737. echo json_encode(array('msg'=>'系统中未查到此运单,请确认!','success'=>false));exit;
  738. }
  739. }
  740. }
  741. /**
  742. if($yd[0]['printtype'] != 1)
  743. {
  744. echo json_encode(array('msg'=>'请扫描正确的运单号!','success'=>false));exit;
  745. }
  746. **/
  747. $nu = $this->outbound->get_number($number);
  748. if($nu)
  749. {
  750. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  751. }
  752. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'express'=>$express,'gtime'=>date('Ymd',time()),'time'=>time())))
  753. {
  754. $data = $this->outbound->find_count($where);
  755. echo json_encode(array('msg'=>'提交成功,数量:'.$data,'music'=>'1','success'=>true));exit;
  756. }
  757. else
  758. {
  759. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  760. }
  761. }
  762. else
  763. {
  764. $dd = $this->fullorder->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  765. if(isset($dd[0]['number']))
  766. {
  767. if($dd[0]['express'] != $express)
  768. {
  769. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  770. }
  771. }
  772. else
  773. {
  774. $dd = $this->fullordersmt->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  775. if(isset($dd[0]['number']))
  776. {
  777. $number = $dd[0]['number'];
  778. if($dd[0]['express'] != $express)
  779. {
  780. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  781. }
  782. }
  783. else
  784. {
  785. $dd = $this->fullordertt->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  786. if(isset($dd[0]['number']))
  787. {
  788. $number = $dd[0]['number'];
  789. if($dd[0]['express'] != $express)
  790. {
  791. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  792. }
  793. }
  794. else
  795. {
  796. echo json_encode(array('msg'=>'系统中未查到此编号,请确认!','success'=>false));exit;
  797. }
  798. }
  799. }
  800. if($dd[0]['printtype'] != 2)
  801. {
  802. echo json_encode(array('msg'=>'请扫描正确的条码!','success'=>false));exit;
  803. }
  804. $nu = $this->outbound->get_number($number);
  805. if($nu)
  806. {
  807. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  808. }
  809. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'express'=>$express,'gtime'=>date('Ymd',time()),'time'=>time())))
  810. {
  811. $data = $this->outbound->find_count($where);
  812. echo json_encode(array('msg'=>'添加成功!','success'=>true));exit;
  813. }
  814. else
  815. {
  816. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  817. }
  818. }
  819. /**
  820. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'waybill'=>$waybill,'express'=>$express,'gtime'=>date('Ymd',$time),'time'=>$time+1)))
  821. {
  822. echo json_encode(array('msg'=>'添加成功!','success'=>true));exit;
  823. }
  824. **/
  825. }
  826. }
  827. public function _del()
  828. {
  829. $post = $this->input->post(NULL, TRUE);
  830. if(isset($post['delarr']))
  831. {
  832. $id_arr = $this->input->post('delarr');
  833. $id_arr = explode(',',rtrim($id_arr,','));
  834. if(!$id_arr)
  835. {
  836. echo json_encode(array('msg'=>'未选择需要删除的内容!','success'=>false));exit;
  837. }
  838. //循环删除记录
  839. $a=0;
  840. foreach ($id_arr as $v)
  841. {
  842. if($this->outbound->remove($v))
  843. {
  844. $a++;
  845. }
  846. }
  847. if($a == count($id_arr))
  848. {
  849. $data = $this->outbound->find_count("gtime = '".date('Ymd',time())."'");
  850. echo json_encode(array('del'=>$id_arr,'data'=>$data,'msg'=>'删除成功!','success'=>true));
  851. }
  852. else
  853. {
  854. echo json_encode(array('del'=>$id_arr,'msg'=>'部分记录删除失败,请查询确认!','success'=>true));
  855. }
  856. }
  857. }
  858. public function _ex()
  859. {
  860. }
  861. }