Systembound.php 37 KB

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