Systembound.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  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_fullorderamz','fullorderamz');
  15. $this->load->_model('Model_fullordersmt','fullordersmt');
  16. $this->load->_model('Model_fullorderxw','fullorderxw');
  17. $this->load->_model('Model_logic_order','logic_order');
  18. }
  19. //定义方法的调用规则 获取URI第二段值
  20. public function _remap($arg,$arg_array)
  21. {
  22. if($arg == 'data')
  23. {
  24. $this->_data();
  25. }
  26. else if($arg == 'out')
  27. {
  28. $this->_out();
  29. }
  30. else if($arg == 'del')
  31. {
  32. $this->_del();
  33. }
  34. else if($arg == 'add')
  35. {
  36. $this->_add();
  37. }
  38. else if($arg == 'excel')
  39. {
  40. $this->_excel();
  41. }
  42. else if($arg == 'excelhc')
  43. {
  44. //一件导出惠城和GES的全部快递
  45. $this->_excelhc();
  46. }else if($arg == 'zxdpdexcel'){
  47. $this->_zxdpdexcel();
  48. }
  49. else
  50. {
  51. $this->_index();
  52. }
  53. }
  54. public function _index()
  55. {
  56. if(isset($_SESSION['api']))
  57. {
  58. $user = $this->user->get_api($_SESSION['api']);
  59. $usp = $user;
  60. $fgshop = "";$sid = "";$wid="";$wtype="";
  61. $usersp = explode('|',trim($user['shop'],'|'));
  62. $userwh = explode('|',trim($user['warehouse'],'|'));
  63. foreach ($usersp as $value)
  64. {
  65. $fgshop .= " shop = ".$value." or";
  66. $sid .= " id = ".$value." or";
  67. }
  68. foreach ($userwh as $value)
  69. {
  70. $wid .= " id = ".$value." or";
  71. $wtype .= " type = ".$value." or";
  72. }
  73. }
  74. if(isset($_SESSION['api']))
  75. {
  76. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  77. $warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");
  78. $this->data['wlshop'] = $wlshop;
  79. $this->data['warehouse'] = $warehouse;
  80. $this->data['vip'] = $user['vip'];
  81. }
  82. $this->_Template('systembound',$this->data);
  83. }
  84. public function _data()
  85. {
  86. $post = $this->input->post(NULL, TRUE);
  87. if(isset($post['page']))
  88. {
  89. $api = $this->input->post('api',true);
  90. $page = $this->input->post('page',true);
  91. $perpage = $this->input->post('perpage',true);
  92. $number = $this->input->post('number',true);
  93. $waybill = $this->input->post('waybill',true);
  94. $express = $this->input->post('express',true);
  95. $type = $this->input->post('type',true);
  96. $timetk = $this->input->post('timetk',true);
  97. $timetj = $this->input->post('timetj',true);
  98. $timetk = strtotime($timetk);
  99. $timetj = strtotime($timetj);
  100. $where = "type != 0";
  101. if(isset($_SESSION['api']))
  102. {
  103. if($type)
  104. {
  105. $where .= " and type = '$type'";
  106. }
  107. else
  108. {
  109. $uw = '';
  110. $u = $this->user->get_api($_SESSION['api']);
  111. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  112. foreach ($u['warehouse'] as $v)
  113. {
  114. $uw .= " type = '$v' or";
  115. }
  116. $uw = rtrim($uw,'or');
  117. $uw = " and (".ltrim($uw,' ').")";
  118. $where .= $uw;
  119. }
  120. }
  121. if($timetk && $timetj)
  122. {
  123. $where .= " and time > '$timetk' and time < '$timetj'";
  124. }
  125. if($number)
  126. {
  127. $where .= " and number = '$number'";
  128. }
  129. if($waybill)
  130. {
  131. $where .= " and waybill = '$waybill'";
  132. }
  133. if($express)
  134. {
  135. $where .= " and express = '$express'";
  136. }
  137. //数据排序
  138. $order_str = "time desc";
  139. if(empty($page))
  140. {
  141. $start = 0;
  142. $perpage = 1;
  143. }
  144. else
  145. {
  146. $start = ($page - 1)*$perpage;
  147. }
  148. //取得信息列表
  149. $info_list = $this->outbound->find_all($where,'id,type,express,number,waybill,time',$order_str,$start,$perpage);
  150. //格式化数据
  151. foreach ($info_list as $key=>$value)
  152. {
  153. if($value['waybill'] == '0')
  154. {
  155. $info_list[$key]['waybill'] = "无";
  156. }
  157. if($value['express'] == '0')
  158. {
  159. $info_list[$key]['express'] = "无";
  160. }
  161. else
  162. {
  163. $express = $this->express->read($value['express']);
  164. $info_list[$key]['express'] = $express['servicename'];
  165. }
  166. $warehouse = $this->warehouse->read($value['type']);
  167. $info_list[$key]['type'] = $warehouse['title'];
  168. $info_list[$key]['time'] = '<em class="t">'.date('Y-m-d H:i:s',$value['time']).'</em>';
  169. }
  170. $ex = array();
  171. $ed = $this->outbound->find_all($where,'express');
  172. foreach ($ed as $key=>$value)
  173. {
  174. if(isset($ex[$value['express']]))
  175. {
  176. $ex[$value['express']] += 1;
  177. }
  178. else
  179. {
  180. $ex[$value['express']] = 1;
  181. }
  182. }
  183. $exdata = '';
  184. foreach ($ex as $k=>$v)
  185. {
  186. $e = $this->express->read($k);
  187. $exdata .= "<li>".$e['servicename'].":".$v."单</li>";
  188. }
  189. $datacount = $this->outbound->find_count($where." and gtime = '".date('Ymd',time())."'");
  190. $total = $this->outbound->find_count($where);
  191. $pagenum = ceil($total/$perpage);
  192. $over = $total-($start+$perpage);
  193. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'datacount'=>$datacount,'exdata'=>$exdata);
  194. echo json_encode($rows);exit;
  195. }
  196. }
  197. private function _zxdpdexcel(){
  198. if(isset($_GET['fexcel']))
  199. {
  200. $timetk = $this->input->get('timetk',true);
  201. $timetj = $this->input->get('timetj',true);
  202. $library = $this->input->get('library',true);
  203. $type = $this->input->get('type',true);
  204. $number = $this->input->get('number',true);
  205. $waybill = $this->input->get('waybill',true);
  206. $timetk = strtotime($timetk);
  207. $timetj = strtotime($timetj);
  208. $select_express = $this->input->get('select_express',true);
  209. $typename = "正鑫DPD";
  210. $cx_arr = [78,79];
  211. $ex_list = $this->express->find_all("id in (".implode(',',$cx_arr).")","id,servicename");
  212. $where = "type != 0 and express in (".implode(',',$cx_arr).")";
  213. if($timetk && $timetj)
  214. {
  215. $where .= " and time > '$timetk' and time < '$timetj'";
  216. }
  217. if(isset($_SESSION['api']))
  218. {
  219. if($type)
  220. {
  221. $where .= " and type = '$type'";
  222. }
  223. else
  224. {
  225. $uw = '';
  226. $u = $this->user->get_api($_SESSION['api']);
  227. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  228. foreach ($u['warehouse'] as $v)
  229. {
  230. $uw .= " type = '$v' or";
  231. }
  232. $uw = rtrim($uw,'or');
  233. $uw = " and (".ltrim($uw,' ').")";
  234. $where .= $uw;
  235. }
  236. }
  237. else
  238. {
  239. echo json_encode(array('msg'=>'导出失败,请重新登陆!','success'=>false));exit;
  240. }
  241. if($number)
  242. {
  243. $where .= " and number = '$number'";
  244. }
  245. if($waybill)
  246. {
  247. $where .= " and waybill = '$waybill'";
  248. }
  249. $data = array();
  250. $datafy = array();
  251. $j = 0;
  252. $info_list = $this->outbound->find_all($where,'number,waybill,express','time asc');
  253. $final_list= [
  254. ];
  255. foreach($cx_arr as $v){
  256. $final_list[$v] = [];
  257. }
  258. foreach ($info_list as $key=>$value)
  259. {
  260. if(isset($final_list[$value['express']])){
  261. $orderinfo = $this->logic_order->getInfo('number = "'.$value['number'].'"');
  262. $weight = 0;
  263. if(!empty($orderinfo)){
  264. $weight = $orderinfo['weight'];
  265. }
  266. $final_list[$value['express']][] = [
  267. $value['number'],
  268. $value['waybill'],
  269. $weight
  270. ];
  271. }
  272. }
  273. $data[] = $datafy;
  274. //格式化数据
  275. $i = 0;$cpexcel = array();
  276. $title = date('Ymd',time()).$typename."发货统计信息"; $td = '';
  277. $td = "";
  278. $count = 0;
  279. foreach($ex_list as $v){
  280. $num = count($final_list[$v['id']]);
  281. if($num > $count){
  282. $count = $num;
  283. }
  284. $td .= "<td>".$v['servicename']."</td><td>总数(".$num.")</td><td>重量</td>";
  285. }
  286. foreach($final_list as $k=>$v){
  287. for($i=0;$i < $count ;$i++){
  288. if(!isset($final_list[$k][$i])){
  289. $final_list[$k][$i] = [
  290. " "," ",""
  291. ];
  292. }
  293. }
  294. }
  295. $titlename = "<table border=1>
  296. <tr>
  297. ".$td."
  298. </tr>
  299. </table>";
  300. $filename = $title.".xls";
  301. $this->excel->get_fz6($final_list,$titlename,$filename);
  302. }
  303. }
  304. public function _excel()
  305. {
  306. if(isset($_GET['fexcel']))
  307. {
  308. $timetk = $this->input->get('timetk',true);
  309. $timetj = $this->input->get('timetj',true);
  310. $library = $this->input->get('library',true);
  311. $type = $this->input->get('type',true);
  312. $number = $this->input->get('number',true);
  313. $waybill = $this->input->get('waybill',true);
  314. $express = $this->input->get('express',true);
  315. $timetk = strtotime($timetk);
  316. $timetj = strtotime($timetj);
  317. $where = "type != 0";
  318. if($timetk && $timetj)
  319. {
  320. $where .= " and time > '$timetk' and time < '$timetj'";
  321. }
  322. if(isset($_SESSION['api']))
  323. {
  324. if($type)
  325. {
  326. $where .= " and type = '$type'";
  327. }
  328. else
  329. {
  330. $uw = '';
  331. $u = $this->user->get_api($_SESSION['api']);
  332. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  333. foreach ($u['warehouse'] as $v)
  334. {
  335. $uw .= " type = '$v' or";
  336. }
  337. $uw = rtrim($uw,'or');
  338. $uw = " and (".ltrim($uw,' ').")";
  339. $where .= $uw;
  340. }
  341. }
  342. else
  343. {
  344. echo json_encode(array('msg'=>'导出失败,请重新登陆!','success'=>false));exit;
  345. }
  346. if($number)
  347. {
  348. $where .= " and number = '$number'";
  349. }
  350. if($waybill)
  351. {
  352. $where .= " and waybill = '$waybill'";
  353. }
  354. if($express)
  355. {
  356. $where .= " and express = '$express'";
  357. }
  358. $data = array();
  359. $datafy = array();
  360. $j = 0;
  361. $info_list = $this->outbound->find_all($where,'number,waybill','time asc');
  362. foreach ($info_list as $key=>$value)
  363. {
  364. $datafy[] = array($value['number'],$value['waybill']);
  365. if($j == $library-1)
  366. {
  367. $data[] = $datafy;
  368. $j = 0;$datafy = array();
  369. }
  370. else
  371. {
  372. $j++;
  373. }
  374. }
  375. $data[] = $datafy;
  376. //格式化数据
  377. $i = 0;$cpexcel = array();
  378. $title = date('Ymd',time())."发货统计信息"; $td = '';
  379. for($i=0;$i<ceil(count($info_list)/$library);$i++)
  380. {
  381. $td .= "<td>组".($i+1)."</td><td></td>";
  382. }
  383. $titlename = "<table border=1>
  384. <tr>
  385. ".$td."
  386. </tr>
  387. </table>";
  388. $filename = $title.".xls";
  389. $this->excel->get_fz6($data,$titlename,$filename);
  390. }
  391. }
  392. //一件导出惠城的全部快递
  393. public function _excelhc()
  394. {
  395. if(isset($_GET['fexcel']))
  396. {
  397. $timetk = $this->input->get('timetk',true);
  398. $timetj = $this->input->get('timetj',true);
  399. $library = $this->input->get('library',true);
  400. $type = $this->input->get('type',true);
  401. $number = $this->input->get('number',true);
  402. $waybill = $this->input->get('waybill',true);
  403. $timetk = strtotime($timetk);
  404. $timetj = strtotime($timetj);
  405. $select_express = $this->input->get('select_express',true);
  406. if($select_express == 'ozyt'){
  407. //云途(欧洲) 云途(欧洲)-带保险
  408. $cx_arr = [66,67];//需要的查询数据
  409. $typename = "云途(欧洲)";
  410. }else{
  411. //GES 7 惠城联邦 50 惠城GES 51 惠城安迈世 51 惠城DHL 69 惠城usps 73
  412. $cx_arr = [7,50,51,52,69,73];//需要的查询数据
  413. $typename = "惠程";
  414. }
  415. $ex_list = $this->express->find_all("id in (".implode(',',$cx_arr).")","id,servicename");
  416. $where = "type != 0 and express in (".implode(',',$cx_arr).")";
  417. if($timetk && $timetj)
  418. {
  419. $where .= " and time > '$timetk' and time < '$timetj'";
  420. }
  421. if(isset($_SESSION['api']))
  422. {
  423. if($type)
  424. {
  425. $where .= " and type = '$type'";
  426. }
  427. else
  428. {
  429. $uw = '';
  430. $u = $this->user->get_api($_SESSION['api']);
  431. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  432. foreach ($u['warehouse'] as $v)
  433. {
  434. $uw .= " type = '$v' or";
  435. }
  436. $uw = rtrim($uw,'or');
  437. $uw = " and (".ltrim($uw,' ').")";
  438. $where .= $uw;
  439. }
  440. }
  441. else
  442. {
  443. echo json_encode(array('msg'=>'导出失败,请重新登陆!','success'=>false));exit;
  444. }
  445. if($number)
  446. {
  447. $where .= " and number = '$number'";
  448. }
  449. if($waybill)
  450. {
  451. $where .= " and waybill = '$waybill'";
  452. }
  453. $data = array();
  454. $datafy = array();
  455. $j = 0;
  456. $info_list = $this->outbound->find_all($where,'number,waybill,express','time asc');
  457. $final_list= [
  458. ];
  459. foreach($cx_arr as $v){
  460. $final_list[$v] = [];
  461. }
  462. foreach ($info_list as $key=>$value)
  463. {
  464. if(isset($final_list[$value['express']])){
  465. $final_list[$value['express']][] = [
  466. $value['number'],
  467. $value['waybill'],
  468. ];
  469. }
  470. }
  471. $data[] = $datafy;
  472. //格式化数据
  473. $i = 0;$cpexcel = array();
  474. $title = date('Ymd',time()).$typename."发货统计信息"; $td = '';
  475. $td = "";
  476. $count = 0;
  477. foreach($ex_list as $v){
  478. $num = count($final_list[$v['id']]);
  479. if($num > $count){
  480. $count = $num;
  481. }
  482. $td .= "<td>".$v['servicename']."</td><td>".$num."</td>";
  483. }
  484. foreach($final_list as $k=>$v){
  485. for($i=0;$i < $count ;$i++){
  486. if(!isset($final_list[$k][$i])){
  487. $final_list[$k][$i] = [
  488. " "," "
  489. ];
  490. }
  491. }
  492. }
  493. $titlename = "<table border=1>
  494. <tr>
  495. ".$td."
  496. </tr>
  497. </table>";
  498. $filename = $title.".xls";
  499. $this->excel->get_fz6($final_list,$titlename,$filename);
  500. }
  501. }
  502. public function _add()
  503. {
  504. $post = $this->input->post(NULL, TRUE);
  505. if(isset($post['number']))
  506. {
  507. $where = "gtime = '".date('Ymd',time())."'";
  508. $number = $this->input->post('number',true);
  509. //$waybill = $this->input->post('waybill',true);
  510. $id = $this->input->post('id',true);
  511. $type = $this->input->post('type',true);
  512. $express = $this->input->post('express',true);
  513. $time = $this->input->post('time',true);
  514. if($time)
  515. {
  516. $time = strtotime($time);
  517. }
  518. else
  519. {
  520. $time = time();
  521. }
  522. if($id)
  523. {
  524. if($type)
  525. {
  526. $where .= " and type = '$type'";
  527. }
  528. else
  529. {
  530. $uw = '';
  531. $u = $this->user->get_api($id);
  532. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  533. foreach ($u['warehouse'] as $v)
  534. {
  535. $uw .= " type = '$v' or";
  536. }
  537. $uw = rtrim($uw,'or');
  538. $uw = " and (".ltrim($uw,' ').")";
  539. $where .= $uw;
  540. }
  541. }
  542. /**
  543. if(!$number)
  544. {
  545. echo json_encode(array('msg'=>'编号不能为空!','success'=>false));exit;
  546. }
  547. if(!$waybill)
  548. {
  549. //echo json_encode(array('msg'=>'运单号不能为空!','success'=>false));exit;
  550. }
  551. if(!$type)
  552. {
  553. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  554. }
  555. if(!$express)
  556. {
  557. echo json_encode(array('msg'=>'请选择需要录入的快递!','success'=>false));exit;
  558. }
  559. $nu = $this->outbound->get_number($number);
  560. if($nu)
  561. {
  562. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  563. }
  564. if($waybill)
  565. {
  566. $wa = $this->outbound->get_waybill($waybill);
  567. if($wa)
  568. {
  569. echo json_encode(array('msg'=>'错误!此运单号'.date('Ymd',$wa['time']).'已录入!','success'=>false));exit;
  570. }
  571. $sex = $this->express->read($express);
  572. $ex = array('DHL'=>10,'FEDEX'=>12,'FEDEXGF'=>12,'UPS'=>18,'GES'=>17,'TNT'=>9,'ARAMEX'=>11,'EMS_ZX_ZX_US'=>13);
  573. if(isset($ex[$sex['printcode']]))
  574. {
  575. if(strlen($waybill) != $ex[$sex['printcode']])
  576. {
  577. echo json_encode(array('msg'=>'运单号错误,此单请重新录入运单号!','success'=>false));exit;
  578. }
  579. }
  580. }
  581. **/
  582. if(!$number)
  583. {
  584. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  585. }
  586. if(!$type)
  587. {
  588. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  589. }
  590. if(!$express)
  591. {
  592. echo json_encode(array('msg'=>'请选择需要录入的快递!','success'=>false));exit;
  593. }
  594. $sex = $this->express->read($express);
  595. if(stripos($number,'-') === false)
  596. {
  597. if(substr($number,0,3) == '788' && substr($number,-4,4) == '0430')//Fedex联邦
  598. {
  599. $number = substr($number,0,12);
  600. }
  601. if(strlen($number) == '34')//联邦杭州超长运单截取
  602. {
  603. $str = substr($number, 0,3);
  604. if($str == "420"){
  605. $number = substr($number,12);
  606. }else{
  607. $number = substr($number,22,12);
  608. }
  609. }
  610. /**
  611. $ex = array('DHL'=>10,'FEDEX'=>12,'FEDEXGF'=>12,'UPS'=>18,'GES'=>17,'TNT'=>9,'ARAMEX'=>11,'EMS_ZX_ZX_US'=>13);
  612. if(isset($ex[$sex['printcode']]))
  613. {
  614. if(strlen($number) != $ex[$sex['printcode']])
  615. {
  616. echo json_encode(array('msg'=>'运单号错误,此单请重新录入运单号!','success'=>false));exit;
  617. }
  618. }
  619. **/
  620. if(strlen($number) == 12 && $sex['printcode'] != 'FEDEX' && $sex['printcode'] != 'FEDEXGF' && $sex['printcode'] != 'HUALEI-MLXY' && $sex['printcode'] != 'FEDEX_G' && $sex['printcode'] != 'HUALEIXW-USPS' && $sex['printcode'] != 'FedEx_GD' )
  621. {
  622. echo json_encode(array('msg'=>'运单号和快递类型不符!F','success'=>false));exit;
  623. }
  624. if(strlen($number) == 10 && $sex['printcode'] != 'DHL' && $sex['printcode'] != 'DHLUSA' && $sex['printcode'] != 'HUALEI-DHL')
  625. {
  626. echo json_encode(array('msg'=>'运单号和快递类型不符!D','success'=>false));exit;
  627. }
  628. if(strlen($number) == 18 && $sex['printcode'] != 'UPS' && $sex['printcode'] != 'YunExpress' && $sex['printcode'] != 'YunExpress_BaoXian' && $sex['printcode'] != 'USKD01')
  629. {
  630. echo json_encode(array('msg'=>'运单号和快递类型不符!U'.$sex['printcode'],'success'=>false));exit;
  631. }
  632. if(strlen($number) == 16 && $sex['printcode'] != '3PE_XB' && $sex['printcode'] != 'TTUK')
  633. {
  634. echo json_encode(array('msg'=>'运单号和快递类型不符!PE'.$sex['printcode'],'success'=>false));exit;
  635. }
  636. $tmp_waybill = $number;
  637. $yd = $this->fullorder->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  638. if(isset($yd[0]['number']))
  639. {
  640. $number = $yd[0]['number'];
  641. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  642. {
  643. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  644. }
  645. }
  646. else
  647. {
  648. $yd = $this->fullordersmt->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  649. if(isset($yd[0]['number']))
  650. {
  651. $number = $yd[0]['number'];
  652. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  653. {
  654. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  655. }
  656. if($yd[0]['express'] != 24 && $yd[0]['express'] == 31)
  657. {
  658. echo json_encode(array('msg'=>'请选择杭州联邦快递方式录入','success'=>false));exit;
  659. }
  660. }
  661. else
  662. {
  663. $yd = $this->fullordertt->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  664. if(isset($yd[0]['number']))
  665. {
  666. $number = $yd[0]['number'];
  667. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  668. {
  669. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  670. }
  671. if($yd[0]['express'] != 24 && $yd[0]['express'] == 31)
  672. {
  673. echo json_encode(array('msg'=>'请选择杭州联邦快递方式录入','success'=>false));exit;
  674. }
  675. }
  676. else
  677. {
  678. $yd = $this->fullorderamz->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  679. if(isset($yd[0]['number']))
  680. {
  681. $number = $yd[0]['number'];
  682. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  683. {
  684. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  685. }
  686. if($yd[0]['express'] != 24 && $yd[0]['express'] == 31)
  687. {
  688. echo json_encode(array('msg'=>'请选择杭州联邦快递方式录入','success'=>false));exit;
  689. }
  690. }
  691. else
  692. {
  693. $yd = $this->fullorderxw->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  694. if(isset($yd[0]['number']))
  695. {
  696. $number = $yd[0]['number'];
  697. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  698. {
  699. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  700. }
  701. if($yd[0]['express'] != 24 && $yd[0]['express'] == 31)
  702. {
  703. echo json_encode(array('msg'=>'请选择杭州联邦快递方式录入','success'=>false));exit;
  704. }
  705. }
  706. else
  707. {
  708. echo json_encode(array('msg'=>'系统中未查到此运单,请确认!'.$number,'success'=>false));exit;
  709. }
  710. }
  711. }
  712. }
  713. }
  714. /**
  715. if($yd[0]['printtype'] != 1)
  716. {
  717. echo json_encode(array('msg'=>'请扫描正确的运单号!','success'=>false));exit;
  718. }
  719. **/
  720. $nu = $this->outbound->get_number($number);
  721. if($nu)
  722. {
  723. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  724. }
  725. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'waybill'=>$tmp_waybill,'express'=>$express,'gtime'=>date('Ymd',time()),'time'=>$time)))
  726. {
  727. $data = $this->outbound->find_count($where);
  728. echo json_encode(array('msg'=>'提交成功,数量:'.$data,'music'=>'1','success'=>true));exit;
  729. }
  730. else
  731. {
  732. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  733. }
  734. }
  735. else
  736. {
  737. $dd = $this->fullorder->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  738. if(isset($dd[0]['number']))
  739. {
  740. if($dd[0]['express'] != $express)
  741. {
  742. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  743. }
  744. }
  745. else
  746. {
  747. $dd = $this->fullordersmt->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  748. if(isset($dd[0]['number']))
  749. {
  750. $number = $dd[0]['number'];
  751. if($dd[0]['express'] != $express)
  752. {
  753. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  754. }
  755. }
  756. else
  757. {
  758. $dd = $this->fullordertt->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  759. if(isset($dd[0]['number']))
  760. {
  761. $number = $dd[0]['number'];
  762. if($dd[0]['express'] != $express)
  763. {
  764. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  765. }
  766. }
  767. else
  768. {
  769. $dd = $this->fullorderamz->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  770. if(isset($dd[0]['number']))
  771. {
  772. $number = $dd[0]['number'];
  773. if($dd[0]['express'] != $express)
  774. {
  775. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  776. }
  777. }
  778. else
  779. {
  780. $dd = $this->fullorderxw->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  781. if(isset($dd[0]['number']))
  782. {
  783. $number = $dd[0]['number'];
  784. if($dd[0]['express'] != $express)
  785. {
  786. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  787. }
  788. }
  789. else
  790. {
  791. echo json_encode(array('msg'=>'系统中未查到此编号,请确认!','success'=>false));exit;
  792. }
  793. }
  794. }
  795. }
  796. }
  797. $tmp_waybill = "";
  798. if(isset($dd[0]['waybill'])){
  799. $tmp_waybill= $dd[0]['waybill'];
  800. }
  801. if(($dd[0]['printtype'] != 2) && (!in_array($dd[0]['express'],[50,51,52,69,73])))
  802. {
  803. echo json_encode(array('msg'=>'请扫描正确的条码!','success'=>false));exit;
  804. }
  805. $nu = $this->outbound->get_number($number);
  806. if($nu)
  807. {
  808. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  809. }
  810. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'waybill'=>$tmp_waybill,'express'=>$express,'gtime'=>date('Ymd',time()),'time'=>$time)))
  811. {
  812. $data = $this->outbound->find_count($where);
  813. echo json_encode(array('msg'=>'添加成功!','success'=>true));exit;
  814. }
  815. else
  816. {
  817. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  818. }
  819. }
  820. /**
  821. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'waybill'=>$waybill,'express'=>$express,'gtime'=>date('Ymd',$time),'time'=>$time+1)))
  822. {
  823. echo json_encode(array('msg'=>'添加成功!','success'=>true));exit;
  824. }
  825. **/
  826. }
  827. }
  828. public function _del()
  829. {
  830. $post = $this->input->post(NULL, TRUE);
  831. if(isset($post['delarr']))
  832. {
  833. $id_arr = $this->input->post('delarr');
  834. $id_arr = explode(',',rtrim($id_arr,','));
  835. if(!$id_arr)
  836. {
  837. echo json_encode(array('msg'=>'未选择需要删除的内容!','success'=>false));exit;
  838. }
  839. //循环删除记录
  840. $a=0;
  841. foreach ($id_arr as $v)
  842. {
  843. if($this->outbound->remove($v))
  844. {
  845. $a++;
  846. }
  847. }
  848. if($a == count($id_arr))
  849. {
  850. $data = $this->outbound->find_count("gtime = '".date('Ymd',time())."'");
  851. echo json_encode(array('del'=>$id_arr,'data'=>$data,'msg'=>'删除成功!','success'=>true));
  852. }
  853. else
  854. {
  855. echo json_encode(array('del'=>$id_arr,'msg'=>'部分记录删除失败,请查询确认!','success'=>true));
  856. }
  857. }
  858. }
  859. public function _ex()
  860. {
  861. }
  862. public function _out()
  863. {
  864. $post = $this->input->post(NULL, TRUE);
  865. if(isset($post['number']))
  866. {
  867. $where = "gtime = '".date('Ymd',time())."'";
  868. $number = $this->input->post('number',true);
  869. $type = $this->input->post('type',true);
  870. $express = $this->input->post('express',true);
  871. if($_SESSION['api'])
  872. {
  873. if($type)
  874. {
  875. $where .= " and type = '$type'";
  876. }
  877. else
  878. {
  879. $uw = '';
  880. $u = $this->user->get_api($_SESSION['api']);
  881. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  882. foreach ($u['warehouse'] as $v)
  883. {
  884. $uw .= " type = '$v' or";
  885. }
  886. $uw = rtrim($uw,'or');
  887. $uw = " and (".ltrim($uw,' ').")";
  888. $where .= $uw;
  889. }
  890. }
  891. if(!$number)
  892. {
  893. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  894. }
  895. if(!$type)
  896. {
  897. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  898. }
  899. if(!$express)
  900. {
  901. echo json_encode(array('msg'=>'请选择需要录入的快递!','success'=>false));exit;
  902. }
  903. $sex = $this->express->read($express);
  904. if(stripos($number,'-') === false)
  905. {
  906. if(substr($number,0,3) == '788' && substr($number,-4,4) == '0430')//Fedex联邦
  907. {
  908. $number = substr($number,0,12);
  909. }
  910. if(strlen($number) == '34')//联邦杭州超长运单截取
  911. {
  912. //$number = substr($number,22,12);
  913. $str = substr($number, 0,3);
  914. if($str == "420"){
  915. $number = substr($number,12);
  916. }else{
  917. $number = substr($number,22,12);
  918. }
  919. }
  920. /**
  921. $ex = array('DHL'=>10,'FEDEX'=>12,'FEDEXGF'=>12,'UPS'=>18,'GES'=>17,'TNT'=>9,'ARAMEX'=>11,'EMS_ZX_ZX_US'=>13);
  922. if(isset($ex[$sex['printcode']]))
  923. {
  924. if(strlen($number) != $ex[$sex['printcode']])
  925. {
  926. echo json_encode(array('msg'=>'运单号错误,此单请重新录入运单号!','success'=>false));exit;
  927. }
  928. }
  929. **/
  930. if(strlen($number) == 12 && $sex['printcode'] != 'FEDEX' && $sex['printcode'] != 'FEDEXGF' && $sex['printcode'] != 'HUALEI-MLXY' && $sex['printcode'] != 'FEDEX_G' && $sex['printcode'] != 'HUALEIXW-USPS' && $sex['printcode'] != 'FedEx_GD' && $sex['printcode'] != 'HUALEI-GES-EU' && $sex['printcode'] != 'ZXDPD_UK' && $sex['printcode'] != 'ZXDPD_EU')
  931. {
  932. echo json_encode(array('msg'=>'运单号和快递类型不符!F','success'=>false));exit;
  933. }
  934. if(strlen($number) == 10 && $sex['printcode'] != 'DHL' && $sex['printcode'] != 'DHLUSA' && $sex['printcode'] != 'HUALEI-DHL' && $sex['printcode'] != 'ZXDPD_UK' && $sex['printcode'] != 'ZXDPD_EU')
  935. {
  936. echo json_encode(array('msg'=>'运单号和快递类型不符!D','success'=>false));exit;
  937. }
  938. if(strlen($number) == 18 && $sex['printcode'] != 'UPS' && $sex['printcode'] != 'YunExpress' && $sex['printcode'] != 'YunExpress_BaoXian' && $sex['printcode'] != 'USKD01')
  939. {
  940. echo json_encode(array('msg'=>'运单号和快递类型不符!U'.$sex['printcode'],'success'=>false));exit;
  941. }
  942. if(strlen($number) == 16 && $sex['printcode'] != '3PE_XB' && $sex['printcode'] != 'TTUK')
  943. {
  944. echo json_encode(array('msg'=>'运单号和快递类型不符!PE'.$sex['printcode'],'success'=>false));exit;
  945. }
  946. $yd = $this->fullorder->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  947. if(isset($yd[0]['number']))
  948. {
  949. $number = $yd[0]['number'];
  950. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  951. {
  952. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  953. }
  954. }
  955. else
  956. {
  957. $yd = $this->fullordersmt->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  958. if(isset($yd[0]['number']))
  959. {
  960. $number = $yd[0]['number'];
  961. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  962. {
  963. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  964. }
  965. }
  966. else
  967. {
  968. $yd = $this->fullordertt->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  969. if(isset($yd[0]['number']))
  970. {
  971. $number = $yd[0]['number'];
  972. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  973. {
  974. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  975. }
  976. }
  977. else
  978. {
  979. $yd = $this->fullorderamz->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  980. if(isset($yd[0]['number']))
  981. {
  982. $number = $yd[0]['number'];
  983. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  984. {
  985. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  986. }
  987. }
  988. else
  989. {
  990. $yd = $this->fullorderxw->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  991. if(isset($yd[0]['number']))
  992. {
  993. $number = $yd[0]['number'];
  994. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  995. {
  996. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  997. }
  998. }
  999. else
  1000. {
  1001. echo json_encode(array('msg'=>'系统中未查到此运单,请确认!'.$number,'success'=>false));exit;
  1002. }
  1003. }
  1004. }
  1005. }
  1006. }
  1007. /**
  1008. if($yd[0]['printtype'] != 1)
  1009. {
  1010. echo json_encode(array('msg'=>'请扫描正确的运单号!','success'=>false));exit;
  1011. }
  1012. **/
  1013. //再次判断下杭州不报关的类别是否满足条件 如果有影响可以删除
  1014. if($yd[0]['express'] != $express){
  1015. echo json_encode(array('msg'=>'录入信息和选择快递不一致!2','success'=>false));exit;
  1016. }
  1017. $nu = $this->outbound->get_number($number);
  1018. if($nu)
  1019. {
  1020. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  1021. }
  1022. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'waybill'=>$yd[0]['waybill'],'express'=>$yd[0]['express'],'gtime'=>date('Ymd',time()),'time'=>time())))
  1023. {
  1024. $data = $this->outbound->find_count($where);
  1025. echo json_encode(array('msg'=>$data,'music'=>'1','success'=>true));exit;
  1026. }
  1027. else
  1028. {
  1029. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  1030. }
  1031. }
  1032. else
  1033. {
  1034. $dd = $this->fullorder->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  1035. if(isset($dd[0]['number']))
  1036. {
  1037. if($dd[0]['express'] != $express)
  1038. {
  1039. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  1040. }
  1041. }
  1042. else
  1043. {
  1044. $dd = $this->fullordersmt->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  1045. if(isset($dd[0]['number']))
  1046. {
  1047. $number = $dd[0]['number'];
  1048. if($dd[0]['express'] != $express)
  1049. {
  1050. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  1051. }
  1052. }
  1053. else
  1054. {
  1055. $dd = $this->fullordertt->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  1056. if(isset($dd[0]['number']))
  1057. {
  1058. $number = $dd[0]['number'];
  1059. if($dd[0]['express'] != $express)
  1060. {
  1061. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  1062. }
  1063. }
  1064. else
  1065. {
  1066. $dd = $this->fullorderamz->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  1067. if(isset($dd[0]['number']))
  1068. {
  1069. $number = $dd[0]['number'];
  1070. if($dd[0]['express'] != $express)
  1071. {
  1072. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  1073. }
  1074. }
  1075. else
  1076. {
  1077. $dd = $this->fullorderxw->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  1078. if(isset($dd[0]['number']))
  1079. {
  1080. $number = $dd[0]['number'];
  1081. if($dd[0]['express'] != $express)
  1082. {
  1083. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  1084. }
  1085. }
  1086. else
  1087. {
  1088. echo json_encode(array('msg'=>'系统中未查到此编号,请确认!','success'=>false));exit;
  1089. }
  1090. }
  1091. }
  1092. }
  1093. }
  1094. //惠程-美国USPS 惠程-联邦 惠程-安迈世 惠程-DHL 惠程-GES(欧盟)
  1095. if(($dd[0]['printtype'] != 2) && (!in_array($dd[0]['express'],[50,51,52,69,73,75])))
  1096. {
  1097. echo json_encode(array('msg'=>'请扫描正确的条码!','success'=>false));exit;
  1098. }
  1099. //判断该订单的快递单号是否存在 如果不存在提示 补齐快递单号 在进行扫描
  1100. // if(empty($dd[0]['waybill'])){
  1101. // echo json_encode(array('msg'=>'该订单未检索到快递信息,请补齐快递单号!','success'=>false));exit;
  1102. // }
  1103. $nu = $this->outbound->get_number($number);
  1104. if($nu)
  1105. {
  1106. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  1107. }
  1108. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'waybill'=>$dd[0]['waybill'],'express'=>$dd[0]['express'],'gtime'=>date('Ymd',time()),'time'=>time())))
  1109. {
  1110. $data = $this->outbound->find_count($where);
  1111. echo json_encode(array('msg'=>$data,'music'=>'1','success'=>true));exit;
  1112. }
  1113. else
  1114. {
  1115. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  1116. }
  1117. }
  1118. }
  1119. }
  1120. }