Systembound.php 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  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];
  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];//需要的查询数据
  414. $typename = "云途(欧洲)";
  415. }else{
  416. //GES 7 惠城联邦 50 惠城GES 51 惠城安迈世 51 惠城DHL 69 惠城usps 73
  417. $cx_arr = [7,50,51,52,69,73];//需要的查询数据
  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' )
  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')
  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')
  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'] != 'TTUK')
  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. $dd = $this->fullorder->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  743. if(isset($dd[0]['number']))
  744. {
  745. if($dd[0]['express'] != $express)
  746. {
  747. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  748. }
  749. }
  750. else
  751. {
  752. $dd = $this->fullordersmt->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  753. if(isset($dd[0]['number']))
  754. {
  755. $number = $dd[0]['number'];
  756. if($dd[0]['express'] != $express)
  757. {
  758. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  759. }
  760. }
  761. else
  762. {
  763. $dd = $this->fullordertt->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  764. if(isset($dd[0]['number']))
  765. {
  766. $number = $dd[0]['number'];
  767. if($dd[0]['express'] != $express)
  768. {
  769. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  770. }
  771. }
  772. else
  773. {
  774. $dd = $this->fullorderamz->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  775. if(isset($dd[0]['number']))
  776. {
  777. $number = $dd[0]['number'];
  778. if($dd[0]['express'] != $express)
  779. {
  780. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  781. }
  782. }
  783. else
  784. {
  785. $dd = $this->fullorderxw->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  786. if(isset($dd[0]['number']))
  787. {
  788. $number = $dd[0]['number'];
  789. if($dd[0]['express'] != $express)
  790. {
  791. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  792. }
  793. }
  794. else
  795. {
  796. echo json_encode(array('msg'=>'系统中未查到此编号,请确认!','success'=>false));exit;
  797. }
  798. }
  799. }
  800. }
  801. }
  802. $tmp_waybill = "";
  803. if(isset($dd[0]['waybill'])){
  804. $tmp_waybill= $dd[0]['waybill'];
  805. }
  806. if(($dd[0]['printtype'] != 2) && (!in_array($dd[0]['express'],[50,51,52,69,73])))
  807. {
  808. echo json_encode(array('msg'=>'请扫描正确的条码!','success'=>false));exit;
  809. }
  810. $nu = $this->outbound->get_number($number);
  811. if($nu)
  812. {
  813. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  814. }
  815. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'waybill'=>$tmp_waybill,'express'=>$express,'gtime'=>date('Ymd',time()),'time'=>$time)))
  816. {
  817. $data = $this->outbound->find_count($where);
  818. echo json_encode(array('msg'=>'添加成功!','success'=>true));exit;
  819. }
  820. else
  821. {
  822. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  823. }
  824. }
  825. /**
  826. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'waybill'=>$waybill,'express'=>$express,'gtime'=>date('Ymd',$time),'time'=>$time+1)))
  827. {
  828. echo json_encode(array('msg'=>'添加成功!','success'=>true));exit;
  829. }
  830. **/
  831. }
  832. }
  833. public function _del()
  834. {
  835. $post = $this->input->post(NULL, TRUE);
  836. if(isset($post['delarr']))
  837. {
  838. $id_arr = $this->input->post('delarr');
  839. $id_arr = explode(',',rtrim($id_arr,','));
  840. if(!$id_arr)
  841. {
  842. echo json_encode(array('msg'=>'未选择需要删除的内容!','success'=>false));exit;
  843. }
  844. //循环删除记录
  845. $a=0;
  846. foreach ($id_arr as $v)
  847. {
  848. if($this->outbound->remove($v))
  849. {
  850. $a++;
  851. }
  852. }
  853. if($a == count($id_arr))
  854. {
  855. $data = $this->outbound->find_count("gtime = '".date('Ymd',time())."'");
  856. echo json_encode(array('del'=>$id_arr,'data'=>$data,'msg'=>'删除成功!','success'=>true));
  857. }
  858. else
  859. {
  860. echo json_encode(array('del'=>$id_arr,'msg'=>'部分记录删除失败,请查询确认!','success'=>true));
  861. }
  862. }
  863. }
  864. public function _ex()
  865. {
  866. }
  867. public function _out()
  868. {
  869. $post = $this->input->post(NULL, TRUE);
  870. if(isset($post['number']))
  871. {
  872. $where = "gtime = '".date('Ymd',time())."'";
  873. $number = $this->input->post('number',true);
  874. $type = $this->input->post('type',true);
  875. $express = $this->input->post('express',true);
  876. if($_SESSION['api'])
  877. {
  878. if($type)
  879. {
  880. $where .= " and type = '$type'";
  881. }
  882. else
  883. {
  884. $uw = '';
  885. $u = $this->user->get_api($_SESSION['api']);
  886. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  887. foreach ($u['warehouse'] as $v)
  888. {
  889. $uw .= " type = '$v' or";
  890. }
  891. $uw = rtrim($uw,'or');
  892. $uw = " and (".ltrim($uw,' ').")";
  893. $where .= $uw;
  894. }
  895. }
  896. if(!$number)
  897. {
  898. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  899. }
  900. if(!$type)
  901. {
  902. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  903. }
  904. if(!$express)
  905. {
  906. echo json_encode(array('msg'=>'请选择需要录入的快递!','success'=>false));exit;
  907. }
  908. $sex = $this->express->read($express);
  909. if(stripos($number,'-') === false)
  910. {
  911. if(substr($number,0,3) == '788' && substr($number,-4,4) == '0430')//Fedex联邦
  912. {
  913. $number = substr($number,0,12);
  914. }
  915. if(strlen($number) == '34')//联邦杭州超长运单截取
  916. {
  917. //$number = substr($number,22,12);
  918. $str = substr($number, 0,3);
  919. if($str == "420"){
  920. $number = substr($number,12);
  921. }else{
  922. $number = substr($number,22,12);
  923. }
  924. }
  925. /**
  926. $ex = array('DHL'=>10,'FEDEX'=>12,'FEDEXGF'=>12,'UPS'=>18,'GES'=>17,'TNT'=>9,'ARAMEX'=>11,'EMS_ZX_ZX_US'=>13);
  927. if(isset($ex[$sex['printcode']]))
  928. {
  929. if(strlen($number) != $ex[$sex['printcode']])
  930. {
  931. echo json_encode(array('msg'=>'运单号错误,此单请重新录入运单号!','success'=>false));exit;
  932. }
  933. }
  934. **/
  935. 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')
  936. {
  937. echo json_encode(array('msg'=>'运单号和快递类型不符!F','success'=>false));exit;
  938. }
  939. 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')
  940. {
  941. echo json_encode(array('msg'=>'运单号和快递类型不符!D','success'=>false));exit;
  942. }
  943. 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')
  944. {
  945. echo json_encode(array('msg'=>'运单号和快递类型不符!U'.$sex['printcode'],'success'=>false));exit;
  946. }
  947. if(strlen($number) == 16 && $sex['printcode'] != '3PE_XB' && $sex['printcode'] != 'TTUK' && $sex['printcode'] != 'TTUS' && $sex['printcode'] != 'TTSP' && $sex['printcode'] != 'TTSP-Fedex')
  948. {
  949. echo json_encode(array('msg'=>'运单号和快递类型不符!PE'.$sex['printcode'],'success'=>false));exit;
  950. }
  951. // $r = $this->logic_express->ydCheckByPrintcode($number,$sex['printcode']);
  952. // if(!$r){
  953. // echo json_encode(array('msg'=>'运单号和快递类型不符-'.$sex['printcode'],'success'=>false));exit;
  954. // }
  955. $yd = $this->fullorder->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  956. if(isset($yd[0]['number']))
  957. {
  958. $number = $yd[0]['number'];
  959. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  960. {
  961. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  962. }
  963. }
  964. else
  965. {
  966. $yd = $this->fullordersmt->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  967. if(isset($yd[0]['number']))
  968. {
  969. $number = $yd[0]['number'];
  970. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  971. {
  972. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  973. }
  974. }
  975. else
  976. {
  977. $yd = $this->fullordertt->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  978. if(isset($yd[0]['number']))
  979. {
  980. $number = $yd[0]['number'];
  981. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  982. {
  983. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  984. }
  985. }
  986. else
  987. {
  988. $yd = $this->fullorderamz->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  989. if(isset($yd[0]['number']))
  990. {
  991. $number = $yd[0]['number'];
  992. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  993. {
  994. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  995. }
  996. }
  997. else
  998. {
  999. $yd = $this->fullorderxw->find_all("waybill = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  1000. if(isset($yd[0]['number']))
  1001. {
  1002. $number = $yd[0]['number'];
  1003. if($yd[0]['express'] != $express && $yd[0]['express'] != 31)
  1004. {
  1005. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  1006. }
  1007. }
  1008. else
  1009. {
  1010. echo json_encode(array('msg'=>'系统中未查到此运单,请确认!'.$number,'success'=>false));exit;
  1011. }
  1012. }
  1013. }
  1014. }
  1015. }
  1016. /**
  1017. if($yd[0]['printtype'] != 1)
  1018. {
  1019. echo json_encode(array('msg'=>'请扫描正确的运单号!','success'=>false));exit;
  1020. }
  1021. **/
  1022. //再次判断下杭州不报关的类别是否满足条件 如果有影响可以删除
  1023. if($yd[0]['express'] != $express){
  1024. echo json_encode(array('msg'=>'录入信息和选择快递不一致!2','success'=>false));exit;
  1025. }
  1026. $nu = $this->outbound->get_number($number);
  1027. if($nu)
  1028. {
  1029. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  1030. }
  1031. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'waybill'=>$yd[0]['waybill'],'express'=>$yd[0]['express'],'gtime'=>date('Ymd',time()),'time'=>time())))
  1032. {
  1033. $data = $this->outbound->find_count($where);
  1034. echo json_encode(array('msg'=>$data,'music'=>'1','success'=>true));exit;
  1035. }
  1036. else
  1037. {
  1038. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  1039. }
  1040. }
  1041. else
  1042. {
  1043. $dd = $this->fullorder->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  1044. if(isset($dd[0]['number']))
  1045. {
  1046. if($dd[0]['express'] != $express)
  1047. {
  1048. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  1049. }
  1050. }
  1051. else
  1052. {
  1053. $dd = $this->fullordersmt->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  1054. if(isset($dd[0]['number']))
  1055. {
  1056. $number = $dd[0]['number'];
  1057. if($dd[0]['express'] != $express)
  1058. {
  1059. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  1060. }
  1061. }
  1062. else
  1063. {
  1064. $dd = $this->fullordertt->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  1065. if(isset($dd[0]['number']))
  1066. {
  1067. $number = $dd[0]['number'];
  1068. if($dd[0]['express'] != $express)
  1069. {
  1070. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  1071. }
  1072. }
  1073. else
  1074. {
  1075. $dd = $this->fullorderamz->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  1076. if(isset($dd[0]['number']))
  1077. {
  1078. $number = $dd[0]['number'];
  1079. if($dd[0]['express'] != $express)
  1080. {
  1081. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  1082. }
  1083. }
  1084. else
  1085. {
  1086. $dd = $this->fullorderxw->find_all("number = '$number' and library = '2' and librarytime > '".(time()-30*24*3600)."'");
  1087. if(isset($dd[0]['number']))
  1088. {
  1089. $number = $dd[0]['number'];
  1090. if($dd[0]['express'] != $express)
  1091. {
  1092. echo json_encode(array('msg'=>'录入信息和选择快递不一致!','success'=>false));exit;
  1093. }
  1094. }
  1095. else
  1096. {
  1097. echo json_encode(array('msg'=>'系统中未查到此编号,请确认!','success'=>false));exit;
  1098. }
  1099. }
  1100. }
  1101. }
  1102. }
  1103. //惠程-美国USPS 惠程-联邦 惠程-安迈世 惠程-DHL 惠程-GES(欧盟)
  1104. if(($dd[0]['printtype'] != 2) && (!in_array($dd[0]['express'],[50,51,52,69,73,75])))
  1105. {
  1106. echo json_encode(array('msg'=>'请扫描正确的条码!','success'=>false));exit;
  1107. }
  1108. //判断该订单的快递单号是否存在 如果不存在提示 补齐快递单号 在进行扫描
  1109. // if(empty($dd[0]['waybill'])){
  1110. // echo json_encode(array('msg'=>'该订单未检索到快递信息,请补齐快递单号!','success'=>false));exit;
  1111. // }
  1112. $nu = $this->outbound->get_number($number);
  1113. if($nu)
  1114. {
  1115. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  1116. }
  1117. if($this->outbound->insert(array('type'=>$type,'number'=>$number,'waybill'=>$dd[0]['waybill'],'express'=>$dd[0]['express'],'gtime'=>date('Ymd',time()),'time'=>time())))
  1118. {
  1119. $data = $this->outbound->find_count($where);
  1120. echo json_encode(array('msg'=>$data,'music'=>'1','success'=>true));exit;
  1121. }
  1122. else
  1123. {
  1124. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  1125. }
  1126. }
  1127. }
  1128. }
  1129. public function _dcall(){
  1130. if(isset($_GET['fexcel']))
  1131. {
  1132. $timetk = $this->input->get('timetk',true);
  1133. $timetj = $this->input->get('timetj',true);
  1134. $library = $this->input->get('library',true);
  1135. $type = $this->input->get('type',true);
  1136. $number = $this->input->get('number',true);
  1137. $waybill = $this->input->get('waybill',true);
  1138. $timetk = strtotime($timetk);
  1139. $timetj = strtotime($timetj);
  1140. $typename = "订单计数";
  1141. // $cx_arr = [78,79];
  1142. // $ex_list = $this->express->find_all("id in (".implode(',',$cx_arr).")","id,servicename");
  1143. // $where = "type != 0 and express in (".implode(',',$cx_arr).")";
  1144. $where = " type != 0 ";
  1145. if($timetk && $timetj)
  1146. {
  1147. $where .= " and time > '$timetk' and time < '$timetj'";
  1148. }
  1149. if(isset($_SESSION['api']))
  1150. {
  1151. if($type)
  1152. {
  1153. $where .= " and type = '$type'";
  1154. }
  1155. else
  1156. {
  1157. $uw = '';
  1158. $u = $this->user->get_api($_SESSION['api']);
  1159. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  1160. foreach ($u['warehouse'] as $v)
  1161. {
  1162. $uw .= " type = '$v' or";
  1163. }
  1164. $uw = rtrim($uw,'or');
  1165. $uw = " and (".ltrim($uw,' ').")";
  1166. $where .= $uw;
  1167. }
  1168. }
  1169. else
  1170. {
  1171. echo json_encode(array('msg'=>'导出失败,请重新登陆!','success'=>false));exit;
  1172. }
  1173. if($number)
  1174. {
  1175. $where .= " and number = '$number'";
  1176. }
  1177. if($waybill)
  1178. {
  1179. $where .= " and waybill = '$waybill'";
  1180. }
  1181. $data = array();
  1182. $datafy = array();
  1183. $j = 0;
  1184. $info_list = $this->outbound->find_all($where,'number,waybill,express','time asc');
  1185. $express_ids = array_unique(array_column($info_list,'express'));
  1186. $express_ids = array_values($express_ids);
  1187. $ex_list = $this->express->find_all("id in (".implode(',',$express_ids).")","id,servicename",'id asc');
  1188. $final_list= [
  1189. ];
  1190. foreach($ex_list as $v){
  1191. $final_list[$v['id']] = [];
  1192. }
  1193. foreach ($info_list as $key=>$value)
  1194. {
  1195. if(isset($final_list[$value['express']])){
  1196. $orderinfo = $this->logic_order->getInfo('number = "'.$value['number'].'"');
  1197. $weight = 0;
  1198. if(!empty($orderinfo)){
  1199. $weight = $orderinfo['weight'];
  1200. }
  1201. $weight = str_replace('kgkg','kg',$weight);
  1202. $final_list[$value['express']][] = [
  1203. $value['number'],
  1204. $value['waybill'],
  1205. $weight
  1206. ];
  1207. }
  1208. }
  1209. $data[] = $datafy;
  1210. //格式化数据
  1211. $i = 0;$cpexcel = array();
  1212. $title = date('Ymd',time()).$typename."发货统计信息"; $td = '';
  1213. $td = "";
  1214. $count = 0;
  1215. foreach($ex_list as $v){
  1216. $num = count($final_list[$v['id']]);
  1217. if($num > $count){
  1218. $count = $num;
  1219. }
  1220. $td .= "<td>".$v['servicename']."</td><td>总数(".$num.")</td><td>重量</td>";
  1221. }
  1222. foreach($final_list as $k=>$v){
  1223. for($i=0;$i < $count ;$i++){
  1224. if(!isset($final_list[$k][$i])){
  1225. $final_list[$k][$i] = [
  1226. " "," ",""
  1227. ];
  1228. }
  1229. }
  1230. }
  1231. $titlename = "<table border=1>
  1232. <tr>
  1233. ".$td."
  1234. </tr>
  1235. </table>";
  1236. $filename = $title.".xls";
  1237. $this->excel->get_fz7($final_list,$titlename,$filename);
  1238. }
  1239. }
  1240. }