Systembound.php 41 KB

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