Systembox.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. header("Access-Control-Allow-Origin: *");
  3. class Systembox extends Start_Controller {
  4. public function __construct(){
  5. parent::__construct();
  6. $this->load->library('session');
  7. $this->load->_model('Model_systembox','systembox');
  8. $this->load->_model('Model_systemboxclassid','systemboxclassid');
  9. $this->load->_model('Model_excel','excel');
  10. $this->load->_model('Model_express','express');
  11. $this->load->_model('Model_shop','shop');
  12. $this->load->_model('Model_warehouse','warehouse');
  13. $this->load->_model('Model_fullorder','fullorder');
  14. $this->load->_model('Model_fullordertt','fullordertt');
  15. $this->load->_model('Model_fullordersmt','fullordersmt');
  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 if($arg == 'sh')
  41. {
  42. $this->_sh();
  43. }
  44. else if($arg == 'classid')
  45. {
  46. $this->_classid();
  47. }
  48. else if($arg == 'rk')
  49. {
  50. $this->_rk();
  51. }
  52. else
  53. {
  54. $this->_index();
  55. }
  56. }
  57. public function _index()
  58. {
  59. if(isset($_SESSION['api']))
  60. {
  61. $user = $this->user->get_api($_SESSION['api']);
  62. $usp = $user;
  63. $fgshop = "";$sid = "";$wid="";$wtype="";
  64. $usersp = explode('|',trim($user['shop'],'|'));
  65. $userwh = explode('|',trim($user['warehouse'],'|'));
  66. foreach ($usersp as $value)
  67. {
  68. $fgshop .= " shop = ".$value." or";
  69. $sid .= " id = ".$value." or";
  70. }
  71. foreach ($userwh as $value)
  72. {
  73. $wid .= " id = ".$value." or";
  74. $wtype .= " type = ".$value." or";
  75. }
  76. }
  77. if(isset($_SESSION['api']))
  78. {
  79. $warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");
  80. $this->data['warehouse'] = $warehouse;
  81. $this->data['vip'] = $user['vip'];
  82. }
  83. $systemboxclassid = $this->systemboxclassid->find_all('1=1','*','id desc','0','20');
  84. $this->data['systemboxclassid'] = $systemboxclassid;
  85. $this->data['time'] = date('YmdHis',time());
  86. $this->_Template('systembox',$this->data);
  87. }
  88. public function _sh()
  89. {
  90. if(isset($_SESSION['api']))
  91. {
  92. $user = $this->user->get_api($_SESSION['api']);
  93. $usp = $user;
  94. $fgshop = "";$sid = "";$wid="";$wtype="";
  95. $usersp = explode('|',trim($user['shop'],'|'));
  96. $userwh = explode('|',trim($user['warehouse'],'|'));
  97. foreach ($usersp as $value)
  98. {
  99. $fgshop .= " shop = ".$value." or";
  100. $sid .= " id = ".$value." or";
  101. }
  102. foreach ($userwh as $value)
  103. {
  104. $wid .= " id = ".$value." or";
  105. $wtype .= " type = ".$value." or";
  106. }
  107. }
  108. if(isset($_SESSION['api']))
  109. {
  110. $warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");
  111. $this->data['warehouse'] = $warehouse;
  112. $this->data['vip'] = $user['vip'];
  113. }
  114. $post = $this->input->post(NULL, TRUE);
  115. if(isset($post['page']))
  116. {
  117. $api = $this->input->post('api',true);
  118. $page = $this->input->post('page',true);
  119. $perpage = $this->input->post('perpage',true);
  120. $number = $this->input->post('number',true);
  121. $warehouse = $this->input->post('warehouse',true);
  122. $zt = $this->input->post('zt',true);
  123. $systemboxclassid = $this->input->post('classid',true);
  124. $timetk = $this->input->post('timetk',true);
  125. $timetj = $this->input->post('timetj',true);
  126. $timetk = strtotime($timetk);
  127. $timetj = strtotime($timetj);
  128. $where = "1 = 1";
  129. if($timetk && $timetj)
  130. {
  131. $where .= " and time > '$timetk' and time < '$timetj'";
  132. }
  133. if($number)
  134. {
  135. $where .= " and number = '$number'";
  136. }
  137. /**
  138. if($warehouse)
  139. {
  140. $where .= " and warehouse = '$warehouse'";
  141. }
  142. **/
  143. if($zt == '0')
  144. {
  145. $where .= " and shtime = '$zt'";
  146. }
  147. if($zt == '1')
  148. {
  149. $where .= " and shtime != '0'";
  150. }
  151. if($systemboxclassid)
  152. {
  153. $where .= " and systemboxclassid = '$systemboxclassid'";
  154. }
  155. //数据排序
  156. $order_str = "id desc";
  157. if(empty($page))
  158. {
  159. $start = 0;
  160. $perpage = 1;
  161. }
  162. else
  163. {
  164. $start = ($page - 1)*$perpage;
  165. }
  166. //取得信息列表
  167. $info_list = $this->systembox->find_all($where,'id,warehouse,systemboxclassid,number,time,shwarehouse,shtime',$order_str,$start,$perpage);
  168. //格式化数据
  169. foreach ($info_list as $key=>$value)
  170. {
  171. $warehouse = $this->warehouse->read($value['warehouse']);
  172. $shwarehouse = $this->warehouse->read($value['shwarehouse']);
  173. $info_list[$key]['warehouse'] = $warehouse['title'];
  174. $info_list[$key]['time'] = '<em class="t">'.date('Y-m-d H:i:s',$value['time']).'</em>';
  175. if($value['shtime'] != '0')
  176. {
  177. $info_list[$key]['shwarehouse'] = $shwarehouse['title'];
  178. $info_list[$key]['shtime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['shtime']).'</em>';
  179. }
  180. else
  181. {
  182. $info_list[$key]['shwarehouse'] = '';
  183. $info_list[$key]['shtime'] = '';
  184. }
  185. }
  186. $datacount = $this->systembox->find_count($where." and gtime = '".date('Ymd',time())."'");
  187. $total = $this->systembox->find_count($where);
  188. $pagenum = ceil($total/$perpage);
  189. $over = $total-($start+$perpage);
  190. $num = $this->systembox->find_count("systemboxclassid = '$systemboxclassid'");
  191. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'num'=>$num);
  192. echo json_encode($rows);exit;
  193. }
  194. $systemboxclassid = $this->systemboxclassid->find_all('1=1','*','id desc','0','20');
  195. $this->data['systemboxclassid'] = $systemboxclassid;
  196. $this->data['time'] = date('YmdHis',time());
  197. $this->_Template('systembox_sh',$this->data);
  198. }
  199. public function _data()
  200. {
  201. $post = $this->input->post(NULL, TRUE);
  202. if(isset($post['page']))
  203. {
  204. $api = $this->input->post('api',true);
  205. $page = $this->input->post('page',true);
  206. $perpage = $this->input->post('perpage',true);
  207. $number = $this->input->post('number',true);
  208. $warehouse = $this->input->post('warehouse',true);
  209. $zt = $this->input->post('zt',true);
  210. $systemboxclassid = $this->input->post('classid',true);
  211. $timetk = $this->input->post('timetk',true);
  212. $timetj = $this->input->post('timetj',true);
  213. $timetk = strtotime($timetk);
  214. $timetj = strtotime($timetj);
  215. $where = "1 = 1";
  216. if($timetk && $timetj)
  217. {
  218. $where .= " and time > '$timetk' and time < '$timetj'";
  219. }
  220. if($number)
  221. {
  222. $where .= " and number = '$number'";
  223. }
  224. if($warehouse)
  225. {
  226. $where .= " and warehouse = '$warehouse'";
  227. }
  228. if($zt == '0')
  229. {
  230. $where .= " and shtime = '$zt'";
  231. }
  232. if($zt == '1')
  233. {
  234. $where .= " and shtime != '0'";
  235. }
  236. if($systemboxclassid)
  237. {
  238. $where .= " and systemboxclassid = '$systemboxclassid'";
  239. }
  240. //数据排序
  241. $order_str = "id desc";
  242. if(empty($page))
  243. {
  244. $start = 0;
  245. $perpage = 1;
  246. }
  247. else
  248. {
  249. $start = ($page - 1)*$perpage;
  250. }
  251. //取得信息列表
  252. $info_list = $this->systembox->find_all($where,'id,warehouse,systemboxclassid,number,time,shwarehouse,shtime',$order_str,$start,$perpage);
  253. //格式化数据
  254. foreach ($info_list as $key=>$value)
  255. {
  256. $warehouse = $this->warehouse->read($value['warehouse']);
  257. $shwarehouse = $this->warehouse->read($value['shwarehouse']);
  258. $info_list[$key]['warehouse'] = $warehouse['title'];
  259. $info_list[$key]['time'] = '<em class="t">'.date('Y-m-d H:i:s',$value['time']).'</em>';
  260. if($value['shtime'] != '0')
  261. {
  262. $info_list[$key]['shwarehouse'] = $shwarehouse['title'];
  263. $info_list[$key]['shtime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['shtime']).'</em>';
  264. }
  265. else
  266. {
  267. $info_list[$key]['shwarehouse'] = '';
  268. $info_list[$key]['shtime'] = '';
  269. }
  270. }
  271. $datacount = $this->systembox->find_count($where." and gtime = '".date('Ymd',time())."'");
  272. $total = $this->systembox->find_count($where);
  273. $pagenum = ceil($total/$perpage);
  274. $over = $total-($start+$perpage);
  275. $num = $this->systembox->find_count("systemboxclassid = '$systemboxclassid'");
  276. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'num'=>$num);
  277. echo json_encode($rows);exit;
  278. }
  279. }
  280. public function _out()
  281. {
  282. $post = $this->input->post(NULL, TRUE);
  283. if(isset($post['number']))
  284. {
  285. $time = time();
  286. $where = "gtime = '".date('Ymd',time())."'";
  287. $number = $this->input->post('number',true);
  288. $systemboxclassid = $this->input->post('systemboxclassid',true);
  289. $warehouse = $this->input->post('warehouse',true);
  290. if(!$number)
  291. {
  292. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  293. }
  294. if(!$warehouse)
  295. {
  296. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  297. }
  298. $classid = $this->systemboxclassid->get_box($systemboxclassid);
  299. if(!$classid)
  300. {
  301. if(!$this->systemboxclassid->insert(array('box'=>$systemboxclassid,'gtime'=>date('Ymd',$time),'time'=>$time)))
  302. {
  303. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  304. }
  305. }
  306. if($this->systembox->insert(array('warehouse'=>$warehouse,'number'=>$number,'systemboxclassid'=>$systemboxclassid,'gtime'=>date('Ymd',$time),'time'=>$time)))
  307. {
  308. $data = $this->systembox->find_count($where);
  309. echo json_encode(array('msg'=>$data,'music'=>'1','success'=>true));exit;
  310. }
  311. else
  312. {
  313. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  314. }
  315. }
  316. }
  317. public function _rk()
  318. {
  319. $post = $this->input->post(NULL, TRUE);
  320. if(isset($post['number']))
  321. {
  322. $time = time();
  323. $number = $this->input->post('number',true);
  324. $systemboxclassid = $this->input->post('systemboxclassid',true);
  325. $warehouse = $this->input->post('warehouse',true);
  326. if(!$number)
  327. {
  328. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  329. }
  330. if(!$warehouse)
  331. {
  332. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  333. }
  334. if(!$systemboxclassid)
  335. {
  336. echo json_encode(array('msg'=>'需要先扫描箱号!','success'=>false));exit;
  337. }
  338. $data = $this->systembox->get_data($number,$systemboxclassid);
  339. if(!$data)
  340. {
  341. echo json_encode(array('msg'=>'箱号:'.$systemboxclassid.'中没未找到此产品','success'=>false));exit;
  342. }
  343. if($this->systembox->save(array('shwarehouse'=>$warehouse,'shgtime'=>date('Ymd',$time),'shtime'=>$time),$data['id']))
  344. {
  345. $sl = $this->systembox->find_count("systemboxclassid = '$systemboxclassid' and shtime = '0'");
  346. echo json_encode(array('msg'=>$data,'music'=>'1','sl'=>'箱号'.$systemboxclassid.'未扫码数量:'.$sl,'success'=>true));exit;
  347. }
  348. else
  349. {
  350. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  351. }
  352. }
  353. }
  354. public function _classid()
  355. {
  356. $post = $this->input->post(NULL, TRUE);
  357. if(isset($post['systemboxclassid']))
  358. {
  359. $systemboxclassid = $this->input->post('systemboxclassid',true);
  360. $box = $this->systemboxclassid->get_box($systemboxclassid);
  361. if(!$box)
  362. {
  363. echo json_encode(array('msg'=>'箱号错误!','success'=>false));exit;
  364. }
  365. $sl = $this->systembox->find_count("systemboxclassid = '$systemboxclassid' and shtime = '0'");
  366. echo json_encode(array('music'=>'1','sl'=>'箱号'.$systemboxclassid.'未扫码数量:'.$sl,'success'=>true));exit;
  367. }
  368. }
  369. public function _excel()
  370. {
  371. if(isset($_GET['fexcel']))
  372. {
  373. $classid = $this->input->get('classid',true);
  374. $warehouse = $this->input->get('warehouse',true);
  375. $timetk = $this->input->get('timetk',true);
  376. $timetj = $this->input->get('timetj',true);
  377. $timetk = strtotime($timetk);
  378. $timetj = strtotime($timetj);
  379. $where = "1=1";
  380. if($timetk && $timetj)
  381. {
  382. $where .= " and time > '$timetk' and time < '$timetj'";
  383. }
  384. if($classid)
  385. {
  386. $where .= " and systemboxclassid = '$classid'";
  387. }
  388. if($warehouse)
  389. {
  390. $where .= " and warehouse = '$warehouse'";
  391. }
  392. $data = array();
  393. $datafy = array();
  394. $j = '';
  395. $info_list = $this->systembox->find_all($where,'number,warehouse,time,shwarehouse,shtime');
  396. foreach ($info_list as $key=>$value)
  397. {
  398. $warehouse = $this->warehouse->read($value['warehouse']);
  399. $warehouse = $warehouse['title'];
  400. if($value['shwarehouse'])
  401. {
  402. $shwarehouse = $this->warehouse->read($value['shwarehouse']);
  403. $shwarehouse = $shwarehouse['title'];
  404. $j.= "<tr><td align='left'>".$value['number']."</td><td align='left'>".$warehouse."</td><td align='left'>".date('Y-m-d H:i:s',$value['time'])."</td><td align='left'>".$shwarehouse."</td><td align='left'>".date('Y-m-d H:i:s',$value['shtime'])."</td></tr>";
  405. }
  406. else
  407. {
  408. $j.= "<tr><td align='left'>".$value['number']."</td><td align='left'>".$warehouse."</td><td align='left'>".date('Y-m-d H:i:s',$value['time'])."</td><td align='left'></td><td align='left'></td></tr>";
  409. }
  410. }
  411. $data[] = $datafy;
  412. //格式化数据
  413. $i = 0;$cpexcel = array();
  414. $title = "箱号".$classid.'统计信息'; $td = '';
  415. $titlename = "<table border=1>
  416. <tr><th colspan='5' align='left'><h3>箱号".$classid.' - 总数量:'.count($info_list)."<h3></th></tr>
  417. <tr><td>编号</td><td>发货仓库</td><td>发货扫码时间</td><td>收货仓库</td><td>收货扫码时间</td></tr>
  418. ".$j."
  419. </table>";
  420. $filename = $title.".xls";
  421. $this->excel->get_fz6($data,$titlename,$filename);
  422. }
  423. }
  424. public function _add()
  425. {
  426. $post = $this->input->post(NULL, TRUE);
  427. if(isset($post['number']))
  428. {
  429. $where = "gtime = '".date('Ymd',time())."'";
  430. $number = $this->input->post('number',true);
  431. $waybill = $this->input->post('waybill',true);
  432. $id = $this->input->post('id',true);
  433. $type = $this->input->post('type',true);
  434. $express = $this->input->post('express',true);
  435. $time = $this->input->post('time',true);
  436. $time = strtotime($time);
  437. if($id)
  438. {
  439. if($type)
  440. {
  441. $where .= " and type = '$type'";
  442. }
  443. else
  444. {
  445. $uw = '';
  446. $u = $this->user->get_api($id);
  447. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  448. foreach ($u['warehouse'] as $v)
  449. {
  450. $uw .= " type = '$v' or";
  451. }
  452. $uw = rtrim($uw,'or');
  453. $uw = " and (".ltrim($uw,' ').")";
  454. $where .= $uw;
  455. }
  456. }
  457. if(!$number)
  458. {
  459. echo json_encode(array('msg'=>'编号不能为空!','success'=>false));exit;
  460. }
  461. if(!$waybill)
  462. {
  463. echo json_encode(array('msg'=>'运单号不能为空!','success'=>false));exit;
  464. }
  465. if(!$type)
  466. {
  467. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  468. }
  469. if(!$express)
  470. {
  471. echo json_encode(array('msg'=>'请选择需要录入的快递!','success'=>false));exit;
  472. }
  473. $nu = $this->systembox->get_number($number);
  474. if($nu)
  475. {
  476. echo json_encode(array('msg'=>'错误!此编号'.date('Ymd',$nu['time']).'已录入!','success'=>false));exit;
  477. }
  478. $wa = $this->systembox->get_waybill($waybill);
  479. if($wa)
  480. {
  481. echo json_encode(array('msg'=>'错误!此运单号'.date('Ymd',$wa['time']).'已录入!','success'=>false));exit;
  482. }
  483. $sex = $this->express->read($express);
  484. $ex = array('DHL'=>10,'FEDEX'=>12,'FEDEXGF'=>12,'UPS'=>18,'GES'=>17,'TNT'=>9,'ARAMEX'=>11,'EMS_ZX_ZX_US'=>13);
  485. if(isset($ex[$sex['printcode']]))
  486. {
  487. if(strlen($waybill) != $ex[$sex['printcode']])
  488. {
  489. echo json_encode(array('msg'=>'运单号错误,此单请重新录入运单号!','success'=>false));exit;
  490. }
  491. }
  492. if($this->systembox->insert(array('type'=>$type,'number'=>$number,'waybill'=>$waybill,'express'=>$express,'gtime'=>date('Ymd',$time),'time'=>$time+1)))
  493. {
  494. echo json_encode(array('msg'=>'添加成功!','success'=>true));exit;
  495. }
  496. }
  497. }
  498. public function _del()
  499. {
  500. $post = $this->input->post(NULL, TRUE);
  501. if(isset($post['delarr']))
  502. {
  503. $id_arr = $this->input->post('delarr');
  504. $id_arr = explode(',',rtrim($id_arr,','));
  505. if(!$id_arr)
  506. {
  507. echo json_encode(array('msg'=>'未选择需要删除的内容!','success'=>false));exit;
  508. }
  509. //循环删除记录
  510. $a=0;
  511. foreach ($id_arr as $v)
  512. {
  513. if($this->systembox->remove($v))
  514. {
  515. $a++;
  516. }
  517. }
  518. if($a == count($id_arr))
  519. {
  520. $data = $this->systembox->find_count("gtime = '".date('Ymd',time())."'");
  521. echo json_encode(array('del'=>$id_arr,'data'=>$data,'msg'=>'删除成功!','success'=>true));
  522. }
  523. else
  524. {
  525. echo json_encode(array('del'=>$id_arr,'msg'=>'部分记录删除失败,请查询确认!','success'=>true));
  526. }
  527. }
  528. }
  529. public function _ex()
  530. {
  531. }
  532. }