load->library('session'); $this->load->_model('Model_whlabel','whlabel'); $this->load->_model('Model_warehouse','warehouse'); $this->load->_model('Model_productprice','productprice'); $this->load->_model('Model_excel','excel'); $this->load->_model('Model_fullorder','fullorder'); $this->load->_model('Model_fullordertt','fullordertt'); $this->load->_model('Model_fullorderamz','fullorderamz'); $this->load->_model('Model_fullordersmt','fullordersmt'); $this->load->_model('Model_outbound','outbound'); $this->load->_model('Model_express','express'); $this->load->_model('Model_shop','shop'); $this->load->_model('Model_typeclass','typeclass'); $this->load->_model('Model_country','country'); $this->load->_model('Model_kdniao','kdniao'); $this->load->_model('Model_notice','notice'); $this->load->_model('Model_dhl','dhl'); $this->load->_model('Model_dhlhz','dhlhz'); $this->load->_model('Model_usps','usps'); $this->load->_model('Model_fedex','fedex'); $this->load->_model('Model_fedex_cby','fedex_cby'); $this->load->_model('Model_ups','ups'); $this->load->_model('Model_ali','ali'); $this->load->_model('Model_dpd','dpd'); $this->load->_model('Model_shop','shop'); $this->load->_model('Model_user','user'); $this->load->_model('Model_whlabel','whlabel'); $this->load->_model('Model_specialstock','specialstock'); $this->load->_model('Model_ck','ck'); $this->load->_model('Model_whlabellabel','whlabellabel'); $this->load->_model('Model_apiyy','apiyy'); $this->load->helper('url'); $this->load->_model('Model_whlabel_fc','whlabel_fc'); $this->load->_model('Model_systemtransfer','systemtransfer'); $this->load->_model('Model_classid','classid'); $this->load->_model('Model_allocation','allocation'); $this->load->_model('Model_fullorderxw','fullorderxw'); $this->load->_model('Model_fullorderpaypal','fullorderpaypal'); $this->load->_model("Model_logic_ding","logic_ding"); $this->load->_model("Model_fedexv1",'fedexv1'); $this->load->_model("Model_zzquque_u9","zzquque_u9"); $this->load->_model("Model_customsdeclaration","customsdeclaration"); } //定义方法的调用规则 获取URI第二段值 public function _remap($arg,$arg_array) { if($arg == 'exceltwo') { $this->_exceltwo($arg_array); } else { $this->_index(); } } public function _exceltwo($arg_array) { if(isset($_SESSION['api'])) { $user = $this->user->get_api($_SESSION['api']); $usp = $user; $fgshop = "";$sid = "";$wid="";$wtype=""; $usersp = explode('|',trim($user['shop'],'|')); $userwh = explode('|',trim($user['warehouse'],'|')); foreach ($usersp as $value) { $fgshop .= " shop = ".$value." or"; $sid .= " id = ".$value." or"; } foreach ($userwh as $value) { $wid .= " id = ".$value." or"; $wtype .= " type = ".$value." or"; } if($user['userid'] == 'xw') { $xw = 1; } } if(isset($_GET['fexcel'])) { $dowid = $this->input->get('a'); $wid = ""; if($dowid != "") { $id_arr = explode(',',rtrim($dowid,',')); foreach ($id_arr as $v) { $wid .= " id = '$v' or"; } $wid = " and".rtrim($wid,'or'); } $t = $this->input->get('t',true); $timetk = $this->input->get('timetk',true); $timetj = $this->input->get('timetj',true); $shop = $this->input->get('shop',true); $source = $this->input->get('source',true); $orderinfo = $this->input->get('orderinfo',true); $number = $this->input->get('number',true); $library = $this->input->get('library',true); $waybill = $this->input->get('waybill',true); $express = $this->input->get('express',true); $type = $this->input->get('type',true); $so = $this->input->get('so',true); $timetk = strtotime($timetk); $timetj = strtotime($timetj); $where = (isset($_SESSION['api']))?"library!=3 and libraryconfirm=2 and print = 3 and (".rtrim($wtype,'or').")":"id = '0'"; if($timetk && $timetj && $library == 1) { //$cxtime = 'reviewtime'; $where .= " and printtime > '$timetk - 180*24*3600' and printtime < '$timetj'"; $where .= " and state != 217"; } else if($timetk && $timetj && $library == 2) { $cxtime = 'librarytime'; $where .= " and librarytime > '$timetk' and librarytime < '$timetj'"; } if(isset($_SESSION['api'])) { if($type) { $where .= " and type = '$type'"; } else { $uw = ''; $u = $this->user->get_api($_SESSION['api']); $u['warehouse'] = explode('|',trim($u['warehouse'],'|')); foreach ($u['warehouse'] as $v) { $uw .= " type = '$v' or"; } $uw = rtrim($uw,'or'); $uw = " and (".ltrim($uw,' ').")"; $where .= $uw; } } else { echo json_encode(array('msg'=>'导出失败,请重新登陆!','success'=>false));exit; } if($shop) { $where .= " and shop = '$shop'"; } if($number) { $where .= " and number = '$number'"; } if($library) { $where .= " and library = '$library'"; } if($waybill) { $where .= " and waybill = '$waybill'"; } if($express) { $where .= " and express = '$express'"; } if($orderinfo) { $where .= " and orderinfo = '$orderinfo'"; } if($so) { $where .= " and shipremarks like '%$so%'"; } //数据排序 //$order_str = ($print != 3)?"id desc":"librarytime desc"; $order_str = "librarytime desc"; if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } $typeclass = array(); $tclass = $this->typeclass->find_all(); foreach ($tclass as $v) { $typeclass[$v['id']] = $v; } $classid = $classid = $this->classid->sku(); $shop_list = $this->shop->find_all(); $shop_list = array_column($shop_list,'shopname','id'); $express_list = $this->express->find_all(); $express_list = array_column($express_list,'servicename','id'); $warehouse_list = $this->warehouse->find_all(); $warehouse_list = array_column($warehouse_list,'title','id'); $info_list = $this->_getAndTransfer('fullorder',$where.$wid,$order_str,$shop_list,$express_list,$warehouse_list,$classid,$typeclass); $info_listsmt = $this->_getAndTransfer('fullordersmt',$where.$wid,$order_str,$shop_list,$express_list,$warehouse_list,$classid,$typeclass); $info_listtt = $this->_getAndTransfer('fullordertt',$where.$wid,$order_str,$shop_list,$express_list,$warehouse_list,$classid,$typeclass); $info_listamz = $this->_getAndTransfer('fullorderamz',$where.$wid,$order_str,$shop_list,$express_list,$warehouse_list,$classid,$typeclass); $info_listxw = $this->_getAndTransfer('fullorderxw',$where.$wid,$order_str,$shop_list,$express_list,$warehouse_list,$classid,$typeclass); $list = []; $list = array_merge($info_list,$info_listsmt,$info_listtt,$info_listamz,$info_listxw); // $final_list = []; // foreach(){ // } //生成excel $filename = '订单出库-'.date('Ymd',time()).".xlsx"; $str = " "; $str .= ""; $str .= ""; foreach ($list as $key=>$value) { foreach($value['trans_list'] as $k=>$v){ $str .= ""; $str .= ""; $str .= ""; $str .= ""; $str .= ""; $str .= ""; $str .= ""; $str .= ""; $str .= ""; } } $str .= "
编码出库时间仓库品名申报条数品名料品料品条数
". $value['number']. "". $value['librarytime']. "". $value['shipremarks']. "". $value['ts']. "". $v['pm']. "". $v['jm']. "". $v['ts']. "
"; header( "Content-Type: application/vnd.ms-excel; name='excel'" ); header( "Content-type: application/octet-stream" ); header( "Content-Disposition: attachment; filename=".$filename ); header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); header( "Pragma: no-cache" ); header( "Expires: 0" ); exit($str); } } /** * 对多个平台的数据进行循环处理 */ private function _getAndTransfer($table,$where,$order_str,$shop_list,$express_list,$warehouse_list,$classid,$typeclass){ //取得信息列表 $info_list = $this->$table->find_all($where,'shop,type,orderinfo,number,waybill,express,print,library,librarytime,shipremarks,ts,fpdata',$order_str); //格式化数据 foreach ($info_list as $key=>$value) { $info_list[$key]['shop'] = isset($shop_list[$value['shop']])?$shop_list[$value['shop']]: ""; if($value['waybill'] == '0') { $info_list[$key]['waybill'] = ""; } $info_list[$key]['express'] = isset($express_list[$value['express']])?$express_list[$value['express']]:""; $info_list[$key]['type'] = isset($warehouse_list[$value['type']])?$warehouse_list[$value['type']]: ""; if($value['print'] == 1) { $info_list[$key]['print'] = '不可打印'; } else if($value['print'] == 2) { $info_list[$key]['print'] = '未打印'; } else if($value['print'] == 3) { $info_list[$key]['print'] = '已打印'; } if($value['library'] == 1) { $info_list[$key]['library'] = '未出库'; } else if($value['library'] == 2) { $info_list[$key]['library'] = '已出库'; } else if($value['library'] == 3) { $info_list[$key]['library'] = '已退库'; } if($value['librarytime'] == '0') { $info_list[$key]['librarytime'] = ''; } else { $info_list[$key]['librarytime'] = ''.date('Y-m-d H:i:s',$value['librarytime']).''; } $dbapi = explode(';',trim($value['fpdata'],';')); $trans_list = []; foreach ($dbapi as $va) { $pm = $classid; $jm = $classid; $bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>''); $features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$va); $ts = explode('|',trim($features,'|')); if(stripos($ts[0],',') !== false) { $ft = explode(',',$ts[0]); $features = explode('-',trim($ft[1],'-')); $features[] = $ft[0]; } else { $features = explode('-',trim($ts[0],'-')); } foreach($features as $k=>$v) { if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']])) { if($typeclass[$v]['bm'] != '') { $bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm']; } } if($v != 0 && isset($typeclass[$v])) { if($typeclass[$v]['classid'] == 13) { $dj = $typeclass[$v]['title']; } if($typeclass[$v]['classid'] == 8) { $ys = $typeclass[$v]['title']; } if($typeclass[$v]['classid'] == 15) { $hx = $typeclass[$v]['title']; } if(isset($pm[$typeclass[$v]['classid']])) { if($typeclass[$v]['title'] == '9A') { $pm[$typeclass[$v]['classid']] = '9A'; } else if($typeclass[$v]['title'] == '10A') { $pm[$typeclass[$v]['classid']] = '10A'; } else { $clzh = $typeclass[$v]['zh']; if(stripos($typeclass[$v]['zh'],'|') !== false) { $clzh = explode('|',rtrim($typeclass[$v]['zh'],'|')); $clzh = $clzh[0]; } $pm[$typeclass[$v]['classid']] = $clzh; } } if(isset($jm[$typeclass[$v]['classid']])) { if($typeclass[$v]['jm']) { $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm']; } } } } $jm = array_filter($jm);//去除空值 $jm = implode("-",$jm); $pm = array_filter($pm);//去除空值 $zh = implode(" ",$pm); $zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' ')); $trans_list[] = [ 'jm'=>$jm , 'pm'=>$zh, 'ts'=>isset($ts[2])?$ts[2]:json_encode($ts), ]; } $info_list[$key]['trans_list'] = $trans_list; } return $info_list; } }