Systembound.php 38 KB

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