Systemfoutfz.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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. // $final_list = [];
  209. // foreach(){
  210. // }
  211. //生成excel
  212. $filename = '订单出库-'.date('Ymd',time());
  213. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  214. <head>
  215. <!--[if gte mso 9]><xml>
  216. <x:ExcelWorkbook>
  217. <x:ExcelWorksheets>
  218. <x:ExcelWorksheet>
  219. <x:Name>EXCEL</x:Name>
  220. <x:WorksheetOptions>
  221. <x:Print>
  222. <x:ValidPrinterInfo />
  223. </x:Print>
  224. </x:WorksheetOptions>
  225. </x:ExcelWorksheet>
  226. </x:ExcelWorksheets>
  227. </x:ExcelWorkbook>
  228. </xml>
  229. <![endif]-->
  230. </head><body>";
  231. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  232. $str .= "<tr><td>编码</td><td>出库时间</td><td>仓库品名</td><td>总条数</td><td>品名</td><td>料品</td><td>条数</td></tr>";
  233. foreach ($info_list as $key=>$value)
  234. {
  235. foreach($value['trans_list'] as $k=>$v){
  236. $tmp_detail = explode("|",$v);
  237. $str .= "<tr>";
  238. $str .= "<td>". $value['number']. "</td>";
  239. $str .= "<td>". $value['librarytime']. "</td>";
  240. $str .= "<td>". $value['shipremarks']. "</td>";
  241. $str .= "<td>". $value['ts']. "</td>";
  242. $str .= "<td>". $v['pm']. "</td>";
  243. $str .= "<td>". $v['jm']. "</td>";
  244. $str .= "<td>". $v['ts']. "</td>";
  245. $str .= "</tr>";
  246. }
  247. }
  248. $str .= "</table></body></html>";
  249. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  250. header( "Content-type: application/octet-stream" );
  251. header( "Content-Disposition: attachment; filename=".$filename );
  252. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  253. header( "Pragma: no-cache" );
  254. header( "Expires: 0" );
  255. exit($str);
  256. }
  257. }
  258. /**
  259. * 对多个平台的数据进行循环处理
  260. */
  261. private function _getAndTransfer($table,$where,$order_str,$shop_list,$express_list,$warehouse_list,$classid,$typeclass){
  262. //取得信息列表
  263. $info_list = $this->$table->find_all($where,'shop,type,orderinfo,number,waybill,express,print,library,librarytime,shipremarks,ts,fpdata',$order_str);
  264. //格式化数据
  265. foreach ($info_list as $key=>$value)
  266. {
  267. $info_list[$key]['shop'] = isset($shop_list[$value['shop']])?$shop_list[$value['shop']]: "";
  268. if($value['waybill'] == '0')
  269. {
  270. $info_list[$key]['waybill'] = "";
  271. }
  272. $info_list[$key]['express'] = isset($express_list[$value['express']])?$express_list[$value['express']]:"";
  273. $info_list[$key]['type'] = isset($warehouse_list[$value['type']])?$warehouse_list[$value['type']]: "";
  274. if($value['print'] == 1)
  275. {
  276. $info_list[$key]['print'] = '不可打印';
  277. }
  278. else if($value['print'] == 2)
  279. {
  280. $info_list[$key]['print'] = '未打印';
  281. }
  282. else if($value['print'] == 3)
  283. {
  284. $info_list[$key]['print'] = '已打印';
  285. }
  286. if($value['library'] == 1)
  287. {
  288. $info_list[$key]['library'] = '<em class="c">未出库</em>';
  289. }
  290. else if($value['library'] == 2)
  291. {
  292. $info_list[$key]['library'] = '<em class="c">已出库</em>';
  293. }
  294. else if($value['library'] == 3)
  295. {
  296. $info_list[$key]['library'] = '<em class="c">已退库</em>';
  297. }
  298. if($value['librarytime'] == '0')
  299. {
  300. $info_list[$key]['librarytime'] = '<em class="t"></em>';
  301. }
  302. else
  303. {
  304. $info_list[$key]['librarytime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['librarytime']).'</em>';
  305. }
  306. $dbapi = explode(';',trim($value['fpdata'],';'));
  307. $trans_list = [];
  308. foreach ($dbapi as $va)
  309. {
  310. $pm = $classid;
  311. $jm = $classid;
  312. $bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
  313. $features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$va);
  314. $ts = explode('|',trim($features,'|'));
  315. if(stripos($ts[0],',') !== false)
  316. {
  317. $ft = explode(',',$ts[0]);
  318. $features = explode('-',trim($ft[1],'-'));
  319. $features[] = $ft[0];
  320. }
  321. else
  322. {
  323. $features = explode('-',trim($ts[0],'-'));
  324. }
  325. foreach($features as $k=>$v)
  326. {
  327. if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']]))
  328. {
  329. if($typeclass[$v]['bm'] != '')
  330. {
  331. $bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];
  332. }
  333. }
  334. if($v != 0 && isset($typeclass[$v]))
  335. {
  336. if($typeclass[$v]['classid'] == 13)
  337. {
  338. $dj = $typeclass[$v]['title'];
  339. }
  340. if($typeclass[$v]['classid'] == 8)
  341. {
  342. $ys = $typeclass[$v]['title'];
  343. }
  344. if($typeclass[$v]['classid'] == 15)
  345. {
  346. $hx = $typeclass[$v]['title'];
  347. }
  348. if(isset($pm[$typeclass[$v]['classid']]))
  349. {
  350. if($typeclass[$v]['title'] == '9A')
  351. {
  352. $pm[$typeclass[$v]['classid']] = '9A';
  353. }
  354. else if($typeclass[$v]['title'] == '10A')
  355. {
  356. $pm[$typeclass[$v]['classid']] = '10A';
  357. }
  358. else
  359. {
  360. $clzh = $typeclass[$v]['zh'];
  361. if(stripos($typeclass[$v]['zh'],'|') !== false)
  362. {
  363. $clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
  364. $clzh = $clzh[0];
  365. }
  366. $pm[$typeclass[$v]['classid']] = $clzh;
  367. }
  368. }
  369. if(isset($jm[$typeclass[$v]['classid']]))
  370. {
  371. if($typeclass[$v]['jm'])
  372. {
  373. $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
  374. }
  375. }
  376. }
  377. }
  378. $jm = array_filter($jm);//去除空值
  379. $jm = implode("-",$jm);
  380. $pm = array_filter($pm);//去除空值
  381. $zh = implode(" ",$pm);
  382. $zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
  383. $trans_list[] = [
  384. 'jm'=>$jm ,
  385. 'pm'=>$zh,
  386. 'ts'=>$ts[2]
  387. ];
  388. }
  389. $info_list[$key]['trans_list'] = $trans_list;
  390. }
  391. return $info_list;
  392. }
  393. }