Systemfoutfz.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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($_GET['fexcel']))
  64. {
  65. $dowid = $this->input->get('a');
  66. $wid = "";
  67. if($dowid != "")
  68. {
  69. $id_arr = explode(',',rtrim($dowid,','));
  70. foreach ($id_arr as $v)
  71. {
  72. $wid .= " id = '$v' or";
  73. }
  74. $wid = " and".rtrim($wid,'or');
  75. }
  76. $t = $this->input->get('t',true);
  77. $timetk = $this->input->get('timetk',true);
  78. $timetj = $this->input->get('timetj',true);
  79. $shop = $this->input->get('shop',true);
  80. $source = $this->input->get('source',true);
  81. $orderinfo = $this->input->get('orderinfo',true);
  82. $number = $this->input->get('number',true);
  83. $library = $this->input->get('library',true);
  84. $waybill = $this->input->get('waybill',true);
  85. $express = $this->input->get('express',true);
  86. $type = $this->input->get('type',true);
  87. $so = $this->input->get('so',true);
  88. $timetk = strtotime($timetk);
  89. $timetj = strtotime($timetj);
  90. $where = (isset($_SESSION['api']))?"library!=3 and libraryconfirm=2 and print = 3 and (".rtrim($wtype,'or').")":"id = '0'";
  91. if($timetk && $timetj && $library == 1)
  92. {
  93. //$cxtime = 'reviewtime';
  94. $where .= " and printtime > '$timetk - 180*24*3600' and printtime < '$timetj'";
  95. $where .= " and state != 217";
  96. }
  97. else if($timetk && $timetj && $library == 2)
  98. {
  99. $cxtime = 'librarytime';
  100. $where .= " and librarytime > '$timetk' and librarytime < '$timetj'";
  101. }
  102. if(isset($_SESSION['api']))
  103. {
  104. if($type)
  105. {
  106. $where .= " and type = '$type'";
  107. }
  108. else
  109. {
  110. $uw = '';
  111. $u = $this->user->get_api($_SESSION['api']);
  112. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  113. foreach ($u['warehouse'] as $v)
  114. {
  115. $uw .= " type = '$v' or";
  116. }
  117. $uw = rtrim($uw,'or');
  118. $uw = " and (".ltrim($uw,' ').")";
  119. $where .= $uw;
  120. }
  121. }
  122. else
  123. {
  124. echo json_encode(array('msg'=>'导出失败,请重新登陆!','success'=>false));exit;
  125. }
  126. if($shop)
  127. {
  128. $where .= " and shop = '$shop'";
  129. }
  130. if($number)
  131. {
  132. $where .= " and number = '$number'";
  133. }
  134. if($library)
  135. {
  136. $where .= " and library = '$library'";
  137. }
  138. if($waybill)
  139. {
  140. $where .= " and waybill = '$waybill'";
  141. }
  142. if($express)
  143. {
  144. $where .= " and express = '$express'";
  145. }
  146. if($orderinfo)
  147. {
  148. $where .= " and orderinfo = '$orderinfo'";
  149. }
  150. if($so)
  151. {
  152. $where .= " and shipremarks like '%$so%'";
  153. }
  154. //数据排序
  155. //$order_str = ($print != 3)?"id desc":"librarytime desc";
  156. $order_str = "librarytime desc";
  157. if(empty($page))
  158. {
  159. $start = 0;
  160. $perpage = 1;
  161. }
  162. else
  163. {
  164. $start = ($page - 1)*$perpage;
  165. }
  166. $typeclass = array();
  167. $tclass = $this->typeclass->find_all();
  168. foreach ($tclass as $v)
  169. {
  170. $typeclass[$v['id']] = $v;
  171. }
  172. $classid = $classid = $this->classid->sku();
  173. $shop_list = $this->shop->find_all();
  174. $shop_list = array_column($shop_list,'shopname','id');
  175. $express_list = $this->express->find_all();
  176. $express_list = array_column($express_list,'servicename','id');
  177. $warehouse_list = $this->warehouse->find_all();
  178. $warehouse_list = array_column($warehouse_list,'title','id');
  179. $info_list = $this->_getAndTransfer('fullorder',$where.$wid,$order_str,$shop_list,$express_list,$warehouse_list,$classid);
  180. $info_listsmt = $this->_getAndTransfer('fullordersmt',$where.$wid,$order_str,$shop_list,$express_list,$warehouse_list,$classid);
  181. $info_listtt = $this->_getAndTransfer('fullordertt',$where.$wid,$order_str,$shop_list,$express_list,$warehouse_list,$classid);
  182. $info_listamz = $this->_getAndTransfer('fullorderamz',$where.$wid,$order_str,$shop_list,$express_list,$warehouse_list,$classid);
  183. $info_listxw = $this->_getAndTransfer('fullorderxw',$where.$wid,$order_str,$shop_list,$express_list,$warehouse_list,$classid);
  184. $list = [];
  185. $list = array_merge($info_list,$info_listsmt,$info_listtt,$info_listamz,$info_listxw);
  186. echo "<pre>";
  187. print_r($list);
  188. die;
  189. $final_list = [];
  190. // foreach(){
  191. // }
  192. $title = '订单出库-'.date('Ymd',time());
  193. $titlename = "<table border=1>".$t."<td>条数</td><td>料品</td><td>品名</td></table>";
  194. $tail = "\n";
  195. $filename = $title.".xls";
  196. $this->excel->get_fz2(array_merge($info_list,$info_listtt,$info_listamz,$info_listxw,$info_listsmt),$titlename,$filename,$tail);
  197. }
  198. }
  199. /**
  200. * 对多个平台的数据进行循环处理
  201. */
  202. private function _getAndTransfer($table,$where,$order_str,$shop_list,$express_list,$warehouse_list,$classid){
  203. //取得信息列表
  204. $info_list = $this->$table->find_all($where,'shop,type,orderinfo,number,waybill,express,print,library,librarytime,shipremarks,ts,fpdata',$order_str);
  205. //格式化数据
  206. foreach ($info_list as $key=>$value)
  207. {
  208. $info_list[$key]['shop'] = isset($shop_list[$value['shop']])?$shop_list[$value['shop']]: "";
  209. if($value['waybill'] == '0')
  210. {
  211. $info_list[$key]['waybill'] = "";
  212. }
  213. $info_list[$key]['express'] = isset($express_list[$value['express']])?$express_list[$value['express']]:"";
  214. $info_list[$key]['type'] = isset($warehouse_list[$value['type']])?$warehouse_list[$value['type']]: "";
  215. if($value['print'] == 1)
  216. {
  217. $info_list[$key]['print'] = '不可打印';
  218. }
  219. else if($value['print'] == 2)
  220. {
  221. $info_list[$key]['print'] = '未打印';
  222. }
  223. else if($value['print'] == 3)
  224. {
  225. $info_list[$key]['print'] = '已打印';
  226. }
  227. if($value['library'] == 1)
  228. {
  229. $info_list[$key]['library'] = '<em class="c">未出库</em>';
  230. }
  231. else if($value['library'] == 2)
  232. {
  233. $info_list[$key]['library'] = '<em class="c">已出库</em>';
  234. }
  235. else if($value['library'] == 3)
  236. {
  237. $info_list[$key]['library'] = '<em class="c">已退库</em>';
  238. }
  239. if($value['librarytime'] == '0')
  240. {
  241. $info_list[$key]['librarytime'] = '<em class="t"></em>';
  242. }
  243. else
  244. {
  245. $info_list[$key]['librarytime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['librarytime']).'</em>';
  246. }
  247. $dbapi = explode(';',trim($value['fpdata'],';'));
  248. $tmp_jm = "";
  249. $tmp_zh = "";
  250. foreach ($dbapi as $va)
  251. {
  252. $pm = $classid;
  253. $jm = $classid;
  254. $bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
  255. $features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$va);
  256. $ts = explode('|',trim($features,'|'));
  257. if(stripos($ts[0],',') !== false)
  258. {
  259. $ft = explode(',',$ts[0]);
  260. $features = explode('-',trim($ft[1],'-'));
  261. $features[] = $ft[0];
  262. }
  263. else
  264. {
  265. $features = explode('-',trim($ts[0],'-'));
  266. }
  267. foreach($features as $k=>$v)
  268. {
  269. if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']]))
  270. {
  271. if($typeclass[$v]['bm'] != '')
  272. {
  273. $bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];
  274. }
  275. }
  276. if($v != 0 && isset($typeclass[$v]))
  277. {
  278. if($typeclass[$v]['classid'] == 13)
  279. {
  280. $dj = $typeclass[$v]['title'];
  281. }
  282. if($typeclass[$v]['classid'] == 8)
  283. {
  284. $ys = $typeclass[$v]['title'];
  285. }
  286. if($typeclass[$v]['classid'] == 15)
  287. {
  288. $hx = $typeclass[$v]['title'];
  289. }
  290. if(isset($pm[$typeclass[$v]['classid']]))
  291. {
  292. if($typeclass[$v]['title'] == '9A')
  293. {
  294. $pm[$typeclass[$v]['classid']] = '9A';
  295. }
  296. else if($typeclass[$v]['title'] == '10A')
  297. {
  298. $pm[$typeclass[$v]['classid']] = '10A';
  299. }
  300. else
  301. {
  302. $clzh = $typeclass[$v]['zh'];
  303. if(stripos($typeclass[$v]['zh'],'|') !== false)
  304. {
  305. $clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
  306. $clzh = $clzh[0];
  307. }
  308. $pm[$typeclass[$v]['classid']] = $clzh;
  309. }
  310. }
  311. if(isset($jm[$typeclass[$v]['classid']]))
  312. {
  313. if($typeclass[$v]['jm'])
  314. {
  315. $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
  316. }
  317. }
  318. }
  319. }
  320. $jm = array_filter($jm);//去除空值
  321. $jm = implode("-",$jm);
  322. $tmp_jm .= $jm.";";
  323. $pm = array_filter($pm);//去除空值
  324. $zh = implode(" ",$pm);
  325. $zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
  326. $tmp_zh .= $zh.";";
  327. }
  328. $info_list[$key]['jm'] = trim($tmp_jm,';');
  329. $info_list[$key]['zh'] = trim($tmp_zh,';');
  330. }
  331. return $info_list;
  332. }
  333. }