| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762 | <?php defined('BASEPATH') OR exit('No direct script access allowed');class Fullorderexcel extends Start_Controller {	public function __construct(){		parent::__construct();		$this->load->library('session');		$this->load->_model('Model_fullorder','fullorder');		$this->load->_model('Model_fullordertt','fullordertt');		$this->load->_model('Model_fullorderxw','fullorderxw');		$this->load->_model('Model_fullorder_smt','fullorder_smt');		$this->load->_model('Model_fullordersmt','fullordersmt');		$this->load->_model('Model_fullorderamz','fullorderamz');		$this->load->_model('Model_fullorderexcel','fullorderexcel');		$this->load->_model('Model_fullorderexcelclassid','fullorderexcelclassid');		$this->load->_model('Model_shop','shop');		$this->load->_model('Model_country','country');		$this->load->_model('Model_warehouse','warehouse');		$this->load->_model('Model_excel','excel');		$this->load->_model('Model_notice','notice');		$this->load->_model('Model_express','express');		$this->load->_model('Model_api','api');		$this->load->_model('Model_apismt','apismt');		$this->load->_model('Model_usps','usps');		$this->load->_model('Model_typeclass','typeclass');		$this->load->_model('Model_systemwigsout','systemwigsout');		$this->load->_model('Model_setting','setting');		$this->load->_model('Model_customer','customer');		$this->load->_model('Model_customersmt','customersmt');		$this->load->_model('Model_orderurl','orderurl');		$this->load->_model('Model_whlabel','whlabel');		$this->load->_model('Model_whlabel_bh','whlabel_bh');		$this->load->_model('Model_apiyy','apiyy');		$this->load->_model('Model_classid','classid');		$this->load->_model('Model_systemtransfer','systemtransfer');		$this->load->_model('Model_transfer','transfer');		$this->load->_model('Model_classid','classid');		$this->load->_model('Model_whlabel_type','whlabel_type');		$this->load->_model('Model_power','power');		$this->load->_model('Model_productdescribe','productdescribe');		$this->load->_model('Model_shopsku','shopsku');		$this->load->_model('Model_is','is');		$this->load->_model('Model_whlabel_qh','whlabel_qh');		$this->load->_model('Model_emaildata','emaildata');		$this->load->_model('Model_afspaypal','afspaypal');		$this->load->_model('Model_producttitle','producttitle');		$this->load->_model('Model_message','message');		$this->load->_model("Model_logic_ding","logic_ding");	}	//定义方法的调用规则 获取URI第二段值    public function _remap($arg,$arg_array)    {		if($arg == 'excel')        {             $this->_excel();        }		else if($arg == 'add')        {             $this->_add();        }		else if($arg == 'edit')        {             $this->_edit($arg_array);        }		else if($arg == 'copy'){			$this->_copy($arg_array);		}		else if($arg == 'del')        {             $this->_del();        }		else if($arg == 'rows')        {             $this->_rows();        }		else if($arg == 'waybill')        {             $this->_waybill($arg_array);        }		else if($arg == 'order')        {             $this->_order($arg_array);        }		else if($arg == 'xxpl')//线下批量导入        {             $this->_xxpl();        }		else if($arg == 'skuzh')//sku转中文        {             $this->_skuzh();        }		else if($arg == 'cs')        {             $this->_cs();        }		else if($arg == 'scwd')        {             $this->_scwd();        }		else if($arg == 'jmexcel')        {             $this->_jmexcel();        }		else if($arg == 'classid')        {             $this->_classid();        }		else if($arg == 'classidadd')        {             $this->_classidadd();        }		else if($arg == 'classidedit')        {             $this->_classidedit($arg_array);        }		else		{			 $this->_index();		}    }	//管理	public function _index()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['page']))  		{		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',true);			$type = $this->input->post('type',true);			$where = "1=1 ";            //数据排序            $order_str = "id asc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }			if($type)			{				$where .= " and type = '$type'";			}            //取得信息列表            $info_list = $this->fullorderexcel->find_all($where,'id,type,title',$order_str,$start,$perpage);			foreach ($info_list as $k=>$v) 			{				$classid = $this->fullorderexcelclassid->read($v['type']);				$info_list[$k]['type'] = $classid['title'];				$info_list[$k]['action'] = "<h9 class='window' data-h='/fullorderexcel/copy/".$v['id']."' style='color:#000'><span>复制表格</span></h9>";			}		    $total = $this->fullorderexcel->find_count($where);		    $pagenum = ceil($total/$perpage);		    $over = $total-($start+$perpage);		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));		    echo json_encode($rows);exit;		}		$classid = $this->fullorderexcelclassid->find_all();		$this->data['classid'] = $classid;		$this->_Template('fullorderexcel',$this->data);	}	//添加	public function _add()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['title']))		{			$post['title'] = $this->input->post('title',true);			$post['type'] = $this->input->post('type',true);			$post['content'] = $this->input->post('content',true);			$post['contentzh'] = $this->input->post('contentzh',true);			$addid = $this->fullorderexcel->insert($post);			if($addid)        	{				$adminid = $this->power->read(1);				$this->power->save(array("excelid"=>$adminid['excelid'].$addid.'|',"exceltext"=>$adminid['exceltext'].$post['title'].'|'),$adminid['id']);				echo json_encode(array('msg'=>'添加成功','success'=>true));exit;       	 	}       		else        	{           		echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;        	}		}		$classid = $this->fullorderexcelclassid->find_all();		$this->data['classid'] = $classid;		$this->_Template('fullorderexcel_add',$this->data);	}	//修改	public function _edit($arg_array)	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['id']))		{			$id = $this->input->post('id',true);			$post['title'] = $this->input->post('title',true);			$post['type'] = $this->input->post('type',true);			$post['content'] = $this->input->post('content',true);			$post['contentzh'] = $this->input->post('contentzh',true);			if($this->fullorderexcel->save($post,$id))        	{         		echo json_encode(array('msg'=>'修改成功','success'=>true));exit;       	 	}       		else        	{           		echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;        	}		}		$arg_array = $arg_array[0];		$fullorderexcel = $this->fullorderexcel->read($arg_array);		$this->data['fullorderexcel'] = $fullorderexcel;		$classid = $this->fullorderexcelclassid->find_all();		$this->data['classid'] = $classid;		$this->_Template('fullorderexcel_edit',$this->data);	}	public function _copy($arg_array)	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['id']))		{						$post['title'] = $this->input->post('title',true);			$post['type'] = $this->input->post('type',true);			$post['content'] = $this->input->post('content',true);			$post['contentzh'] = $this->input->post('contentzh',true);			unset($post['id']);			$addid =$this->fullorderexcel->insert($post);			         					if($addid)			{				$adminid = $this->power->read(1);				$this->power->save(array("excelid"=>$adminid['excelid'].$addid.'|',"exceltext"=>$adminid['exceltext'].$post['title'].'|'),$adminid['id']);				echo json_encode(array('msg'=>'添加成功','success'=>true));exit;			}			else			{				echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;			}       	 			}		$arg_array = $arg_array[0];		$fullorderexcel = $this->fullorderexcel->read($arg_array);		$this->data['fullorderexcel'] = $fullorderexcel;		$classid = $this->fullorderexcelclassid->find_all();		$this->data['classid'] = $classid;		$this->_Template('fullorderexcel_copy',$this->data);	}	//删除	public function _del()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['s']))		{            $id_arr = $this->input->post('s');            $id_arr =  explode(',',$id_arr);            if(!$id_arr)            {                echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;            }            //循环删除记录            foreach ($id_arr as $v)		    {                $this->fullorderexcel->remove($v);            }            echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));		}    }	//获取数据	public function _rows()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['id']))  		{			$id = $this->input->post('id',true);			$fullorderexcel = $this->fullorderexcel->read($id);		    $content = explode('|',rtrim($fullorderexcel['content'],'|'));			$contentzh = explode('|',rtrim($fullorderexcel['contentzh'],'|'));			$data = array();			for($i=0;$i<count($content);$i++) 			{				$a = explode('-',$content[$i]);				$b = explode('-',$contentzh[$i]);			    $data[] = array(0=>$a[1],1=>$b[1]);			}		    echo json_encode(array('rows'=>($data),'success'=>true));		}    }	//导出订单excel	public function _excel()	{		$fgshop = "";$sid = "";$excelshop="";		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);			$usp = $user;		    		    $usersp = explode('|',trim($user['shop'],'|'));			foreach ($usersp as $value) 		    {				$fgshop .= " shop = ".$value." or";				$sid .= " id = ".$value." or";			}			$userexcel = explode('|',trim($user['excelshop'],'|'));			if($user['excelshop'] == '')			{				echo "没有下载权限";exit;			}			foreach ($userexcel as $value) 		    {				$excelshop .= " shop =  ".$value." or";			}			if($excelshop != "")			{				$excelshop = "(".rtrim($excelshop,'or').")";			}		}		if(isset($_GET['fexcel']))  		{			$typeclass = array();			$tclass = $this->typeclass->find_all();			foreach ($tclass as $v) 			{				$typeclass[$v['id']] = $v;			}			$dowid = $this->input->get('a');			$wid = "";			if($dowid != "")			{				$id_arr =  explode(',',rtrim($dowid,','));				$wid  .= " id = 0 or";				foreach ($id_arr as $v) 		        {                    $wid  .= " id = '$v' or";                }				$wid = " and".rtrim($wid,'or');			}			$fexcel = $this->input->get('fexcel',true);			$page = $this->input->get('page',true);		    $perpage = $this->input->get('perpage',true);			$warehouse = $this->input->get('warehouse',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);			$state = $this->input->get('state',true);			$review = $this->input->get('review',true);			$type = $this->input->get('type',true);			$express = $this->input->get('express',true);			$orderinfo = $this->input->get('orderinfo',true);			$user = $this->input->get('user',true);			$client = $this->input->get('name',true);			$waybill = $this->input->get('waybill',true);			$number = $this->input->get('number',true);			$email = $this->input->get('email',true);			$dlz = $this->input->get('dlz',true);			$library = $this->input->get('library',true);			$libraryconfirm = $this->input->get('libraryconfirm',true);			$print = $this->input->get('print',true);			$timetkk = $this->input->get('timetkk',true);			$timetjj = $this->input->get('timetjj',true);			$xztime = $this->input->get('xztime',true);			$country = $this->input->get('country',true);			$zf = $this->input->get('zf',true);			$pay = $this->input->get('pay',true);			$phone = $this->input->get('phone',true);			$so = $this->input->get('so',true);			$sfxh = $this->input->get('sfxh',true);			$xdcs = $this->input->get('xdcs',true);			$xdcs = $this->input->get('xdcs',true);			$dbapi = $this->input->get('dbapi',true);			$orderurl = $this->input->get('orderurl',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$timetkk = strtotime($timetkk);			$timetjj = strtotime($timetjj);			$px = $this->input->get('px',true);			$fexcel = $this->fullorderexcel->read($fexcel);			$classid = $this->fullorderexcelclassid->read($fexcel['type']);			$where = "1 = 1 and (".rtrim($fgshop,'or').")";			if($warehouse)            {                $where  .= " and type = '$warehouse'";            }			if($xztime)			{				if($timetk && $timetj)            	{                	$where  .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";            	}				if($timetkk && $timetjj)            	{                	$where  .= " and ".$xztime." > '$timetkk' and ".$xztime." < '$timetjj'";            	}			}			else			{				$where  .= " and dtime > '$timetk' and dtime < '$timetj'";			}			if($library)            {                $where  .= " and library = '$library'";            }			if($print)            {                $where  .= " and print = '$print'";            }			if($shop)            {                $where  .= " and shop = '$shop'";            }			if($source)            {				if($source == '2d')				{					$where  .= " and source >= '2'";				}				else				{                    $where  .= " and source = '$source'";				}            }			if($state)            {				$where  .= " and state = '$state'";            }			if($review)            {                $where  .= " and review = '$review'";            }			if($type)            {                $where  .= " and type = '$type'";            }			if($express)            {                $where  .= " and express = '$express'";            }			if($orderinfo)            {                $where  .= " and orderinfo = '$orderinfo'";            }			if($user)            {                $where  .= " and user = '$user'";            }			if($client)            {                $where  .= " and client like '%$client%'";            }			if($waybill)            {                $where  .= " and waybill = '$waybill'";            }			if($number)            {                $where  .= " and number = '$number'";            }			if($email)            {                $where  .= " and email = '$email'";            }			if($country)            {                $where  .= " and country = '$country'";            }			if($dlz)            {                $where  .= " and waybill != '' and dlz = 0";            }			if($libraryconfirm)            {                $where  .= " and libraryconfirm = '$libraryconfirm'";            }			if($so)            {                $where  .= " and shipremarks like '%$so%'";            }			if($pay)            {                $where  .= " and pay = '$pay'";            }			if($phone)            {                $where  .= " and phone = '$phone'";            }			if($sfxh != '')            {                $where .= " and sfxh = '$sfxh'";            }			if($orderurl)            {				$url = $this->orderurl->read($orderurl);                $where  .= " and link like '%".$url['url']."%'";            }			if($zf)            {				if($zf == 1)				{                    $where  .= " and paypal not like '%-%-%-%'";				}				else				{					$where  .= " and paypal like '%-%-%-%'";				}            }			$sj = $this->input->get('sj',true);			if($sj)			{				$sj = $this->input->get('sj',true);			}			else			{				$sj = $classid['type'];			}						$fexceleq = explode("|",rtrim($fexcel['content'],'|'));			foreach ($fexceleq as $k=>$v) 		    {				$fexceleq[$k] = explode('-',$v);				$num[$k] = $fexceleq[$k][0];			}			//array_multisort($num,SORT_ASC,$fexceleq);//重新排序			$feq = "";$kong = array();$sku9610 = '';			foreach ($fexceleq as $k=>$v) 		    {				if(isset($v[1]))				{				    if($v[1] == 'klarnabill' || $v[1] == 'klarnaship' || $v[1] == 'PPname' || $v[1] == 'PPaddress' || $v[1] == 'PPemail' || $v[1] == 'afterpayship' || $v[1] == 'afterpaybill')				    {				    	 $feq .= 'klarnadata,';				    }				    if($v[1] == 'ccfpdata' || $v[1] == 'cpfpdata' || $v[1] == 'dbapi' || $v[1] == 'scapi')				    {				    	 $feq .= 'fpdata,';				    }				    if($v[1] != 'kong')//空值去除				    {					    if($v[1] == '9610sku' || $v[1] == 'issku' || $v[1] == 'sku')					    {					    	if($v[1] == '9610sku')					    	{						    	$sku9610 = 1;						    }						    if($sj == 'fullordersmt')						    {						    	$v[1] = 'sku';						    }						    else						    {						    	$v[1] = 'issku';						    }					    }				        $feq .= $v[1].',';				    }				    else				    {				    	$kong[$v[0]] = 1;				    }			    }			}			//处理额外加上的subtotal和rowtoal 但是不想在表中加太多字段 想着以后有关金额的都给怼到extra_price字段中			if((strpos($feq,'subtotal')!= false)||(strpos($feq,'rowtotal')!= false) ||(strpos($feq,'product_id')!= false)){				if(strpos($feq,'subtotal')!= false){					$feq = str_replace('subtotal,',"extra_price as subtotal,",$feq);				}				if(strpos($feq,'rowtotal')!= false){					$feq = str_replace('rowtotal,',"extra_price as rowtotal,",$feq);				}				if(strpos($feq,'product_id')!= false){					$feq = str_replace('product_id,',"extra_price as product_id,",$feq);				}			}			$feq = rtrim($feq,',');						$fexcelzhw = explode('|',rtrim($fexcel['contentzh'],'|'));			foreach ($fexcelzhw as $k=>$v) 		    {				$fexcelzhw[$k] = explode('-',$v);				$numb[$k] = $fexcelzhw[$k][0];			}			//array_multisort($numb,SORT_ASC,$fexcelzhw);//重新排序			$fexcelzh = array();			foreach ($fexcelzhw as $k=>$v) 		    {				$fexcelzh[] = $v[1];			}			if($px)			{                $order_str = $px." desc";			}			else			{				$order_str = "id desc";			}			// if($_GET['fexcel'] == '157'){			// 	$this->logic_ding->sendToDing("excel导出的【".$where.$wid.' and '.$excelshop);			// 	$this->logic_ding->sendToDing("excel导出的【".'id,'.$feq);			// 	$this->logic_ding->sendToDing("excel导出的【".$order_str);			// 	$this->logic_ding->sendToDing("excel导出的SJ【".$sj);			// }			            //取得信息列表            $info_list = $this->$sj->find_all($where.$wid.' and '.$excelshop,'id,'.$feq,$order_str);			 //格式化数据			 $i = 1;$shouldmoney = 0;$hl=1;            foreach ($info_list as $key=>$value) 		    {				$data = $this->$sj->read($value['id']);				$data = str_replace(array("'"),array("’"),$data);				if(isset($value['email']) && $usp['excelpass'] == '1')				{					$emailpass = $this->setting->get_excelpass($value['email']);					$info_list[$key]['email'] = $emailpass;				}				if(isset($value['phone']) && $usp['excelpass'] == '1')				{					$phonepass = $this->setting->get_excelpass($value['phone']);					$info_list[$key]['phone'] = $phonepass;				}				if(isset($value['currencytitle']))				{					if($value['currencytitle'] != "CNY")					{						$hl=$value['hl'];					}					$shouldmoney=$shouldmoney+($value['shouldmoney']*$hl);					$budget=$budget+($value['budget']*$hl);					$currency=$currency+(($value['shouldmoney']-$value['budget'])*$hl);					$refund=$refund+($value['refund']*$hl);				}				if(isset($value['shop']))				{					$shop = $this->shop->read($value['shop']);				    $info_list[$key]['shop'] = $shop['shopname'];				}				if(isset($value['dtime']))				{					$info_list[$key]['dtime'] = date('Y-m-d H:i:s',$value['dtime']);				}				if(isset($value['printtime']))				{					if($value['printtime'] > 0)					{					    $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);					}				}				if(isset($value['sku']))				{					if($sku9610 == '1')					{					$aesku =  explode(';',$value['sku']);					$aesku = $aesku[0];					$aesku =  explode(':',$aesku);					if(count($aesku) > 1)					{						$aesku = $aesku[1];					    $aesku =  str_replace('--','~',$aesku);					    $aesku =  explode('-',$aesku);					    $aesku = $aesku[0];					    $aesku =  str_replace('~','--',$aesku);					    $info_list[$key]['sku'] = $aesku;					}					else					{						$info_list[$key]['sku'] = '';					}					}					else					{						$info_list[$key]['sku'] = $value['sku'];					}				}				if(isset($value['issku']))				{					$value['issku'] = str_replace(array('<','>'),array('<','>'),$value['issku']);					if($sku9610 == '1')					{					$aesku =  explode(';',$value['issku']);					$aesku = $aesku[0];					$aesku =  str_replace('--','~',$aesku);					$aesku =  explode('-',$aesku);					$aesku = $aesku[0];					$aesku =  str_replace('~','--',$aesku);					$aesku = str_replace(array('<','>'),array('<','>'),$aesku);					$info_list[$key]['issku'] = $aesku;					}					else					{						$value['issku'] = str_replace(array('<','>'),array('<','>'),$value['issku']);						$info_list[$key]['issku'] = $value['issku'];					}									}				if(isset($value['subtotal'])){					$tmp_sub_str = "";					$subtotal_list = json_decode($value['subtotal'],true);					foreach($subtotal_list as $v){						if(isset($v['sub_total'])){							$tmp_sub_str .= sprintf( "%.2f",$v['sub_total'])."<br>";						}else{							$tmp_sub_str .= "0<br>";						}					}					$info_list[$key]['subtotal'] = $tmp_sub_str;				}				if(isset($value['rowtotal'])){					$tmp_sub_str = "";					$subtotal_list = json_decode($value['rowtotal'],true);					foreach($subtotal_list as $v){						if(isset($v['row_total'])){							$tmp_sub_str .= sprintf( "%.2f",$v['row_total'])."<br>";						}else{							$tmp_sub_str .= "0<br>";						}					}					$info_list[$key]['rowtotal'] = $tmp_sub_str;				}				if(isset($value['product_id'])){					$tmp_product_id = "";					$product_ids = json_decode($value['product_id'],true);					foreach($product_ids as $v){						if(isset($v['product_id'])){							$tmp_product_id .= $v['product_id']."<br>";						}else{							$tmp_product_id .= "<br>";						}					}					$info_list[$key]['product_id'] = $tmp_product_id;				}				if(isset($value['librarytime']))				{					if($value['librarytime'] > 0)					{					    $info_list[$key]['librarytime'] = date('Y-m-d H:i:s',$value['librarytime']);					}				}				if(isset($value['buytime']))				{					if($value['buytime'] > 0)					{					    $info_list[$key]['buytime'] = date('Y-m-d H:i:s',$value['buytime']);					}				}				if(isset($value['country']))				{					$country = $this->country->read($value['country']);				    $info_list[$key]['country'] = $country['name'];				}				if(isset($value['street']))//暂时用街道导出州二字码				{					if($data['country'] == 192)//如果是美国					{					    $ToState = array('alabama'=>'AL','alaska'=>'AK','arizona'=>'AZ','arkansas'=>'AR','california'=>'CA','colorado'=>'CO','connecticut'=>'CT','delaware'=>'DE','florida'=>'FL','georgia'=>'GA','hawaii'=>'HI','idaho'=>'ID','illinois'=>'IL','indiana'=>'IN','iowa'=>'IA','kansas'=>'KS','kentucky'=>'KY','louisiana'=>'LA','maine'=>'ME','maryland'=>'MD','massachusetts'=>'MA','michigan'=>'MI','minnesota'=>'MN','mississippi'=>'MS','missouri'=>'MO','montana'=>'MT','nebraska'=>'NE','nevada'=>'NV','new hampshire'=>'NH','new jersey'=>'NJ','new mexico'=>'NM','new york'=>'NY','north carolina'=>'NC','north dakota'=>'ND','ohio'=>'OH','oklahoma'=>'OK','oregon'=>'OR','pennsylvania'=>'PA','rhode island'=>'RI','south carolina'=>'SC','south dakota'=>'SD','tennessee'=>'TN','texas'=>'TX','utah'=>'UT','vermont'=>'VT','virginia'=>'VA','washington'=>'WA','west virginia'=>'WV','wisconsin'=>'WI','wyoming'=>'WY','district of columbia'=>'DC','virgin islands'=>'VI');				        $data['province'] = preg_replace('/( | |\s)/',' ',$data['province']);				        $data['province'] = trim($data['province'],' ');						if(isset($ToState[strtolower($data['province'])]))						{				            $dataprovince = strlen($data['province'])==2?$data['province']:$ToState[strtolower($data['province'])]; 						}						else						{							$dataprovince = '';						}				        $info_list[$key]['street'] = $dataprovince;					}					else					{						$info_list[$key]['street'] = '';					}				}				if(isset($value['pay']))				{					$pay = $this->typeclass->read($value['pay']);				    $info_list[$key]['pay'] = $pay['title'];				}				if(isset($value['type']))				{					$type = $this->warehouse->read($value['type']);				    $info_list[$key]['type'] = $type['title'];				}				if(isset($value['express']))				{					$express = $this->express->read($value['express']);					if($express)					{						$info_list[$key]['express'] = $express['servicename'];					}					else					{				        $info_list[$key]['express'] = '未选择';					}				}				if(isset($value['ccfpdata']))				{					$ccfpdata =  explode(';',$value['fpdata']);					$inc = 0;					foreach ($ccfpdata as $v) 					{						if(stripos($v,',') !== false)						{							$cc = explode(',',$v);						    $inctype = $this->typeclass->read($cc[0]);					        if(is_numeric($inctype['spare']))						    {								if($inctype['spare'] > $inc)								{									$inc = $inctype['spare'];								}						     }						}					}					$info_list[$key]['ccfpdata'] = $inc.'inch';				}				if(isset($value['printtype']))				{					if($value['printtype'] == 1)					{						$info_list[$key]['printtype'] = '运单';					}					else if($value['printtype'] == 2)					{						$info_list[$key]['printtype'] = '发货单';					}					else if($value['printtype'] == 3)					{						$info_list[$key]['printtype'] = '不打印单据';					}					else					{						$info_list[$key]['printtype'] = '未选择';					}				}				if(isset($value['exstate']))				{					if($value['exstate'] == '99')					{						$info_list[$key]['exstate'] = '未获取到物流信息';					}					else if($value['exstate'] == '1')					{						$info_list[$key]['exstate'] = '已揽收';					}					else if($value['exstate'] == '2')					{						$info_list[$key]['exstate'] = '在途中';					}					else if($value['exstate'] == '3')					{						$info_list[$key]['exstate'] = '派送中';					}					else if($value['exstate'] == '4')					{						$info_list[$key]['exstate'] = '已签收';					}					else if($value['exstate'] == '5')					{						$info_list[$key]['exstate'] = '派送异常';					}					else					{						$info_list[$key]['exstate'] = '';					}				}				if(isset($value['link']))				{					if($value['link'] != '')					{						$link = explode(',',$value['link']);						$info_list[$key]['link'] = $link[0];					}					else					{						$info_list[$key]['link'] = '';					}				}				if(isset($value['klarnabill']))				{					$klarnadata = explode('|',$value['klarnadata']);					if(isset($klarnadata[2]))					{					    $info_list[$key]['klarnabill'] = $klarnadata[2];					}					else					{						$info_list[$key]['klarnabill'] = '';					}				}				if(isset($value['klarnaship']))				{					$klarnadata = explode('|',$value['klarnadata']);					if(isset($klarnadata[3]))					{					    $info_list[$key]['klarnaship'] = $klarnadata[3];					}					else					{						$info_list[$key]['klarnaship'] = '';					}				}				if(isset($value['afterpaybill']))				{					$klarnadata = explode('|',$value['klarnadata']);					if(isset($klarnadata[1]))					{					    $info_list[$key]['afterpaybill'] = $klarnadata[1];					}					else					{						$info_list[$key]['afterpaybill'] = '';					}				}				if(isset($value['afterpayship']))				{					$klarnadata = explode('|',$value['klarnadata']);					if(isset($klarnadata[2]))					{					    $info_list[$key]['afterpayship'] = $klarnadata[2];					}					else					{						$info_list[$key]['afterpayship'] = '';					}				}				if(isset($value['PPname']))				{					$info_list[$key]['PPname'] = '';					$klarnadata = explode('|',$value['klarnadata']);					if(isset($klarnadata[1]))					{					    $klarnadata = json_decode($klarnadata[1],true);					    if(isset($klarnadata['name']))					    {					        $info_list[$key]['PPname'] = $klarnadata['name'];					    }					}				}				if(isset($value['PPemail']))				{					$info_list[$key]['PPemail'] = '';					$klarnadata = explode('|',$value['klarnadata']);					if(isset($klarnadata[1]))					{					    $klarnadata = json_decode($klarnadata[1],true);					    if(isset($klarnadata['email']))					    {							if($usp['excelpass'] == '1')							{								$ppemailpass = $this->setting->get_excelpass($klarnadata['email']);							}							else							{								$ppemailpass = $klarnadata['email'];							}					        $info_list[$key]['PPemail'] = $ppemailpass;					    }					}				}				if(isset($value['PPaddress']))				{					$info_list[$key]['PPaddress'] = '';					$klarnadata = explode('|',$value['klarnadata']);					if(isset($klarnadata[1]))					{					    $klarnadata = json_decode($klarnadata[1],true);					    if(isset($klarnadata['address']))					    {					        $info_list[$key]['PPaddress'] = $klarnadata['address'];					    }					}				}				if(isset($value['klarnadata']))				{					unset($info_list[$key]['klarnadata']);				}				if(isset($value['shippingmethod']))				{					$tax = explode('Tax:',$value['shippingmethod']);					$info_list[$key]['shippingmethod'] = (isset($tax[1]))?trim($tax[1],';'):'';				}				if(isset($value['systemwigsout']))				{					$out = $this->systemtransfer->find_all("number = '".$data['number']."'");					$outread = '';					if($out)					{						foreach ($out as $val) 		            	{							$list = '';							$rk = explode('|',trim($val['rk'],'|'));					    	$rktime = explode('|',trim($val['rktime'],'|'));					    	$zw = array();					    	$t = $this->transfer->find_all("1=1");					    	foreach ($t as $v)		   		        	{						    	$zw[$v['id']] = $v['title'];					    	}					    	if($val['rk'] != '' && count($rk) > 0)					    	{								for($i=0;$i<count($rk);$i++)		       		        	{							    	if(!isset($rktime[$i]))							    	{										$list .= $zw[$cz[$i]];							    	}							    	else							    	{					   		        	$list .= $zw[$rk[$i]].' :'.date('Y-m-d H:i',$rktime[$i]).',';							    	}								}							}							$outread .= '<span style="color:#f00">'.$val['pm'].'</span>:'.$list.'<br>';						}					}					else					{						$systemwigsout = $this->systemwigsout->find_all("number = '".$data['number']."'");						if($systemwigsout)						{		    				foreach ($systemwigsout as $v) 		    				{								$outread = '';								if($v['czwarehouse'] == 37)								{									$outread  .= '华荣厂';								}								else if($v['czwarehouse'] == 0)								{									$outread  .= '龙盈厂';								}			    				$cz = explode('|',trim($v['cz'],'|'));			    				$cztime = explode('|',trim($v['cztime'],'|'));			    				$zw = $this->transfer->get_list();			    				if($v['cz'] != '' && count($cz) > 0)			    				{			    					for($i=0;$i<count($cz);$i++)		            				{				    					if(!isset($cztime[$i]))					    				{					    					$outread .= $zw[$cz[$i]].' -> ';					    				}					    				else					   				 {					       				 $outread .= $zw[$cz[$i]].' :'.date('Y-m-d H:i',$cztime[$i]).' -> ';					    				}				    				}									$outread .= '<br>';			    				}		    				}						}					}					$info_list[$key]['systemwigsout'] = $outread;				}				if(isset($value['sourcetype']))				{					if($value['sourcetype'] == '1')					{						$info_list[$key]['sourcetype'] = '网红单';					}					else if($value['sourcetype'] == '2')					{						$info_list[$key]['sourcetype'] = '批发单';					}					else if($value['sourcetype'] == '3')					{						$info_list[$key]['sourcetype'] = '线下单';					}					else if($value['sourcetype'] == '4')					{						$info_list[$key]['sourcetype'] = '售后单';					}					else if($value['sourcetype'] == '5')					{						$info_list[$key]['sourcetype'] = '其它';					}					else					{						$info_list[$key]['sourcetype'] = '';					}				}				if(isset($value['js']))				{					if($value['js'] == '0')					{						$info_list[$key]['js'] = 'Ground Advantage';					}					else if($value['js'] == '1')					{						$info_list[$key]['js'] = 'PRIORITY';					}					else if($value['js'] == '2')					{						$info_list[$key]['js'] = 'EXPRESS';					}					else if($value['js'] == '3')					{						$info_list[$key]['js'] = 'IP';					}					else if($value['js'] == '4')					{						$info_list[$key]['js'] = 'FICP';					}				}				if(isset($value['type']))				{					$type = $this->warehouse->read($value['type']);				    $info_list[$key]['type'] = $type['title'];				}				if(isset($value['xdcs']))				{					if($sj == 'fullorder')					{						$xdcs = $this->customer->get_email($data['email'],$data['shop']);					}					else					{						$xdcs = $this->customersmt->get_shopdata($data['shop'],$data['name'],$data['address']);					}					$info_list[$key]['xdcs'] = (isset($xdcs['num']))?(($xdcs['num']==0)?1:$xdcs['num']):1;				}				if(isset($value['dbapi']) || isset($value['scapi']))				{					$jmlist = '';$shuliang = '';					$classid = $this->classid->sku();					$dbapi = explode(';',trim($value['fpdata'],';'));					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);						$jmlist .= $jm.'<br>';						$shuliang .= (isset($ts[2])?$ts[2]:'未知').'<br>';						$pm = array_filter($pm);//去除空值						$zh = implode(" ",$pm);						$zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));					}					if(isset($value['dbapi']))					{					    $info_list[$key]['dbapi'] = $jmlist;					}					else					{					    $info_list[$key]['scapi'] = $shuliang;					}				}								if(isset($value['dbapi']) && isset($value['scapi']))				{					$jmlist = '';$shuliang = '';					$classid = $this->classid->sku();					$dbapi = explode(';',trim($value['fpdata'],';'));					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);						$jmlist .= $jm.'<br>';						$shuliang .= (isset($ts[2])?$ts[2]:'未知').'<br>';						$pm = array_filter($pm);//去除空值						$zh = implode(" ",$pm);						$zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));					}					$info_list[$key]['dbapi'] = $jmlist;					$info_list[$key]['scapi'] = $shuliang;				}												if(isset($value['cpfpdata']))				{					$fpread = '';					$cpfpdata = explode(';',trim($value['fpdata'],';'));					foreach ($cpfpdata as $v) 					{						$va = explode('|',trim($v,'|'));						if(isset($va[1])){						    $fpread .= $va[1].'; ';						}else{						    $fpread .="合并单没有产品异常标记";						}											}					$info_list[$key]['cpfpdata'] = $fpread;				}				unset($info_list[$key]['id']);				unset($info_list[$key]['fpdata']);            }			$fzh = "";			foreach ($fexcelzh as $v)		    {				$fzh .= "<td>".$v."</td>";			}						$data = array($shouldmoney.' CNY');            $title = $fexcel['title'].'-'.date('Ymd',time());            $titlename = "<table border=1>            <tr>"            .$fzh.            "</tr>            </table>";			$tail = "\n";            $filename = $title.".xls";            $this->excel->get_fz5($info_list,$titlename,$filename,$tail,$kong);	    }	}		//上传运单	public function _waybill($arg_array)	{		$readid = $arg_array[0];		$dataorder = array();$datashop = array();$dataex = array();$datack = array();		/*  订单加入键值-k  */		$fdata = $this->fullorder->find_all('shop = "'.$readid.'" and dtime > "'.(time()-30*24*3600).'" and review > 4 and dlz < 1 and state = 207');		foreach ($fdata as $v) 		{			$dataorder[$v['orderinfo']] = $v;		}		$sdata = $this->fullordersmt->find_all('shop = "'.$readid.'" and dtime > "'.(time()-30*24*3600).'" and review > 4 and state = 207 and (dlz < 1 or dlz = 3)');		foreach ($sdata as $v) 		{			$dataorder[$v['orderinfo']] = $v;		}		$tdata = $this->fullordertt->find_all('shop = "'.$readid.'" and dtime > "'.(time()-30*24*3600).'" and review > 4 and state = 207 and (dlz < 1 or dlz = 3)');		foreach ($tdata as $v) 		{			$dataorder[$v['orderinfo']] = $v;		}		$xdata = $this->fullorderxw->find_all('shop = "'.$readid.'" and dtime > "'.(time()-30*24*3600).'" and review > 4 and state = 207 and (dlz < 1 or dlz = 3)');		foreach ($xdata as $v) 		{			$dataorder[$v['orderinfo']] = $v;		}		/*  订单加入键值-j  */		/*  店铺加入键值-j  */		$fshop = $this->shop->find_all('1=1');		foreach ($fshop as $v) 		{			$datashop[$v['id']] = $v;		}		/*  店铺加入键值-k  */		/*  快递加入键值-j  */		$fex = $this->express->find_all('1=1');		foreach ($fex as $v) 		{			$dataex[$v['id']] = $v;		}		/*  快递加入键值-k  */		/*  仓库加入键值-k  */		$fwh = $this->warehouse->find_all('1=1');		foreach ($fwh as $v) 		{			$datack[$v['id']] = $v;		}		/*  仓库加入键值-j  */		$fs = $this->notice->get_ordertatus(216);//216成功状态		if(is_numeric($readid) == false || $readid < 1)		{			echo json_encode(array('msg'=>'店铺信息错误!','success'=>true));exit;		}		$dir = '/data/excel/'.date('Ymd',time()).'/';		$config['upload_path'] = '.'.$dir ;		$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);        $config['allowed_types'] = 'xls|xlsx|csv';        $config['max_size'] = 10240;		$this->load->library('upload', $config);		$this->upload->initialize($config);        if ($this->upload->do_upload('userfile'))        {			$full_path = $dir.$this->upload->data('file_name');			$fileName = '.' . $full_path;            if (!file_exists($fileName)) 			{				echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;            }			else			{				require_once "./data/excel/PHPExcel/IOFactory.php";				$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件				$phpExcel->setActiveSheetIndex(0);// 设置为默认表				$sheetCount = $phpExcel->getSheetCount();// 获取表格数量				$row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数				$column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数				++$column;//如果列数大于26行				$list = array();				for ($i = 2; $i <= $row; $i++) // 行数循环				{					$data = array();                    for ($c = 'A'; $c != $column; $c++)  // 列数循环	                {						$data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();                    }					$list[] = $data;                }			}			$i = 0;$j = 0;$ed = array();$cscs = array();			$this->db->trans_begin();		    foreach ($list as $key=>$value)		    {				$ddh = preg_replace('/\D/s','',$value['0']);				$ydh = preg_replace('/\W/s','',$value['1']);				$shop = $datashop[$readid];				if($shop['type'] == '269')				{					$orid = $readid.$ddh;				}				else				{					$orid = $ddh;				}				if(isset($dataorder[$orid])) 				{					if($shop['type'] == 269)//独立站前缀需要添加ID					{						$time = time();						$xg = $dataorder[$orid];						$oldw = $xg['waybill'];					    $ex = $dataex[$xg['express']];					    $warehouse = $datack[$xg['type']];						$msg = $ydh;						$xg['waybill'] = $ydh;						$fs = $this->notice->find_all("shop = '".$xg['shop']."' and message = '1' and state = '1' and type = '4' and ktime < '$time' and jtime > '$time'");						if(isset($fs[0]))						{							$fs = $fs[0];							$fs['email'] = $this->emaildata->read($fs['email']);							if(($xg['dlzemail'] == 1 && $msg != $oldw) || $xg['dlzemail'] == 0)							{								$ck = $this->notice->get_god($xg,$shop,$ex,$fs);								if($ck == 1)								{									$ckemail = '邮件发送成功,';					    			$this->fullorder->save(array('dlzemail'=>1,'dlzemailtime'=>time()),$xg['id']);								}							}						}						if($msg != $oldw)						{				    		if($xg['source'] != 1)				    		{								$ms = $this->message->find_all("express like '%,".$xg['express'].",%'");								if(!isset($ms[0]))								{									$ms = $this->message->read(2);								}								else								{									$ms = $ms[0];								}								$ddh = substr($xg['orderinfo'],1);								$shopifyid = $xg['shopify'];				        		//独立站地址更新订单状态、物流信息								$shopname = $shop['brandname'];  //店铺名								$buyername = $xg['bname'];   //Bill Name								$email_call = $shop['shopid']; //发货人邮箱;								$phone = $shop['shopphone'];   //发货人电话								$track_type = $ex['title'];   //快递名称								$service = $ex['title'];   //快递追踪名称								$track_link = $ex['url'];   //快递查询网址								$logistics_number = $ydh;    //运单号								$t= array('%buyername%','%email_call%','%track_type%','%service%','%track_link%','%logistics_number%','%shop%','%phone%','%jtime%');								$h= array($buyername,$email_call,$track_type,$service,$track_link,$logistics_number,$shopname,$phone,$ex['yjtime']);								$remark = str_replace($t,$h,$ms['content']);			    				@$gx = $this->api->get_gx($ddh,$ydh,$xg,$shop,$ex,$remark,$shopifyid);				    		}				    		else if($xg['source'] == 1)				    		{					    		$gx['res'] = 3;					    		$gx['state'] = 216;				    		}						}						else						{							$gx['res'] = $xg['dlz'];							$gx['state'] = $xg['state'];						}						$xg['iscode'] = $ex['title'];		        		$xg['url'] = $shop['shopname'];						@$chuanshu = $this->api->get_paypal($xg);						//$this->afspaypal->insert(array('number'=>$xg['number'],'cs'=>$chuanshu));						$this->fullorder->save(array('waybill'=>$msg,'state'=>$gx['state'],'dlz'=>$gx['res']),$xg['id']);						/**					    $xg = $dataorder[$arg_array[0].$ddh];					    $ex = $dataex[$xg['express']];					    $warehouse = $datack[$xg['type']];					    if($xg['source'] != 1 && $ex['iscode'] != 'Other' && $xg['state'] == '207')				        {					        //独立站地址更新订单状态、物流信息					        $gx = $this->api->get_gx($ddh,$ydh,$xg,$shop,$ex,$xg['msg'],$xg['msg'],$dataorder[$orid]['shopify']);						    if(!isset($gx['res']))						    {							    $ed[] = array($ddh.'-更新失败');							    $j++;							    continue;						    }						    $this->fullorder->save(array('waybill'=>$ydh,'dlz'=>$gx['res'],'state'=>$gx['state']),$xg['id']);						    if($gx['res'] == 1 && $fs)						    {						        $ck = $this->_email($fs['content'],$xg,$warehouse['company']);						    }					    }					    else if($xg['source'] == 1 && $xg['state'] == '207')				        {						    $this->fullorder->save(array('waybill'=>$ydh,'dlz'=>3,'state'=>216),$xg['id']);						    if($fs)					        {						        $ck = $this->_email($fs['content'],$xg,$warehouse['company']);				            }					    }					    else					    {						    $ed[] = array($ddh.'-状态错误');						    $j++;						    continue;					    }						**/					}					else if($shop['type'] == 270)//速卖通对接发货声明					{						$xg = $dataorder[$ddh];					    $ex = $dataex[$xg['express']];					    $warehouse = $datack[$xg['type']];					    if($xg['source'] != 1 && $ex['aecode'] != 'Other' && $xg['library'] == 2 && ($xg['dlz'] == '0' || $xg['dlz'] == '2'))				        {					        $result = $this->apismt->get_out($ydh,'all',$xg['orderinfo'],$ex['aecode'],$sp['code']);							if(isset($result['result_success']) && $result['result_success'] == "true")							{								$this->fullordersmt->save(array('waybill'=>$ydh,'state'=>209,'dlz'=>1),$xg['id']);								/** 合并信息处理开始-发货声明 **/								if($xg['merge'] != '0')								{									$hdata = $this->fullordersmt->find_all("merge = '".$xg['merge']."' and id != '".$xg['id']."' and dlz = '0' and source != 1");$l=0;									foreach ($hdata as $v) 									{										 $result = $this->apismt->get_out($ydh,'all',$v['orderinfo'],$ex['aecode'],$sp['code']);					                     if(isset($result['result_success']) && $result['result_success'] == "true")					                     {										      $this->fullordersmt->save(array('waybill'=>$ydh,'state'=>209,'dlz'=>1),$v['id']);									     }										 else										 {											  $ed[] = array($v['orderinfo'].'-合并单发货声明失败,请在ERP上手动操作此单');						    		  	  	  $j++;						    		  	  	  continue;										 }										 $l++;										 if($l > 10)										 {											 break;										 }									}								}								/** 合并信息处理结束开始 **/							}							else							{								$ed[] = array($ddh.'-发货声明失败');						    	$j++;						    	continue;							}					    }						else if($xg['source'] != 1  && $ex['aecode'] != 'Other' && $xg['dlz'] == '1' && $xg['library'] == 2)//修改声明				        {					        $obtain = $this->apismt->get_obtain($xg['orderinfo'],$sp['code']);//修改声明先查询之前物流信息					        if(isset($obtain['logistics_no']))					        {					            $result = $this->apismt->get_editout($obtain['logistics_no'],$ydh,'all',$xg['orderinfo'],$obtain['service_name'],$ex['aecode'],$sp['code']);					        }					        if(isset($result['result_success']) && $result['result_success'] == "true")					        {						        $this->fullordersmt->save(array('waybill'=>$ydh),$xg['id']);								/** 合并信息处理开始-修改声明 **/								if($xg['merge'] != '0')								{									$hdata = $this->fullordersmt->find_all("merge = '".$xg['merge']."' and id != '".$xg['id']."' and dlz != 1 and source != 1");$l=0;									foreach ($hdata as $v) 									{										$obtain = $this->apismt->get_obtain($v['orderinfo'],$sp['code']);//修改声明先查询之前物流信息					       			    if(isset($obtain['logistics_no']))					        		    {					            		    $result = $this->apismt->get_editout($obtain['logistics_no'],$ydh,'all',$v['orderinfo'],$obtain['service_name'],$ex['aecode'],$sp['code']);					                     }					                     if(isset($result['result_success']) && $result['result_success'] == "true")					                     {										      $this->fullordersmt->save(array('waybill'=>$ydh),$v['id']);									     }										 else										 {											  $ed[] = array($v['orderinfo'].'-合并单修改发货声明失败,请在ERP上手动操作此单');						    		  	  	  $j++;						    		  	  	  continue;										 }										 $l++;										 if($l > 10)										 {											 break;										 }									}								}								/** 合并信息处理结束开始 **/					        }					        else					        {						        $ed[] = array($ddh.'-修改发货声明失败');						    	$j++;						    	continue;					        }					    }					    else if($xg['source'] == 1 && $xg['state'] == '207')				        {						    $this->fullordersmt->save(array('waybill'=>$ydh,'dlz'=>3,'state'=>216),$xg['id']);					    }						else				        {						    $this->fullordersmt->save(array('waybill'=>$ydh),$xg['id']);					    }					}									}								else				{					$ed[] = array($ddh.'-单号错误或重复操作');					$i++;					continue;				}				sleep(1);//停留1秒			}			if ($this->db->trans_status() === FALSE)			{    			$this->db->trans_rollback();			}			else			{    			$this->db->trans_commit();			}			if($i+$j > 0)			{				$time = date('Ymd',time());				$title = '错误信息-'.$time;        		$titlename = "<table border=1><tr><td>错误详情</td></tr></table>";				$tail = "\n";        		$filename = $title.".xls";        		$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);				$dir = '/data/excel/'.$time.'/';				$file_name = 'error_'.$time.rand(1000,9999);				if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);				$myfile = fopen(".".$dir.$file_name.".xls", "w") or die();				fwrite($myfile,$ecl);				fclose($myfile);				$error = $dir.$file_name.'.xls';				echo json_encode(array('msg'=>'添加成功,'.$i.'条异常,'.$j.'条失败','error'=>$error,'success'=>true));exit;			}			else			{				echo json_encode(array('msg'=>'添加成功!','error'=>1,'success'=>true));exit;			}        }		else		{			echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;		}    }		//上传速卖通订单	public function _order($arg_array)	{		$dataorder = array();$datashop = array();$dataex = array();$datack = array();		/*  订单加入键值-k  */		$fdata = $this->fullorder_smt->find_all('dtime >'.(time()-5*24*3600));		foreach ($fdata as $v) 		{			$dataorder[$v['orderinfo']] = $v;		}		/*  订单加入键值-j  */		$dir = '/data/excel/'.date('Ymd',time()).'/';		$config['upload_path'] = '.'.$dir ;		$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);        $config['allowed_types'] = 'xls|xlsx|csv';        $config['max_size'] = 10240;		$this->load->library('upload', $config);		$this->upload->initialize($config);        if ($this->upload->do_upload('userfile'))        {			$full_path = $dir.$this->upload->data('file_name');			$fileName = '.' . $full_path;            if (!file_exists($fileName)) 			{				echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;            }			else			{				require_once "./data/excel/PHPExcel/IOFactory.php";				$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件				$phpExcel->setActiveSheetIndex(0);// 设置为默认表				$sheetCount = $phpExcel->getSheetCount();// 获取表格数量				$row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数				$column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数				++$column;//如果列数大于26行				$list = array();				for ($i = 2; $i <= $row; $i++) // 行数循环				{					$data = array();                    for ($c = 'A'; $c != $column; $c++)  // 列数循环	                {						$data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();                    }					$list[] = $data;                }			}			$i = 0;$j = 0;$ed = array();$tytime = time();		    foreach ($list as $key=>$value)		    {				$value['2'] =  preg_replace('/\D/s','',$value['2']);				if($value['2'] && !isset($dataorder[$value['2']])) 				{					$num = $this->fullorder_smt->find_count('gtime = "'.date('Ymd',time()).'"');					$post['source'] = 2;//订单类型:1.线下订单2.PC3.手机					$post['state'] = 207;//订单状态:207等待发货					$post['review'] = 6;//审核状态:1.未送审2.待审核3.不通过4取消重审5.审核通过6.自动通过					$post['reviewtime'] = $tytime;//审核时间					$post['print'] = 2;//打印状态:1.不可打印2.未打印3.已打印					$post['library'] = 1;//出库状态:1.未出库2.已出库3.已退库					$post['libraryconfirm'] = 1;//出库确认:1.不允许2.允许					if($post['print'] != 3)					{					    $post['librarynot'] = "订单未打印,未审核或未通过";//不能出库原因					}					$value['1'] = trim($value['1'],' ');					$shortname = explode('-',$value['1']);					$shortname = $this->shop->get_shortname($shortname[0]);					if(!$shortname)					{						$ed[] = array($value['1'].'-编码有问题');					    $i++;						continue;					}					$post['shop'] = $shortname['id']?$shortname['id']:0;//速卖通					$post['user'] = '无';					$post['number'] = $value['1'];//编号 					$post['orderinfo'] = $value['2'];//订单号					$post['client'] = preg_replace('/( | | |\s)/',' ',$value['3']);//客户名称					$post['buytime'] = $tytime;//时间转UX					$post['dtime'] = $tytime;//订单时间					$post['gtime'] = date('Ymd',$tytime);//格式化时间					//$post['pay'] = $this->input->post('pay',true);//支付方式					$post['capital'] = 3;//资金状态					$post['type'] = 5;//发货仓库					$post['currency'] = 219;//币种					$post['currencytitle'] = 'USD';//币种名称					$post['freight'] = 0;//运费					$post['expressmoney'] = 0;//物流金额					$post['shouldmoney'] = 0;//应收金额					$post['budget'] = 0;//应到金额*店铺到帐金额比					$orderremarks = '';//订单备注					$post['shipremarks'] = $value['12'];//仓库品名					$post['email'] = '';//邮箱					$post['name'] = preg_replace('/( | | |\s)/',' ',$value['3']);//名字					$post['phone'] = $value['10'];//电话					$post['country'] = 192;//国家					$ct = $this->country->get_ename($value['9']);//国家					$post['al'] = $ct['lb'];//国家二字码					$post['province'] = $value['8'];//省、州					$post['city'] = $value['6'];//城市					$post['zipcode'] = $value['7'];//邮编					$post['address'] = $value['4'];//地址1					$post['address2'] = $value['5']?$value['5']:'';//地址2					$post['express'] = 2;//快递					$post['printtype'] = 1;//打印类型					$post['fpdata'] = '';//购买产品内容					$post['sbpm'] = 'Hair Sample';//申报品名					$post['zwpm'] = '假发';//中文品名					$post['ts'] = $value['17'];//条数					$post['dtsbjz'] = 15;//单条申报价					$post['zsbjz'] = 15;//总申报价					$post['zzl'] = 0.5;//总重量					$post['zjs'] = 1;//总件数					$post['quantity'] = 1;//数量					$post['paypal'] = '';//支付号					$post['guarantee'] = '';//卖家保障					$post['zzl'] = $value['13'];//总重量					$post['bx'] = $value['14'];//总重量					$post['qm'] = $value['15'];//总重量					$post['js'] = $value['16'];//总重量					$barcode = $this->usps->get_address(array('address'=>$value['4'],'address2'=>$value['5'],'city'=>$value['6'],'province'=>$value['8'],'zipcode'=>$value['7']));					if(isset($barcode['Address']['Error']['Description']))					{						$ed[] = array($value['1'].'-'.$barcode['Address']['Error']['Description']);					    $i++;					}					else					{					    $this->fullorder_smt->insert($post);						}				}				else				{					$ed[] = array($value['1'].'-单号错误或重复操作');					$i++;				}				sleep(2);//停留2秒			}			if($i+$j > 0)			{				$time = date('Ymd',time());				$title = '错误信息-'.$time;        		$titlename = "<table border=1><tr><td>错误详情</td></tr></table>";				$tail = "\n";        		$filename = $title.".xls";        		$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);				$dir = '/data/excel/'.$time.'/';				$file_name = 'error_'.$time.rand(1000,9999);				if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);				$myfile = fopen(".".$dir.$file_name.".xls", "w") or die();				fwrite($myfile,$ecl);				fclose($myfile);				$error = $dir.$file_name.'.xls';				echo json_encode(array('msg'=>'添加成功,'.$i.'条异常,'.$j.'条失败','error'=>$error,'success'=>true));exit;			}			else			{				echo json_encode(array('msg'=>'添加成功!','error'=>1,'success'=>true));exit;			}        }		else		{			echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;		}    }	public function _email($content,$data,$shopname)	{		$express = $this->express->read($data['express']);		$t= array('$userName','$orderid','$trackingNumber','$expressCompany','$contactPerson','$mobileNo','$zip','$recipientAddress');//需要被替换的内容		$h= array($data['client'],$data['orderinfo'],$data['waybill'],$express['servicename'],$data['name'],$data['phone'],$data['zipcode'],$data['address']);//替换的内容		$content = str_replace($t,$h,$content);		$this->load->library('email');				$config['protocol'] = 'smtp';		$config['smtp_host'] = 'smtpdm-ap-southeast-1.aliyun.com';		$config['smtp_port'] = 465; 		$config['smtp_user'] = 'service@email.supernovahair.com';		$config['smtp_pass'] = 'LONGyihair374';		$config['smtp_crypto'] = 'ssl';		$config['crlf'] = "\r\n"; 		$config['newline'] = "\r\n";		$this->email->initialize($config);		$this->email->from('service@email.supernovahair.com',$shopname);		$this->email->to($data['email']);//收件		$this->email->subject('The product you purchased has a new progress');//标题		$this->email->message($content);//内容		if ( ! $this->email->send())        {			return 2;        }		else		{			return 1;		}	}	//导出订单excel	public function _cs()	{		if(isset($_GET['fexcel']))  		{			if(isset($_SESSION['api']))		    {			    $user = $this->user->get_api($_SESSION['api']);			    $usp = $user;		        $fgshop = "";$sid = "";		        $user = explode('|',trim($user['shop'],'|'));			    foreach ($user as $value) 		        {				    $fgshop .= " shop = ".$value." or";				    $sid .= " id = ".$value." or";			    }		    }			$dowid = $this->input->get('a');			$wid = "";			if($dowid != "")			{				$id_arr =  explode(',',rtrim($dowid,','));				foreach ($id_arr as $v) 		        {					$wid  .= " id = 0 or";                    $wid  .= " id = '$v' or";                }				$wid = " and".rtrim($wid,'or');			}			$fexcel = $this->input->get('fexcel',true);			$page = $this->input->get('page',true);		    $perpage = $this->input->get('perpage',true);			$warehouse = $this->input->get('warehouse',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);			$state = $this->input->get('state',true);			$review = $this->input->get('review',true);			$type = $this->input->get('type',true);			$express = $this->input->get('express',true);			$orderinfo = $this->input->get('orderinfo',true);			$user = $this->input->get('user',true);			$client = $this->input->get('name',true);			$waybill = $this->input->get('waybill',true);			$number = $this->input->get('number',true);			$email = $this->input->get('email',true);			$dlz = $this->input->get('dlz',true);			$library = $this->input->get('library',true);			$libraryconfirm = $this->input->get('libraryconfirm',true);			$print = $this->input->get('print',true);			$timetkk = $this->input->get('timetkk',true);			$timetjj = $this->input->get('timetjj',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$timetkk = strtotime($timetkk);			$timetjj = strtotime($timetjj);			$where = "mergeid = 0 and (".rtrim($fgshop,'or').")";			if($warehouse)            {                $where  .= " and type = '$warehouse'";            }			if($timetk && $timetj)            {				$timetj = $timetj+24*3600;                $where  .= " and dtime > '$timetk' and dtime < '$timetj'";            }			if($timetkk && $timetjj)            {                $where  .= " and librarytime > '$timetkk' and librarytime < '$timetjj'";            }			if($library)            {                $where  .= " and library = '$library'";            }			if($print)            {                $where  .= " and print = '$print'";            }			if($shop)            {                $where  .= " and shop = '$shop'";            }			if($source)            {                $where  .= " and source = '$source'";            }			if($state)            {				$where  .= " and state = '$state'";            }			if($review)            {                $where  .= " and review = '$review'";            }			if($type)            {                $where  .= " and type = '$type'";            }			if($express)            {                $where  .= " and express = '$express'";            }			if($orderinfo)            {                $where  .= " and orderinfo = '$orderinfo'";            }			if($user)            {                $where  .= " and user = '$user'";            }			if($client)            {                $where  .= " and client like '%$client%'";            }			if($waybill)            {                $where  .= " and waybill = '$waybill'";            }			if($number)            {                $where  .= " and number = '$number'";            }			if($email)            {                $where  .= " and email = '$email'";            }			if($dlz)            {                $where  .= " and waybill != '' and dlz = 0";            }			if($dlz)            {                $where  .= " and libraryconfirm = '$libraryconfirm'";            }			$fexcel = $this->fullorderexcel->read($fexcel);			$fexceleq = explode("|",rtrim($fexcel['content'],'|'));			foreach ($fexceleq as $k=>$v) 		    {				$fexceleq[$k] = explode('-',$v);				$num[$k] = $fexceleq[$k][0];			}			//array_multisort($num,SORT_ASC,$fexceleq);//重新排序			$feq = "";			foreach ($fexceleq as $k=>$v) 		    {				$feq .= $v[1].',';			}			$feq = rtrim($feq,',');			$fexcelzhw = explode('|',rtrim($fexcel['contentzh'],'|'));			foreach ($fexcelzhw as $k=>$v) 		    {				$fexcelzhw[$k] = explode('-',$v);				$numb[$k] = $fexcelzhw[$k][0];			}			//array_multisort($numb,SORT_ASC,$fexcelzhw);//重新排序			$fexcelzh = array();			foreach ($fexcelzhw as $k=>$v) 		    {				$fexcelzh[] = $v[1];			}            //取得信息列表            $info_list = $this->fullorder->find_all($where.$wid,$feq,'id desc');			 //格式化数据			 $i = 1;$shouldmoney = 0;$hl=1;            foreach ($info_list as $key=>$value) 		    {				if(isset($value['currencytitle']))				{					if($value['currencytitle'] != "CNY")					{						$hl=$value['hl'];					}					$shouldmoney=$shouldmoney+($value['shouldmoney']*$hl);					$budget=$budget+($value['budget']*$hl);					$currency=$currency+(($value['shouldmoney']-$value['budget'])*$hl);					$refund=$refund+($value['refund']*$hl);				}				if(isset($value['shop']))				{					$shop = $this->shop->read($value['shop']);				    $info_list[$key]['shop'] = $shop['shopname'];				}				if(isset($value['dtime']))				{					$info_list[$key]['dtime'] = date('Y-m-d H:i:s',$value['dtime']);				}				if(isset($value['country']))				{					$country = $this->country->read($value['country']);				    $info_list[$key]['country'] = $country['name'];				}				if(isset($value['type']))				{					$type = $this->warehouse->read($value['type']);				    $info_list[$key]['type'] = $type['title'];				}				if(isset($value['express']))				{					$express = $this->express->read($value['express']);					if($express)					{						$info_list[$key]['express'] = $express['servicename'];					}					else					{				        $info_list[$key]['express'] = '未选择';					}				}            }			echo $timetkk;	    }	}		public function _gggs($sku,$s,$j,$k)	{		$companytitle = array(9=>3,10=>2,11=>1,12=>4);		$this->load->database();		$this->db->select('id');    				  $this->db->from('crowd_whlabel');   				      $this->db->where('warehouse', '5');   				      $this->db->where('sku', $sku);    				  $this->db->where('state', '0');    				  $this->db->limit($s,$k);    				  $query = $this->db->get();    				  $ids = array_column($query->result_array(), 'id');    				  if (!empty($ids)) 					  {        				  // 更新        				  $this->db->where_in('id', $ids);						  $this->db->update('crowd_whlabel', array('companytitle' => $companytitle[$j]));       				      return $this->db->affected_rows();					  }	}	public function _xxpl()	{				 $this->load->database();    $data = ['type' => ''];    $this->db->update('crowd_whlabel', $data);	$wt = array();			$whlabel_type = $this->whlabel_type->find_all();			foreach ($whlabel_type as $v) 			{				$wt[$v['title']] = $v['id'];			}					/*  订单加入键值-j  */		$dir = '/data/excel/'.date('Ymd',time()).'/';		$config['upload_path'] = '.'.$dir ;		$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);        $config['allowed_types'] = 'xls|xlsx|csv';        $config['max_size'] = 10240;		$this->load->library('upload', $config);		$this->upload->initialize($config);        if ($this->upload->do_upload('userfile'))        {			$full_path = $dir.$this->upload->data('file_name');			$fileName = '.' . $full_path;            if (!file_exists($fileName)) 			{				echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;            }			else			{				require_once "./data/excel/PHPExcel/IOFactory.php";				@$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件				@$phpExcel->setActiveSheetIndex(0);// 设置为默认表				$sheetCount = $phpExcel->getSheetCount();// 获取表格数量				$row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数				$column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数				++$column;//如果列数大于26行				$list = array();				for ($i = 2; $i <= $row; $i++) // 行数循环				{					$data = array();                    for ($c = 'A'; $c != $column; $c++)  // 列数循环	                {						$data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();                    }					$list[] = $data;                }			}			$wt = array();			$whlabel_type = $this->whlabel_type->find_all();			foreach ($whlabel_type as $v) 			{				$wt[$v['title']] = $v['id'];			}			$j = 0;$ed = array();$e = 0;$c = 0;$cs = array();			foreach ($list as $v)		    {						 $this->load->database();    // 设置更新数据    $data = ['type' => $wt[$v[1]]];    // 添加条件:SKU 为 123456 且 warehouse 为 5    $this->db->where('SKU', $v[0]);    $this->db->where('warehouse', '5');    // 批量更新    $this->db->update('crowd_whlabel', $data);			}									/** 导入缺货			$time = time();							$whlabel = $this->whlabel->get_sku($v[0]);				if($whlabel)				{					$this->whlabel_qh->insert(array('sku'=>$whlabel['sku'],'features'=>$whlabel['features'],'num'=>$v['1'],'gtime'=>date('Ym',$time),'gxtime'=>date('Ymd',$time)));				}				else				{					$ed[] = $v['0'];					$j++;				}			}			**/			/**			更换等级			 $this->load->database();    // 设置更新数据    $data = ['type' => $wt[$v[1]]];    // 添加条件:SKU 为 123456 且 warehouse 为 5    $this->db->where('SKU', $v[0]);    $this->db->where('warehouse', '5');    // 批量更新    $this->db->update('crowd_whlabel', $data);						**/			/**			$whlabel_type = $this->whlabel_type->find_all();			foreach ($whlabel_type as $v) 			{				$wt[$v['title']] = $v['id'];			}			foreach ($list as $v)		    {				$w = $this->whlabel->find_all("sku = '".$v[0]."' and warehouse = 5");				if($w && isset($wt[$v[1]]))				{					foreach ($w as $val)		    		{						$this->whlabel->save(array('type'=>$wt[$v[1]]),$val['id']);					}				}				else				{					$ed[] = array($v[0],$v[1]);					$j++;				}			}			**/										if($e > 0)			{				$time = date('Ymd',time());				$title = '错误信息-'.$time;        		$titlename = "<table border=1><tr><td>错误详情</td></tr></table>";				$tail = "\n";        		$filename = $title.".xls";        		@$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);				$dir = '/data/excel/'.$time.'/';				$file_name = 'error_'.$time.rand(1000,9999);				if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);				$myfile = fopen(".".$dir.$file_name.".xls", "w") or die();				fwrite($myfile,$ecl);				fclose($myfile);				$error = $dir.$file_name.'.xls';				echo json_encode(array('msg'=>$j.'条异常,','error'=>$error,'success'=>true));exit;			}			else			{				echo json_encode(array('msg'=>'添加成功!'.$c,'success'=>true));exit;			}        }		else		{			echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;		}    }			public function _skuzh()	{		/*  订单加入键值-j  */		$dir = '/data/excel/'.date('Ymd',time()).'/';		$config['upload_path'] = '.'.$dir ;		$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);        $config['allowed_types'] = 'xls|xlsx|csv';        $config['max_size'] = 10240;		$this->load->library('upload', $config);		$this->upload->initialize($config);        if ($this->upload->do_upload('userfile'))        {			$full_path = $dir.$this->upload->data('file_name');			$fileName = '.' . $full_path;            if (!file_exists($fileName)) 			{				echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;            }			else			{				require_once "./data/excel/PHPExcel/IOFactory.php";				@$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件				@$phpExcel->setActiveSheetIndex(0);// 设置为默认表				$sheetCount = $phpExcel->getSheetCount();// 获取表格数量				$row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数				$column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数				++$column;//如果列数大于26行				$list = array();				for ($i = 2; $i <= $row; $i++) // 行数循环				{					$data = array();                    for ($c = 'A'; $c != $column; $c++)  // 列数循环	                {						$data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();                    }					$list[] = $data;                }			}			$dictionaries = $this->typeclass->find_all('spare!= "" and classid != 1 and classid != 2 and classid != 3 and classid != 4 and classid != 5 and classid != 11 and classid != 16 and classid != 17 and classid != 20 and classid != 21 and classid != 23 and classid != 24 and classid != 29 and classid != 30 and classid != 31 and classid != 32');			$dtc = array();			foreach ($dictionaries as $v) 			{				if(stripos($v['spare'],'|') !== false)//如果有多个值				{					$v['spare'] = explode('|',$v['spare']);					foreach ($v['spare'] as $k=>$vs) 		        	{						if(stripos($v['zh'],'|') !== false)						{							$vzh = explode('|',$v['zh']);							$dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$vzh[$k],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);						}						else						{					   	 $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);						}					}				}				else				{					$dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$v['spare']);				}						}			$dictionaries2 = $this->typeclass->find_all();			foreach ($dictionaries2 as $v)			{				$dtctitle[$v['id']] = $v['title'];			}			/*  匹配结束  */    			/*  价格加入  */  			$money = array();			$productdescribe = $this->productdescribe->find_all('1=1');			foreach ($productdescribe as $v) 			{				$money[$v['number']] = array();			}			/*  价格加入  */			/*  匹配ID加入  */			$int = array();			$intdata = $this->typeclass->find_all('classid=14','id,spare');			foreach ($intdata as $v) 			{				$v['spare'] = explode('|',$v['spare']);				$int[$v['id']] = $v['spare'][0];			}				/*  匹配ID加入  */			$zjsku = array();			$shopsku = $this->shopsku->find_all();			foreach ($shopsku as $val) 			{				$ss = explode(',',trim($val['shop'],','));				foreach ($ss as $v) 			    {					if(isset($zjsku[$v]))					{						$zjsku[$v] .= ','.trim($val['sku'],',');					}					else					{						$zjsku[$v] = trim($val['sku'],',');					}				}			}				/*  匹配ID结束  */			$q = '1;';			$is = $this->is->find_all('1=1','*','number asc');//获取仓库平匹配表			$shop = $this->shop->read(19);			if(isset($zjsku[$shop['id']]))//判断是否找到店铺SKU			{				$sku = rtrim($sku,',').','.$zjsku[$shop['id']];			}			$ed = array();			foreach ($list as $v)		    {				$r = $this->api->matching(trim($q,';'),$v['2'],$dtc,$money,$int,$dtctitle,$shop);				$p = '';				$product = explode(';',trim($r['product'],';'));				if($r['title'] != '' && $product)				{			    	foreach ($product as $val) 			    	{				    	$vc = explode('|',$val);						if(isset($vc[1]))						{				    	    $p .= $vc[1].'<br>';						}			    	}					$r['title'] = str_replace(array('<','>'),array('<','>'),$r['title']);			    	$ed[] = array($v['0'],$v['1'],$r['title'],$v['3'],$v['4'],$v['5']);				}				else				{					$ed[] = array($v['0'],$v['1'],$v['2'].' SKU错误',$v['3'],$v['4'],$v['5']);				}			}										$time = date('Ymd',time());			$title = 'sku转换'.$time;        	$titlename = "<table border=1><tr><td>退款日期</td><td>订单号</td><td>SKU</td><td退款金额</td><td退款情况具体描述</td><可用/不可用</td></tr></table>";			$tail = "\n";        	$filename = $title.".xls";        	@$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);			$dir = '/data/excel/'.$time.'/';			$file_name = 'sku转换 '.$time.rand(1000,9999);			if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);			$myfile = fopen(".".$dir.$file_name.".xls", "w") or die();			fwrite($myfile,$ecl);			fclose($myfile);			$error = $dir.$file_name.'.xls';			echo json_encode(array('msg'=>'转换成功!','error'=>$error,'success'=>true));exit;        }		else		{			echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;		}    }		public function _xxpl_b()	{		$dataorder = array();$datashop = array();$dataex = array();$datack = array();		/*  订单加入键值-k  */		$fdata = $this->fullordersmt->find_all('dtime >'.(time()-10*24*3600));		foreach ($fdata as $v) 		{			$dataorder[$v['orderinfo']] = $v;		}		/*  订单加入键值-j  */		$dir = '/data/excel/'.date('Ymd',time()).'/';		$config['upload_path'] = '.'.$dir ;		$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);        $config['allowed_types'] = 'xls|xlsx|csv';        $config['max_size'] = 10240;		$this->load->library('upload', $config);		$this->upload->initialize($config);        if ($this->upload->do_upload('userfile'))        {			$full_path = $dir.$this->upload->data('file_name');			$fileName = '.' . $full_path;            if (!file_exists($fileName)) 			{				echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;            }			else			{				require_once "./data/excel/PHPExcel/IOFactory.php";				@$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件				@$phpExcel->setActiveSheetIndex(0);// 设置为默认表				$sheetCount = $phpExcel->getSheetCount();// 获取表格数量				$row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数				$column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数				++$column;//如果列数大于26行				$list = array();				for ($i = 2; $i <= $row; $i++) // 行数循环				{					$data = array();                    for ($c = 'A'; $c != $column; $c++)  // 列数循环	                {						$data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();                    }					$list[] = $data;                }			}			$i = 0;$j = 0;$ed = array();$time = time();		    foreach ($list as $key=>$value)		    {				$shop = $this->shop->get_shopname($value['2']);//通过店铺名称查找店铺				if(!$shop)				{					$ed[] = array($value['0'].'-无此店铺');					$i++;continue;				}				$post['buytime'] = strtotime($value['6']);//付款时间				$value['0'] =  preg_replace('/\D/s','',$value['0']);				if($value['0'] && !isset($dataorder[$value['0']])) 				{					$post['source'] = 2;//订单类型:1.线下订单2.PC3.手机					$post['state'] = 207;//订单状态:207等待发货					$post['review'] = 6;//审核状态:1.未送审2.待审核3.不通过4取消重审5.审核通过6.自动通过					$post['reviewtime'] = $time;//审核时间					$post['print'] = 2;//打印状态:1.不可打印2.未打印3.已打印					$post['library'] = 1;//出库状态:1.未出库2.已出库3.已退库					$post['libraryconfirm'] = 1;//出库确认:1.不允许2.允许					$post['dtime'] = $time;//订单时间					$post['capital'] = 3;//资金状态					$post['currency'] = 219;//币种					$post['currencytitle'] = 'USD';//币种名称					$post['freight'] = 0;//运费					$post['expressmoney'] = 0;//物流金额					$post['shouldmoney'] = 0;//应收金额					if($post['print'] != 3)					{					    $post['librarynot'] = "订单未打印";//不能出库原因					}										$post['gtime'] = date('Ymd',$post['buytime']);//格式化时间					$num = $this->fullordersmt->find_count('gtime = "'.date('Ymd',$post['buytime']).'" and shop = "'.$shop['id'].'"','id');					$post['number'] = $shop['shortname'].'-'.substr(date('ymd',$post['buytime']),1).'-'.(substr(strval($num+1+1000),1,3));//编号					$post['user'] = $shop['shopuser'];//店铺负责人					$post['orderinfo'] = $value['0'];//订单号					$post['type'] = $value['7'];//发货仓库					$post['shop'] = $shop['id'];//店铺					$post['shouldmoney'] =  $value['3'];//订单金额					$post['product'] =  $value['4']?$value['4']:'';//商品名称					$post['pay'] =  $value['5'];//付款方式					$post['paypal'] =  $value['1']?$value['1']:'';//交易号					$post['orderremarks'] =  $value['8']?$value['8']:'';//订单备注					$post['shipremarks'] =  $value['9'];//仓库品名					$post['client'] = preg_replace('/( | | | |\s)/',' ',$value['10']);//公司名					$post['name'] = preg_replace('/( | | | |\s)/',' ',$value['11']);//收货人					$post['phone'] = $value['12'];//电话					$ct = $this->country->get_ename(preg_replace('/( | | | |\s)/',' ',$value['13']));//国家					if(!$ct)					{						$ed[] = array($value['0'].'-无此国家');					    $i++;continue;					}					$post['country'] = $ct['id'];//国家					$post['al'] = $ct['lb'];//国家二字码					$post['province'] = $value['14'];//省、州					$post['city'] = $value['15'];//城市					$post['zipcode'] = $value['16'];//邮编					$post['address'] = $value['17'];//地址1					$post['address2'] = $value['18']?$value['18']:'';//地址2					$yga = $value['3'];$ygb = $shop['estimaterate'];			        $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额					$post['sbpm'] = $value['19'];//申报品名					$post['zwpm'] = $value['20'];//中文品名					$post['ts'] = $value['21'];//条数					$post['dtsbjz'] = $value['22'];//单条申报价					$post['zsbjz'] = $value['23'];//总申报价					$post['zzl'] = $value['24'];//总重量					$post['zjs'] = $value['25'];//总件数					$express = $this->express->get_servicename(preg_replace('/( | | | |\s)/',' ',$value['26']));					if(!$express)					{						$ed[] = array($value['0'].'-无此快递方式');					    $i++;continue;					}                    $post['express'] = $express['id'];//快递					$post['printtype'] = 1;//打印类型 1.运单.2.发货单					$post['fpdata'] = '';//购买产品内容					$this->fullordersmt->insert($post);				}				else				{					$ed[] = array($value['0'].'-单号错误或重复操作');					$i++;				}				sleep(2);//停留2秒			}			if($i+$j > 0)			{				$time = date('Ymd',time());				$title = '错误信息-'.$time;        		$titlename = "<table border=1><tr><td>错误详情</td></tr></table>";				$tail = "\n";        		$filename = $title.".xls";        		@$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);				$dir = '/data/excel/'.$time.'/';				$file_name = 'error_'.$time.rand(1000,9999);				if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);				$myfile = fopen(".".$dir.$file_name.".xls", "w") or die();				fwrite($myfile,$ecl);				fclose($myfile);				$error = $dir.$file_name.'.xls';				echo json_encode(array('msg'=>'添加成功,'.$i.'条异常,'.$j.'条失败','error'=>$error,'success'=>true));exit;			}			else			{				echo json_encode(array('msg'=>'添加成功!','error'=>1,'success'=>true));exit;			}        }		else		{			echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;		}    }		public function _scwd()	{		$dir = '/data/excel/'.date('Ymd',time()).'/';		$config['upload_path'] = '.'.$dir ;        $config['allowed_types'] = '*';        $config['max_size'] = 102400;		$this->load->library('upload', $config);		$this->upload->initialize($config);        if ($this->upload->do_upload('userfile'))        {			$full_path = $dir.$this->upload->data('file_name');			echo json_encode(array('msg'=>'成功!','wdurl'=>$full_path,'success'=>true));exit;		}		else		{			echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;		}	}		public function _jmexcel()	{		$setting = $this->setting->get_settings();		$excelpass = $setting['excelpass'];		$excelusernum = $setting['excelusernum'];		$exceljmnum = $setting['exceljmnum'];		$user = $this->user->get_api($_SESSION['api']);		if(!isset($user['exceltime']))		{			$this->session->sess_destroy();		    header("Location:/");		}		$post = $this->input->post(NULL, TRUE);		if(isset($post['data']))		{			$data = $this->input->post('data',true);			$data = str_replace("\n",",",$data);;			$data = explode(',',trim($data,','));			$d = '';$i = 0;			foreach ($data as $v) 		    {				if($v == '')				{					continue;				}				$j = $this->setting->get_jmexcelpass($v);				if($j == '')				{					$j = $v.' 信息不正确';				}				$d .= $j."<br />";				$i++;			}			if($i > $exceljmnum)			{				echo json_encode(array('msg'=>'每次解密数量不可超出'.$exceljmnum.'条','success'=>false));exit;			}			if($user['exceltime'] != date('Ymd',time()))			{				$this->user->save(array('exceltime'=>date('Ymd',time()),'excelnum'=>1),$user['id']);			}			else			{				if($user['excelnum'] > $excelusernum)				{					echo json_encode(array('msg'=>'今日此账号解密次数已使用完毕','success'=>false));exit;				}				else				{					$this->user->save(array('excelnum'=>$user['excelnum']+1),$user['id']);				}			}			echo json_encode(array('msg'=>$d,'success'=>true));exit;		}		$this->data['excelpass'] = $excelpass;		$this->data['excelusernum'] = $excelusernum;		$this->data['exceljmnum'] = $exceljmnum;		$this->_Template('fullorderexcel_jmexcel',$this->data);	}		//管理	public function _classid()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['page']))  		{		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',true);			$type = $this->input->post('type',true);			$where = "1=1 ";            //数据排序            $order_str = "id asc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }			if($type)			{				$where .= " and type = '$type'";			}            //取得信息列表            $info_list = $this->fullorderexcelclassid->find_all($where,'id,title,type',$order_str,$start,$perpage);		    $total = $this->fullorderexcelclassid->find_count($where);		    $pagenum = ceil($total/$perpage);		    $over = $total-($start+$perpage);		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));		    echo json_encode($rows);exit;		}		$this->_Template('fullorderexcel_classid',$this->data);	}	//添加	public function _classidadd()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['title']))		{			if($this->fullorderexcelclassid->insert($post))        	{				echo json_encode(array('msg'=>'添加成功','success'=>true));exit;       	 	}       		else        	{           		echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;        	}		}		$this->_Template('fullorderexcel_classidadd',$this->data);	}	//修改	public function _classidedit($arg_array)	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['id']))		{			$id = $this->input->post('id',true);			if($this->fullorderexcelclassid->save($post,$id))        	{         		echo json_encode(array('msg'=>'修改成功','success'=>true));exit;       	 	}       		else        	{           		echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;        	}		}		$arg_array = $arg_array[0];		$fullorderexcelclassid = $this->fullorderexcelclassid->read($arg_array);		$this->data['fullorderexcelclassid'] = $fullorderexcelclassid;		$this->_Template('fullorderexcel_classidedit',$this->data);	}}
 |