Systembound.php 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  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. $weight = str_replace('kgkg','kg',$weight);
  267. $final_list[$value['express']][] = [
  268. $value['number'],
  269. $value['waybill'],
  270. $weight
  271. ];
  272. }
  273. }
  274. $data[] = $datafy;
  275. //格式化数据
  276. $i = 0;$cpexcel = array();
  277. $title = date('Ymd',time()).$typename."发货统计信息"; $td = '';
  278. $td = "";
  279. $count = 0;
  280. foreach($ex_list as $v){
  281. $num = count($final_list[$v['id']]);
  282. if($num > $count){
  283. $count = $num;
  284. }
  285. $td .= "<td>".$v['servicename']."</td><td>总数(".$num.")</td><td>重量</td>";
  286. }
  287. foreach($final_list as $k=>$v){
  288. for($i=0;$i < $count ;$i++){
  289. if(!isset($final_list[$k][$i])){
  290. $final_list[$k][$i] = [
  291. " "," ",""
  292. ];
  293. }
  294. }
  295. }
  296. $titlename = "<table border=1>
  297. <tr>
  298. ".$td."
  299. </tr>
  300. </table>";
  301. $filename = $title.".xls";
  302. $this->excel->get_fz7($final_list,$titlename,$filename);
  303. }
  304. }
  305. public function _excel()
  306. {
  307. if(isset($_GET['fexcel']))
  308. {
  309. $timetk = $this->input->get('timetk',true);
  310. $timetj = $this->input->get('timetj',true);
  311. $library = $this->input->get('library',true);
  312. $type = $this->input->get('type',true);
  313. $number = $this->input->get('number',true);
  314. $waybill = $this->input->get('waybill',true);
  315. $express = $this->input->get('express',true);
  316. $timetk = strtotime($timetk);
  317. $timetj = strtotime($timetj);
  318. $where = "type != 0";
  319. if($timetk && $timetj)
  320. {
  321. $where .= " and time > '$timetk' and time < '$timetj'";
  322. }
  323. if(isset($_SESSION['api']))
  324. {
  325. if($type)
  326. {
  327. $where .= " and type = '$type'";
  328. }
  329. else
  330. {
  331. $uw = '';
  332. $u = $this->user->get_api($_SESSION['api']);
  333. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  334. foreach ($u['warehouse'] as $v)
  335. {
  336. $uw .= " type = '$v' or";
  337. }
  338. $uw = rtrim($uw,'or');
  339. $uw = " and (".ltrim($uw,' ').")";
  340. $where .= $uw;
  341. }
  342. }
  343. else
  344. {
  345. echo json_encode(array('msg'=>'导出失败,请重新登陆!','success'=>false));exit;
  346. }
  347. if($number)
  348. {
  349. $where .= " and number = '$number'";
  350. }
  351. if($waybill)
  352. {
  353. $where .= " and waybill = '$waybill'";
  354. }
  355. if($express)
  356. {
  357. $where .= " and express = '$express'";
  358. }
  359. $data = array();
  360. $datafy = array();
  361. $j = 0;
  362. $info_list = $this->outbound->find_all($where,'number,waybill','time asc');
  363. foreach ($info_list as $key=>$value)
  364. {
  365. $datafy[] = array($value['number'],$value['waybill']);
  366. if($j == $library-1)
  367. {
  368. $data[] = $datafy;
  369. $j = 0;$datafy = array();
  370. }
  371. else
  372. {
  373. $j++;
  374. }
  375. }
  376. $data[] = $datafy;
  377. //格式化数据
  378. $i = 0;$cpexcel = array();
  379. $title = date('Ymd',time())."发货统计信息"; $td = '';
  380. for($i=0;$i<ceil(count($info_list)/$library);$i++)
  381. {
  382. $td .= "<td>组".($i+1)."</td><td></td>";
  383. }
  384. $titlename = "<table border=1>
  385. <tr>
  386. ".$td."
  387. </tr>
  388. </table>";
  389. $filename = $title.".xls";
  390. $this->excel->get_fz6($data,$titlename,$filename);
  391. }
  392. }
  393. //一件导出惠城的全部快递
  394. public function _excelhc()
  395. {
  396. if(isset($_GET['fexcel']))
  397. {
  398. $timetk = $this->input->get('timetk',true);
  399. $timetj = $this->input->get('timetj',true);
  400. $library = $this->input->get('library',true);
  401. $type = $this->input->get('type',true);
  402. $number = $this->input->get('number',true);
  403. $waybill = $this->input->get('waybill',true);
  404. $timetk = strtotime($timetk);
  405. $timetj = strtotime($timetj);
  406. $select_express = $this->input->get('select_express',true);
  407. if($select_express == 'ozyt'){
  408. //云途(欧洲) 云途(欧洲)-带保险
  409. $cx_arr = [66,67];//需要的查询数据
  410. $typename = "云途(欧洲)";
  411. }else{
  412. //GES 7 惠城联邦 50 惠城GES 51 惠城安迈世 51 惠城DHL 69 惠城usps 73
  413. $cx_arr = [7,50,51,52,69,73];//需要的查询数据
  414. $typename = "惠程";
  415. }
  416. $ex_list = $this->express->find_all("id in (".implode(',',$cx_arr).")","id,servicename");
  417. $where = "type != 0 and express in (".implode(',',$cx_arr).")";
  418. if($timetk && $timetj)
  419. {
  420. $where .= " and time > '$timetk' and time < '$timetj'";
  421. }
  422. if(isset($_SESSION['api']))
  423. {
  424. if($type)
  425. {
  426. $where .= " and type = '$type'";
  427. }
  428. else
  429. {
  430. $uw = '';
  431. $u = $this->user->get_api($_SESSION['api']);
  432. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  433. foreach ($u['warehouse'] as $v)
  434. {
  435. $uw .= " type = '$v' or";
  436. }
  437. $uw = rtrim($uw,'or');
  438. $uw = " and (".ltrim($uw,' ').")";
  439. $where .= $uw;
  440. }
  441. }
  442. else
  443. {
  444. echo json_encode(array('msg'=>'导出失败,请重新登陆!','success'=>false));exit;
  445. }
  446. if($number)
  447. {
  448. $where .= " and number = '$number'";
  449. }
  450. if($waybill)
  451. {
  452. $where .= " and waybill = '$waybill'";
  453. }
  454. $data = array();
  455. $datafy = array();
  456. $j = 0;
  457. $info_list = $this->outbound->find_all($where,'number,waybill,express','time asc');
  458. $final_list= [
  459. ];
  460. foreach($cx_arr as $v){
  461. $final_list[$v] = [];
  462. }
  463. foreach ($info_list as $key=>$value)
  464. {
  465. if(isset($final_list[$value['express']])){
  466. $final_list[$value['express']][] = [
  467. $value['number'],
  468. $value['waybill'],
  469. ];
  470. }
  471. }
  472. $data[] = $datafy;
  473. //格式化数据
  474. $i = 0;$cpexcel = array();
  475. $title = date('Ymd',time()).$typename."发货统计信息"; $td = '';
  476. $td = "";
  477. $count = 0;
  478. foreach($ex_list as $v){
  479. $num = count($final_list[$v['id']]);
  480. if($num > $count){
  481. $count = $num;
  482. }
  483. $td .= "<td>".$v['servicename']."</td><td>".$num."</td>";
  484. }
  485. foreach($final_list as $k=>$v){
  486. for($i=0;$i < $count ;$i++){
  487. if(!isset($final_list[$k][$i])){
  488. $final_list[$k][$i] = [
  489. " "," "
  490. ];
  491. }
  492. }
  493. }
  494. $titlename = "<table border=1>
  495. <tr>
  496. ".$td."
  497. </tr>
  498. </table>";
  499. $filename = $title.".xls";
  500. $this->excel->get_fz6($final_list,$titlename,$filename);
  501. }
  502. }
  503. public function _add()
  504. {
  505. $post = $this->input->post(NULL, TRUE);
  506. if(isset($post['number']))
  507. {
  508. $where = "gtime = '".date('Ymd',time())."'";
  509. $number = $this->input->post('number',true);
  510. //$waybill = $this->input->post('waybill',true);
  511. $id = $this->input->post('id',true);
  512. $type = $this->input->post('type',true);
  513. $express = $this->input->post('express',true);
  514. $time = $this->input->post('time',true);
  515. if($time)
  516. {
  517. $time = strtotime($time);
  518. }
  519. else
  520. {
  521. $time = time();
  522. }
  523. if($id)
  524. {
  525. if($type)
  526. {
  527. $where .= " and type = '$type'";
  528. }
  529. else
  530. {
  531. $uw = '';
  532. $u = $this->user->get_api($id);
  533. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  534. foreach ($u['warehouse'] as $v)
  535. {
  536. $uw .= " type = '$v' or";
  537. }
  538. $uw = rtrim($uw,'or');
  539. $uw = " and (".ltrim($uw,' ').")";
  540. $where .= $uw;
  541. }
  542. }
  543. /**
  544. if(!$number)
  545. {
  546. echo json_encode(array('msg'=>'编号不能为空!','success'=>false));exit;
  547. }
  548. if(!$waybill)
  549. {
  550. //echo json_encode(array('msg'=>'运单号不能为空!','success'=>false));exit;
  551. }
  552. if(!$type)
  553. {
  554. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  555. }
  556. if(!$express)
  557. {
  558. echo json_encode(array('msg'=>'请选择需要录入的快递!','success'=>false));exit;
  559. }
  560. $nu = $this->outbound->get_number($number);
  561. if($nu)
  562. {
  563. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  564. }
  565. if($waybill)
  566. {
  567. $wa = $this->outbound->get_waybill($waybill);
  568. if($wa)
  569. {
  570. echo json_encode(array('msg'=>'错误!此运单号'.date('Ymd',$wa['time']).'已录入!','success'=>false));exit;
  571. }
  572. $sex = $this->express->read($express);
  573. $ex = array('DHL'=>10,'FEDEX'=>12,'FEDEXGF'=>12,'UPS'=>18,'GES'=>17,'TNT'=>9,'ARAMEX'=>11,'EMS_ZX_ZX_US'=>13);
  574. if(isset($ex[$sex['printcode']]))
  575. {
  576. if(strlen($waybill) != $ex[$sex['printcode']])
  577. {
  578. echo json_encode(array('msg'=>'运单号错误,此单请重新录入运单号!','success'=>false));exit;
  579. }
  580. }
  581. }
  582. **/
  583. if(!$number)
  584. {
  585. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  586. }
  587. if(!$type)
  588. {
  589. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  590. }
  591. if(!$express)
  592. {
  593. echo json_encode(array('msg'=>'请选择需要录入的快递!','success'=>false));exit;
  594. }
  595. $sex = $this->express->read($express);
  596. if(stripos($number,'-') === false)
  597. {
  598. if(substr($number,0,3) == '788' && substr($number,-4,4) == '0430')//Fedex联邦
  599. {
  600. $number = substr($number,0,12);
  601. }
  602. if(strlen($number) == '34')//联邦杭州超长运单截取
  603. {
  604. $str = substr($number, 0,3);
  605. if($str == "420"){
  606. $number = substr($number,12);
  607. }else{
  608. $number = substr($number,22,12);
  609. }
  610. }
  611. /**
  612. $ex = array('DHL'=>10,'FEDEX'=>12,'FEDEXGF'=>12,'UPS'=>18,'GES'=>17,'TNT'=>9,'ARAMEX'=>11,'EMS_ZX_ZX_US'=>13);
  613. if(isset($ex[$sex['printcode']]))
  614. {
  615. if(strlen($number) != $ex[$sex['printcode']])
  616. {
  617. echo json_encode(array('msg'=>'运单号错误,此单请重新录入运单号!','success'=>false));exit;
  618. }
  619. }
  620. **/
  621. 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' )
  622. {
  623. echo json_encode(array('msg'=>'运单号和快递类型不符!F','success'=>false));exit;
  624. }
  625. if(strlen($number) == 10 && $sex['printcode'] != 'DHL' && $sex['printcode'] != 'DHLUSA' && $sex['printcode'] != 'HUALEI-DHL')
  626. {
  627. echo json_encode(array('msg'=>'运单号和快递类型不符!D','success'=>false));exit;
  628. }
  629. if(strlen($number) == 18 && $sex['printcode'] != 'UPS' && $sex['printcode'] != 'YunExpress' && $sex['printcode'] != 'YunExpress_BaoXian' && $sex['printcode'] != 'USKD01')
  630. {
  631. echo json_encode(array('msg'=>'运单号和快递类型不符!U'.$sex['printcode'],'success'=>false));exit;
  632. }
  633. if(strlen($number) == 16 && $sex['printcode'] != '3PE_XB' && $sex['printcode'] != 'TTUK')
  634. {
  635. echo json_encode(array('msg'=>'运单号和快递类型不符!PE'.$sex['printcode'],'success'=>false));exit;
  636. }
  637. $tmp_waybill = $number;
  638. $yd = $this->fullorder->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  639. if(isset($yd[0]['number']))
  640. {
  641. $number = $yd[0]['number'];
  642. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  643. {
  644. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  645. }
  646. }
  647. else
  648. {
  649. $yd = $this->fullordersmt->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  650. if(isset($yd[0]['number']))
  651. {
  652. $number = $yd[0]['number'];
  653. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  654. {
  655. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  656. }
  657. if($yd[0]['express'] != 24 && $yd[0]['express'] == 31)
  658. {
  659. echo json_encode(array('msg'=>'请选择杭州联邦快递方式录入','success'=>false));exit;
  660. }
  661. }
  662. else
  663. {
  664. $yd = $this->fullordertt->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  665. if(isset($yd[0]['number']))
  666. {
  667. $number = $yd[0]['number'];
  668. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  669. {
  670. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  671. }
  672. if($yd[0]['express'] != 24 && $yd[0]['express'] == 31)
  673. {
  674. echo json_encode(array('msg'=>'请选择杭州联邦快递方式录入','success'=>false));exit;
  675. }
  676. }
  677. else
  678. {
  679. $yd = $this->fullorderamz->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  680. if(isset($yd[0]['number']))
  681. {
  682. $number = $yd[0]['number'];
  683. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  684. {
  685. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  686. }
  687. if($yd[0]['express'] != 24 && $yd[0]['express'] == 31)
  688. {
  689. echo json_encode(array('msg'=>'请选择杭州联邦快递方式录入','success'=>false));exit;
  690. }
  691. }
  692. else
  693. {
  694. $yd = $this->fullorderxw->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  695. if(isset($yd[0]['number']))
  696. {
  697. $number = $yd[0]['number'];
  698. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  699. {
  700. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  701. }
  702. if($yd[0]['express'] != 24 && $yd[0]['express'] == 31)
  703. {
  704. echo json_encode(array('msg'=>'请选择杭州联邦快递方式录入','success'=>false));exit;
  705. }
  706. }
  707. else
  708. {
  709. echo json_encode(array('msg'=>'系统中未查到此运单,请确认!'.$number,'success'=>false));exit;
  710. }
  711. }
  712. }
  713. }
  714. }
  715. /**
  716. if($yd[0]['printtype'] != 1)
  717. {
  718. echo json_encode(array('msg'=>'请扫描正确的运单号!','success'=>false));exit;
  719. }
  720. **/
  721. $nu = $this->outbound->get_number($number);
  722. if($nu)
  723. {
  724. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  725. }
  726. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'waybill'=>$tmp_waybill,'express'=>$express,'gtime'=>date('Ymd',time()),'time'=>$time)))
  727. {
  728. $data = $this->outbound->find_count($where);
  729. echo json_encode(array('msg'=>'提交成功,数量:'.$data,'music'=>'1','success'=>true));exit;
  730. }
  731. else
  732. {
  733. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  734. }
  735. }
  736. else
  737. {
  738. $dd = $this->fullorder->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  739. if(isset($dd[0]['number']))
  740. {
  741. if($dd[0]['express'] != $express)
  742. {
  743. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  744. }
  745. }
  746. else
  747. {
  748. $dd = $this->fullordersmt->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  749. if(isset($dd[0]['number']))
  750. {
  751. $number = $dd[0]['number'];
  752. if($dd[0]['express'] != $express)
  753. {
  754. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  755. }
  756. }
  757. else
  758. {
  759. $dd = $this->fullordertt->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  760. if(isset($dd[0]['number']))
  761. {
  762. $number = $dd[0]['number'];
  763. if($dd[0]['express'] != $express)
  764. {
  765. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  766. }
  767. }
  768. else
  769. {
  770. $dd = $this->fullorderamz->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  771. if(isset($dd[0]['number']))
  772. {
  773. $number = $dd[0]['number'];
  774. if($dd[0]['express'] != $express)
  775. {
  776. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  777. }
  778. }
  779. else
  780. {
  781. $dd = $this->fullorderxw->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  782. if(isset($dd[0]['number']))
  783. {
  784. $number = $dd[0]['number'];
  785. if($dd[0]['express'] != $express)
  786. {
  787. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  788. }
  789. }
  790. else
  791. {
  792. echo json_encode(array('msg'=>'系统中未查到此编号,请确认!','success'=>false));exit;
  793. }
  794. }
  795. }
  796. }
  797. }
  798. $tmp_waybill = "";
  799. if(isset($dd[0]['waybill'])){
  800. $tmp_waybill= $dd[0]['waybill'];
  801. }
  802. if(($dd[0]['printtype'] != 2) && (!in_array($dd[0]['express'],[50,51,52,69,73])))
  803. {
  804. echo json_encode(array('msg'=>'请扫描正确的条码!','success'=>false));exit;
  805. }
  806. $nu = $this->outbound->get_number($number);
  807. if($nu)
  808. {
  809. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  810. }
  811. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'waybill'=>$tmp_waybill,'express'=>$express,'gtime'=>date('Ymd',time()),'time'=>$time)))
  812. {
  813. $data = $this->outbound->find_count($where);
  814. echo json_encode(array('msg'=>'添加成功!','success'=>true));exit;
  815. }
  816. else
  817. {
  818. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  819. }
  820. }
  821. /**
  822. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'waybill'=>$waybill,'express'=>$express,'gtime'=>date('Ymd',$time),'time'=>$time+1)))
  823. {
  824. echo json_encode(array('msg'=>'添加成功!','success'=>true));exit;
  825. }
  826. **/
  827. }
  828. }
  829. public function _del()
  830. {
  831. $post = $this->input->post(NULL, TRUE);
  832. if(isset($post['delarr']))
  833. {
  834. $id_arr = $this->input->post('delarr');
  835. $id_arr = explode(',',rtrim($id_arr,','));
  836. if(!$id_arr)
  837. {
  838. echo json_encode(array('msg'=>'未选择需要删除的内容!','success'=>false));exit;
  839. }
  840. //循环删除记录
  841. $a=0;
  842. foreach ($id_arr as $v)
  843. {
  844. if($this->outbound->remove($v))
  845. {
  846. $a++;
  847. }
  848. }
  849. if($a == count($id_arr))
  850. {
  851. $data = $this->outbound->find_count("gtime = '".date('Ymd',time())."'");
  852. echo json_encode(array('del'=>$id_arr,'data'=>$data,'msg'=>'删除成功!','success'=>true));
  853. }
  854. else
  855. {
  856. echo json_encode(array('del'=>$id_arr,'msg'=>'部分记录删除失败,请查询确认!','success'=>true));
  857. }
  858. }
  859. }
  860. public function _ex()
  861. {
  862. }
  863. public function _out()
  864. {
  865. $post = $this->input->post(NULL, TRUE);
  866. if(isset($post['number']))
  867. {
  868. $where = "gtime = '".date('Ymd',time())."'";
  869. $number = $this->input->post('number',true);
  870. $type = $this->input->post('type',true);
  871. $express = $this->input->post('express',true);
  872. if($_SESSION['api'])
  873. {
  874. if($type)
  875. {
  876. $where .= " and type = '$type'";
  877. }
  878. else
  879. {
  880. $uw = '';
  881. $u = $this->user->get_api($_SESSION['api']);
  882. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  883. foreach ($u['warehouse'] as $v)
  884. {
  885. $uw .= " type = '$v' or";
  886. }
  887. $uw = rtrim($uw,'or');
  888. $uw = " and (".ltrim($uw,' ').")";
  889. $where .= $uw;
  890. }
  891. }
  892. if(!$number)
  893. {
  894. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  895. }
  896. if(!$type)
  897. {
  898. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  899. }
  900. if(!$express)
  901. {
  902. echo json_encode(array('msg'=>'请选择需要录入的快递!','success'=>false));exit;
  903. }
  904. $sex = $this->express->read($express);
  905. if(stripos($number,'-') === false)
  906. {
  907. if(substr($number,0,3) == '788' && substr($number,-4,4) == '0430')//Fedex联邦
  908. {
  909. $number = substr($number,0,12);
  910. }
  911. if(strlen($number) == '34')//联邦杭州超长运单截取
  912. {
  913. //$number = substr($number,22,12);
  914. $str = substr($number, 0,3);
  915. if($str == "420"){
  916. $number = substr($number,12);
  917. }else{
  918. $number = substr($number,22,12);
  919. }
  920. }
  921. /**
  922. $ex = array('DHL'=>10,'FEDEX'=>12,'FEDEXGF'=>12,'UPS'=>18,'GES'=>17,'TNT'=>9,'ARAMEX'=>11,'EMS_ZX_ZX_US'=>13);
  923. if(isset($ex[$sex['printcode']]))
  924. {
  925. if(strlen($number) != $ex[$sex['printcode']])
  926. {
  927. echo json_encode(array('msg'=>'运单号错误,此单请重新录入运单号!','success'=>false));exit;
  928. }
  929. }
  930. **/
  931. 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')
  932. {
  933. echo json_encode(array('msg'=>'运单号和快递类型不符!F','success'=>false));exit;
  934. }
  935. if(strlen($number) == 10 && $sex['printcode'] != 'DHL' && $sex['printcode'] != 'DHLUSA' && $sex['printcode'] != 'HUALEI-DHL' && $sex['printcode'] != 'ZXDPD_UK' && $sex['printcode'] != 'ZXDPD_EU')
  936. {
  937. echo json_encode(array('msg'=>'运单号和快递类型不符!D','success'=>false));exit;
  938. }
  939. if(strlen($number) == 18 && $sex['printcode'] != 'UPS' && $sex['printcode'] != 'YunExpress' && $sex['printcode'] != 'YunExpress_BaoXian' && $sex['printcode'] != 'USKD01')
  940. {
  941. echo json_encode(array('msg'=>'运单号和快递类型不符!U'.$sex['printcode'],'success'=>false));exit;
  942. }
  943. if(strlen($number) == 16 && $sex['printcode'] != '3PE_XB' && $sex['printcode'] != 'TTUK')
  944. {
  945. echo json_encode(array('msg'=>'运单号和快递类型不符!PE'.$sex['printcode'],'success'=>false));exit;
  946. }
  947. $yd = $this->fullorder->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  948. if(isset($yd[0]['number']))
  949. {
  950. $number = $yd[0]['number'];
  951. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  952. {
  953. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  954. }
  955. }
  956. else
  957. {
  958. $yd = $this->fullordersmt->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  959. if(isset($yd[0]['number']))
  960. {
  961. $number = $yd[0]['number'];
  962. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  963. {
  964. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  965. }
  966. }
  967. else
  968. {
  969. $yd = $this->fullordertt->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  970. if(isset($yd[0]['number']))
  971. {
  972. $number = $yd[0]['number'];
  973. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  974. {
  975. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  976. }
  977. }
  978. else
  979. {
  980. $yd = $this->fullorderamz->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  981. if(isset($yd[0]['number']))
  982. {
  983. $number = $yd[0]['number'];
  984. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  985. {
  986. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  987. }
  988. }
  989. else
  990. {
  991. $yd = $this->fullorderxw->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  992. if(isset($yd[0]['number']))
  993. {
  994. $number = $yd[0]['number'];
  995. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  996. {
  997. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  998. }
  999. }
  1000. else
  1001. {
  1002. echo json_encode(array('msg'=>'系统中未查到此运单,请确认!'.$number,'success'=>false));exit;
  1003. }
  1004. }
  1005. }
  1006. }
  1007. }
  1008. /**
  1009. if($yd[0]['printtype'] != 1)
  1010. {
  1011. echo json_encode(array('msg'=>'请扫描正确的运单号!','success'=>false));exit;
  1012. }
  1013. **/
  1014. //再次判断下杭州不报关的类别是否满足条件 如果有影响可以删除
  1015. if($yd[0]['express'] != $express){
  1016. echo json_encode(array('msg'=>'录入信息和选择快递不一致!2','success'=>false));exit;
  1017. }
  1018. $nu = $this->outbound->get_number($number);
  1019. if($nu)
  1020. {
  1021. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  1022. }
  1023. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'waybill'=>$yd[0]['waybill'],'express'=>$yd[0]['express'],'gtime'=>date('Ymd',time()),'time'=>time())))
  1024. {
  1025. $data = $this->outbound->find_count($where);
  1026. echo json_encode(array('msg'=>$data,'music'=>'1','success'=>true));exit;
  1027. }
  1028. else
  1029. {
  1030. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  1031. }
  1032. }
  1033. else
  1034. {
  1035. $dd = $this->fullorder->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  1036. if(isset($dd[0]['number']))
  1037. {
  1038. if($dd[0]['express'] != $express)
  1039. {
  1040. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  1041. }
  1042. }
  1043. else
  1044. {
  1045. $dd = $this->fullordersmt->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  1046. if(isset($dd[0]['number']))
  1047. {
  1048. $number = $dd[0]['number'];
  1049. if($dd[0]['express'] != $express)
  1050. {
  1051. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  1052. }
  1053. }
  1054. else
  1055. {
  1056. $dd = $this->fullordertt->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  1057. if(isset($dd[0]['number']))
  1058. {
  1059. $number = $dd[0]['number'];
  1060. if($dd[0]['express'] != $express)
  1061. {
  1062. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  1063. }
  1064. }
  1065. else
  1066. {
  1067. $dd = $this->fullorderamz->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  1068. if(isset($dd[0]['number']))
  1069. {
  1070. $number = $dd[0]['number'];
  1071. if($dd[0]['express'] != $express)
  1072. {
  1073. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  1074. }
  1075. }
  1076. else
  1077. {
  1078. $dd = $this->fullorderxw->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  1079. if(isset($dd[0]['number']))
  1080. {
  1081. $number = $dd[0]['number'];
  1082. if($dd[0]['express'] != $express)
  1083. {
  1084. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  1085. }
  1086. }
  1087. else
  1088. {
  1089. echo json_encode(array('msg'=>'系统中未查到此编号,请确认!','success'=>false));exit;
  1090. }
  1091. }
  1092. }
  1093. }
  1094. }
  1095. //惠程-美国USPS 惠程-联邦 惠程-安迈世 惠程-DHL 惠程-GES(欧盟)
  1096. if(($dd[0]['printtype'] != 2) && (!in_array($dd[0]['express'],[50,51,52,69,73,75])))
  1097. {
  1098. echo json_encode(array('msg'=>'请扫描正确的条码!','success'=>false));exit;
  1099. }
  1100. //判断该订单的快递单号是否存在 如果不存在提示 补齐快递单号 在进行扫描
  1101. // if(empty($dd[0]['waybill'])){
  1102. // echo json_encode(array('msg'=>'该订单未检索到快递信息,请补齐快递单号!','success'=>false));exit;
  1103. // }
  1104. $nu = $this->outbound->get_number($number);
  1105. if($nu)
  1106. {
  1107. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  1108. }
  1109. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'waybill'=>$dd[0]['waybill'],'express'=>$dd[0]['express'],'gtime'=>date('Ymd',time()),'time'=>time())))
  1110. {
  1111. $data = $this->outbound->find_count($where);
  1112. echo json_encode(array('msg'=>$data,'music'=>'1','success'=>true));exit;
  1113. }
  1114. else
  1115. {
  1116. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  1117. }
  1118. }
  1119. }
  1120. }
  1121. }