Systembound.php 37 KB

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