Systemfoutfz.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. header("Access-Control-Allow-Origin: *");
  3. class Systemfoutfz extends Start_Controller {
  4. public function __construct(){
  5. parent::__construct();
  6. $this->load->library('session');
  7. $this->load->_model('Model_whlabel','whlabel');
  8. $this->load->_model('Model_warehouse','warehouse');
  9. $this->load->_model('Model_productprice','productprice');
  10. $this->load->_model('Model_excel','excel');
  11. $this->load->_model('Model_fullorder','fullorder');
  12. $this->load->_model('Model_fullordertt','fullordertt');
  13. $this->load->_model('Model_fullorderamz','fullorderamz');
  14. $this->load->_model('Model_fullordersmt','fullordersmt');
  15. $this->load->_model('Model_outbound','outbound');
  16. $this->load->_model('Model_express','express');
  17. $this->load->_model('Model_shop','shop');
  18. $this->load->_model('Model_typeclass','typeclass');
  19. $this->load->_model('Model_country','country');
  20. $this->load->_model('Model_kdniao','kdniao');
  21. $this->load->_model('Model_notice','notice');
  22. $this->load->_model('Model_dhl','dhl');
  23. $this->load->_model('Model_dhlhz','dhlhz');
  24. $this->load->_model('Model_usps','usps');
  25. $this->load->_model('Model_fedex','fedex');
  26. $this->load->_model('Model_fedex_cby','fedex_cby');
  27. $this->load->_model('Model_ups','ups');
  28. $this->load->_model('Model_ali','ali');
  29. $this->load->_model('Model_dpd','dpd');
  30. $this->load->_model('Model_shop','shop');
  31. $this->load->_model('Model_user','user');
  32. $this->load->_model('Model_whlabel','whlabel');
  33. $this->load->_model('Model_specialstock','specialstock');
  34. $this->load->_model('Model_ck','ck');
  35. $this->load->_model('Model_whlabellabel','whlabellabel');
  36. $this->load->_model('Model_apiyy','apiyy');
  37. $this->load->helper('url');
  38. $this->load->_model('Model_whlabel_fc','whlabel_fc');
  39. $this->load->_model('Model_systemtransfer','systemtransfer');
  40. $this->load->_model('Model_classid','classid');
  41. $this->load->_model('Model_allocation','allocation');
  42. $this->load->_model('Model_fullorderxw','fullorderxw');
  43. $this->load->_model('Model_fullorderpaypal','fullorderpaypal');
  44. $this->load->_model("Model_logic_ding","logic_ding");
  45. $this->load->_model("Model_fedexv1",'fedexv1');
  46. $this->load->_model("Model_zzquque_u9","zzquque_u9");
  47. $this->load->_model("Model_customsdeclaration","customsdeclaration");
  48. }
  49. //定义方法的调用规则 获取URI第二段值
  50. public function _remap($arg,$arg_array)
  51. {
  52. if($arg == 'exceltwo')
  53. {
  54. $this->_exceltwo($arg_array);
  55. }
  56. else
  57. {
  58. $this->_index();
  59. }
  60. }
  61. public function _exceltwo($arg_array)
  62. {
  63. if(isset($_SESSION['api']))
  64. {
  65. $user = $this->user->get_api($_SESSION['api']);
  66. $usp = $user;
  67. $fgshop = "";$sid = "";$wid="";$wtype="";
  68. $usersp = explode('|',trim($user['shop'],'|'));
  69. $userwh = explode('|',trim($user['warehouse'],'|'));
  70. foreach ($usersp as $value)
  71. {
  72. $fgshop .= " shop = ".$value." or";
  73. $sid .= " id = ".$value." or";
  74. }
  75. foreach ($userwh as $value)
  76. {
  77. $wid .= " id = ".$value." or";
  78. $wtype .= " type = ".$value." or";
  79. }
  80. if($user['userid'] == 'xw')
  81. {
  82. $xw = 1;
  83. }
  84. }
  85. if(isset($_GET['fexcel']))
  86. {
  87. $dowid = $this->input->get('a');
  88. $wid = "";
  89. if($dowid != "")
  90. {
  91. $id_arr = explode(',',rtrim($dowid,','));
  92. foreach ($id_arr as $v)
  93. {
  94. $wid .= " id = '$v' or";
  95. }
  96. $wid = " and".rtrim($wid,'or');
  97. }
  98. $t = $this->input->get('t',true);
  99. $timetk = $this->input->get('timetk',true);
  100. $timetj = $this->input->get('timetj',true);
  101. $shop = $this->input->get('shop',true);
  102. $source = $this->input->get('source',true);
  103. $orderinfo = $this->input->get('orderinfo',true);
  104. $number = $this->input->get('number',true);
  105. $library = $this->input->get('library',true);
  106. $waybill = $this->input->get('waybill',true);
  107. $express = $this->input->get('express',true);
  108. $type = $this->input->get('type',true);
  109. $so = $this->input->get('so',true);
  110. $timetk = strtotime($timetk);
  111. $timetj = strtotime($timetj);
  112. $where = (isset($_SESSION['api']))?"library!=3 and libraryconfirm=2 and print = 3 and (".rtrim($wtype,'or').")":"id = '0'";
  113. if($timetk && $timetj && $library == 1)
  114. {
  115. //$cxtime = 'reviewtime';
  116. $where .= " and printtime > '$timetk - 180*24*3600' and printtime < '$timetj'";
  117. $where .= " and state != 217";
  118. }
  119. else if($timetk && $timetj && $library == 2)
  120. {
  121. $cxtime = 'librarytime';
  122. $where .= " and librarytime > '$timetk' and librarytime < '$timetj'";
  123. }
  124. if(isset($_SESSION['api']))
  125. {
  126. if($type)
  127. {
  128. $where .= " and type = '$type'";
  129. }
  130. else
  131. {
  132. $uw = '';
  133. $u = $this->user->get_api($_SESSION['api']);
  134. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  135. foreach ($u['warehouse'] as $v)
  136. {
  137. $uw .= " type = '$v' or";
  138. }
  139. $uw = rtrim($uw,'or');
  140. $uw = " and (".ltrim($uw,' ').")";
  141. $where .= $uw;
  142. }
  143. }
  144. else
  145. {
  146. echo json_encode(array('msg'=>'导出失败,请重新登陆!','success'=>false));exit;
  147. }
  148. if($shop)
  149. {
  150. $where .= " and shop = '$shop'";
  151. }
  152. if($number)
  153. {
  154. $where .= " and number = '$number'";
  155. }
  156. if($library)
  157. {
  158. $where .= " and library = '$library'";
  159. }
  160. if($waybill)
  161. {
  162. $where .= " and waybill = '$waybill'";
  163. }
  164. if($express)
  165. {
  166. $where .= " and express = '$express'";
  167. }
  168. if($orderinfo)
  169. {
  170. $where .= " and orderinfo = '$orderinfo'";
  171. }
  172. if($so)
  173. {
  174. $where .= " and shipremarks like '%$so%'";
  175. }
  176. //数据排序
  177. //$order_str = ($print != 3)?"id desc":"librarytime desc";
  178. $order_str = "librarytime desc";
  179. if(empty($page))
  180. {
  181. $start = 0;
  182. $perpage = 1;
  183. }
  184. else
  185. {
  186. $start = ($page - 1)*$perpage;
  187. }
  188. $typeclass = array();
  189. $tclass = $this->typeclass->find_all();
  190. foreach ($tclass as $v)
  191. {
  192. $typeclass[$v['id']] = $v;
  193. }
  194. $classid = $classid = $this->classid->sku();
  195. $shop_list = $this->shop->find_all();
  196. $shop_list = array_column($shop_list,'shopname','id');
  197. $express_list = $this->express->find_all();
  198. $express_list = array_column($express_list,'servicename','id');
  199. $warehouse_list = $this->warehouse->find_all();
  200. $warehouse_list = array_column($warehouse_list,'title','id');
  201. $info_list = $this->_getAndTransfer('fullorder',$where.$wid,$order_str,$shop_list,$express_list,$warehouse_list,$classid,$typeclass);
  202. $info_listsmt = $this->_getAndTransfer('fullordersmt',$where.$wid,$order_str,$shop_list,$express_list,$warehouse_list,$classid,$typeclass);
  203. $info_listtt = $this->_getAndTransfer('fullordertt',$where.$wid,$order_str,$shop_list,$express_list,$warehouse_list,$classid,$typeclass);
  204. $info_listamz = $this->_getAndTransfer('fullorderamz',$where.$wid,$order_str,$shop_list,$express_list,$warehouse_list,$classid,$typeclass);
  205. $info_listxw = $this->_getAndTransfer('fullorderxw',$where.$wid,$order_str,$shop_list,$express_list,$warehouse_list,$classid,$typeclass);
  206. $list = [];
  207. $list = array_merge($info_list,$info_listsmt,$info_listtt,$info_listamz,$info_listxw);
  208. echo "<pre>";
  209. print_r($list);
  210. die;
  211. // $final_list = [];
  212. // foreach(){
  213. // }
  214. //生成excel
  215. $filename = '订单出库-'.date('Ymd',time());
  216. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  217. <head>
  218. <!--[if gte mso 9]><xml>
  219. <x:ExcelWorkbook>
  220. <x:ExcelWorksheets>
  221. <x:ExcelWorksheet>
  222. <x:Name>EXCEL</x:Name>
  223. <x:WorksheetOptions>
  224. <x:Print>
  225. <x:ValidPrinterInfo />
  226. </x:Print>
  227. </x:WorksheetOptions>
  228. </x:ExcelWorksheet>
  229. </x:ExcelWorksheets>
  230. </x:ExcelWorkbook>
  231. </xml>
  232. <![endif]-->
  233. </head><body>";
  234. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  235. $str .= "<tr><td>编码</td><td>出库时间</td><td>仓库品名</td><td>条数</td><td>品名</td><td>料品</td></tr>";
  236. foreach ($info_list as $key=>$value)
  237. {
  238. $tmp_list = explode(";",$value['fpdata']);
  239. if(isset($tmp_list[0])){
  240. foreach($tmp_list as $k=>$v){
  241. $tmp_detail = explode("|",$v);
  242. $str .= "<tr>";
  243. $str .= "<td>". $value['number']. "</td>";
  244. $str .= "<td>". $value['librarytime']. "</td>";
  245. $str .= "<td>". $value['shipremarks']. "</td>";
  246. $str .= "<td>". $tmp_detail[2]. "</td>";
  247. $str .= "<td>". $tmp_detail[1]. "</td>";
  248. $str .= "<td>". $value['state']. "</td>";
  249. $str .= "</tr>";
  250. }
  251. }
  252. }
  253. $str .= "</table></body></html>";
  254. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  255. header( "Content-type: application/octet-stream" );
  256. header( "Content-Disposition: attachment; filename=".$filename );
  257. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  258. header( "Pragma: no-cache" );
  259. header( "Expires: 0" );
  260. exit($str);
  261. }
  262. }
  263. /**
  264. * 对多个平台的数据进行循环处理
  265. */
  266. private function _getAndTransfer($table,$where,$order_str,$shop_list,$express_list,$warehouse_list,$classid,$typeclass){
  267. //取得信息列表
  268. $info_list = $this->$table->find_all($where,'shop,type,orderinfo,number,waybill,express,print,library,librarytime,shipremarks,ts,fpdata',$order_str);
  269. //格式化数据
  270. foreach ($info_list as $key=>$value)
  271. {
  272. $info_list[$key]['shop'] = isset($shop_list[$value['shop']])?$shop_list[$value['shop']]: "";
  273. if($value['waybill'] == '0')
  274. {
  275. $info_list[$key]['waybill'] = "";
  276. }
  277. $info_list[$key]['express'] = isset($express_list[$value['express']])?$express_list[$value['express']]:"";
  278. $info_list[$key]['type'] = isset($warehouse_list[$value['type']])?$warehouse_list[$value['type']]: "";
  279. if($value['print'] == 1)
  280. {
  281. $info_list[$key]['print'] = '不可打印';
  282. }
  283. else if($value['print'] == 2)
  284. {
  285. $info_list[$key]['print'] = '未打印';
  286. }
  287. else if($value['print'] == 3)
  288. {
  289. $info_list[$key]['print'] = '已打印';
  290. }
  291. if($value['library'] == 1)
  292. {
  293. $info_list[$key]['library'] = '<em class="c">未出库</em>';
  294. }
  295. else if($value['library'] == 2)
  296. {
  297. $info_list[$key]['library'] = '<em class="c">已出库</em>';
  298. }
  299. else if($value['library'] == 3)
  300. {
  301. $info_list[$key]['library'] = '<em class="c">已退库</em>';
  302. }
  303. if($value['librarytime'] == '0')
  304. {
  305. $info_list[$key]['librarytime'] = '<em class="t"></em>';
  306. }
  307. else
  308. {
  309. $info_list[$key]['librarytime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['librarytime']).'</em>';
  310. }
  311. $dbapi = explode(';',trim($value['fpdata'],';'));
  312. $trans_list = [];
  313. foreach ($dbapi as $va)
  314. {
  315. $pm = $classid;
  316. $jm = $classid;
  317. $bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
  318. $features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$va);
  319. $ts = explode('|',trim($features,'|'));
  320. if(stripos($ts[0],',') !== false)
  321. {
  322. $ft = explode(',',$ts[0]);
  323. $features = explode('-',trim($ft[1],'-'));
  324. $features[] = $ft[0];
  325. }
  326. else
  327. {
  328. $features = explode('-',trim($ts[0],'-'));
  329. }
  330. foreach($features as $k=>$v)
  331. {
  332. if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']]))
  333. {
  334. if($typeclass[$v]['bm'] != '')
  335. {
  336. $bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];
  337. }
  338. }
  339. if($v != 0 && isset($typeclass[$v]))
  340. {
  341. if($typeclass[$v]['classid'] == 13)
  342. {
  343. $dj = $typeclass[$v]['title'];
  344. }
  345. if($typeclass[$v]['classid'] == 8)
  346. {
  347. $ys = $typeclass[$v]['title'];
  348. }
  349. if($typeclass[$v]['classid'] == 15)
  350. {
  351. $hx = $typeclass[$v]['title'];
  352. }
  353. if(isset($pm[$typeclass[$v]['classid']]))
  354. {
  355. if($typeclass[$v]['title'] == '9A')
  356. {
  357. $pm[$typeclass[$v]['classid']] = '9A';
  358. }
  359. else if($typeclass[$v]['title'] == '10A')
  360. {
  361. $pm[$typeclass[$v]['classid']] = '10A';
  362. }
  363. else
  364. {
  365. $clzh = $typeclass[$v]['zh'];
  366. if(stripos($typeclass[$v]['zh'],'|') !== false)
  367. {
  368. $clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
  369. $clzh = $clzh[0];
  370. }
  371. $pm[$typeclass[$v]['classid']] = $clzh;
  372. }
  373. }
  374. if(isset($jm[$typeclass[$v]['classid']]))
  375. {
  376. if($typeclass[$v]['jm'])
  377. {
  378. $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
  379. }
  380. }
  381. }
  382. }
  383. $jm = array_filter($jm);//去除空值
  384. $jm = implode("-",$jm);
  385. $pm = array_filter($pm);//去除空值
  386. $zh = implode(" ",$pm);
  387. $zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
  388. $trans_list[] = [
  389. 'jm'=>$jm ,
  390. 'pm'=>$zh,
  391. 'ts'=>$ts[2]
  392. ];
  393. }
  394. $info_list[$key]['trans_list'] = $trans_list;
  395. }
  396. return $info_list;
  397. }
  398. }