| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177 | <?php defined('BASEPATH') OR exit('No direct script access allowed');class Systemdownload extends Start_Controller {	public function __construct(){		parent::__construct();		$this->load->library('session');		$this->load->_model('Model_typeclass','typeclass');		$this->load->_model('Model_fullorder','fullorder');		$this->load->_model('Model_fullordertt','fullordertt');		$this->load->_model('Model_fullordersmt','fullordersmt');		$this->load->_model('Model_shop','shop');		$this->load->_model('Model_user','user');		$this->load->_model('Model_excel','excel');	}	//定义方法的调用规则 获取URI第二段值    public function _remap($arg,$arg_array)    {		if($arg == 'data')        {             $this->_data();        }		else if($arg == 'hd')        {             $this->_hd();        }		else if($arg == 'qm')        {             $this->_qm();        }		else if($arg == 'bh')        {             $this->_bh();        }		else if($arg == 'hsp')        {             $this->_hsp();        }		else if($arg == 'list')        {             $this->_list();        }		else if($arg == 'listread')        {             $this->_listread();        }		else		{			 $this->_index();		}    }		public function _index()	{		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);			$usp = $user;		    $fgshop = "";$sid = "";		    $usersp = explode('|',trim($user['shop'],'|'));			foreach ($usersp as $value) 		    {				$fgshop .= " shop = ".$value." or";				$sid .= " id = ".$value." or";			}		}		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));		$this->data['wlshop'] = $wlshop;		$this->_Template('systemdownload',$this->data);	}		public function getCombinationToString($val)    {        static $res = array();        if(empty($res))        {            $res = $val;        }		else		{            $list = array();            foreach ($res as $k => $v)			{                foreach ($val as $key => $value) 				{                    $list[] = $v.','.$value;                     }            }            $res = $list;        }        return $res;    }	public function _data()	{		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);			$usp = $user;		    $fgshop = "";$sid = "";$excelshop="";		    $usersp = explode('|',trim($user['shop'],'|'));			foreach ($usersp as $value) 		    {				$fgshop .= " shop = ".$value." or";				$sid .= " id = ".$value." or";			}			$userexcel = explode('|',trim($user['excelshop'],'|'));			foreach ($userexcel as $value) 		    {				$excelshop .= " shop =  ".$value." or";			}			if($excelshop != "")			{				$excelshop = "(".rtrim($excelshop,'or').")";			}		}		$post = $this->input->post(NULL, TRUE);		if(isset($_GET['category']))		{			$timetk = $this->input->get('timetk',true);			$timetj = $this->input->get('timetj',true);			$color = $this->input->get('color',true);			$lowe = $this->input->get('lowe',true);			$size = $this->input->get('size',true);			$grade = $this->input->get('grade',true);			$lacetype = $this->input->get('lacetype',true);			$category = $this->input->get('category',true);			$haircap = $this->input->get('haircap',true);			$shop = $this->input->get('shop',true);			$density = $this->input->get('density',true);			$time = $this->input->get('time',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);						$cw = array();		 	$class = array();$classdata = array();$lx = array();$pm = array();			$a = $this->typeclass->find_all('classid=6 or classid=7 or classid=8 or classid=10 or classid=12 or classid=13 or classid=19 or classid=20 or classid=21 or classid=22 or classid=23 or classid=24'); 		 	foreach ($a as $val)			{				$class[] = '-'.$val['id'].'-';			}		 	$b = $this->typeclass->find_all(); 		 	foreach ($b as $val)			{				$classdata[$val['id']] = $val['title'];				$lx[$val['id']] = $val['classid'];				$pm[$val['id']] = $val['zh'];			}			//Closure  wigs			$fpdata = '';			$category = explode('|',trim($category,'|'));			foreach ($category as $value) 		    {				$fpdata .= "fpdata like '%".$value."%' or ";			}			if(count($category) > 1)			{				$fpdata = "(".trim($fpdata,' or ').")";			}			else			{				$fpdata = trim($fpdata,' or ');			}			$where = "";			if($color)            {                $where  .= "fpdata like '%$color%' and ";            }			if($size)            {                $where  .= "fpdata like '%$size%' and ";            }			if($grade)            {                $where  .= "fpdata like '%$grade%' and ";            }			if($shop)            {                $where  .= "shop = '$shop' and ";            }			else			{				$where  .= $excelshop." and ";			}			if($lowe)            {				$arraydata[] = explode(',',rtrim($lowe,','));            }			else			{				$arraydata[] = array('z');			}			if($density)            {                $arraydata[] = explode(',',rtrim($density,','));            }			else			{				$arraydata[] = array('z');			}			if($lacetype)            {                $arraydata[] = explode(',',rtrim($lacetype,','));            }			else			{				$arraydata[] = array('z');			}			if($haircap)            {                $arraydata[] = explode(',',rtrim($haircap,','));            }			else			{				$arraydata[] = array('z');			}			$res = array();            foreach ($arraydata as $k => $v) 			{                $res = $this->getCombinationToString($v);            }			$warp = array();$cs = array();			if(!$res)			{				$res[0] = 1; 			}			foreach ($res as $resval) 			{				$wheredata = '';$btpm = '';				$resval = explode(',',rtrim($resval,','));				$lowe = $resval[0];$density = $resval[1];$lacetype = $resval[2];$haircap = $resval[3];				if($lowe != 'z')				{					 $wheredata .= "fpdata like '%$lowe%' and ";					 $btpm .= $pm[$lowe];				}				if($density != 'z')				{					 $wheredata .= "fpdata like '%$density%' and ";					 $btpm .= $pm[$density];				}				if($lacetype != 'z')				{					 $wheredata .= "fpdata like '%$lacetype%' and ";				}				if($haircap != 'z')				{					 $wheredata .= "fpdata like '%$haircap%' and ";					 $btpm .= $pm[$haircap];				}		 		$dataa = $this->fullorder->find_all($wheredata.$where.$time." > '$timetk' and ".$time." < '$timetj' and ".$fpdata,'number,fpdata','id desc');		 		$datab = $this->fullordersmt->find_all($wheredata.$where.$time." > '$timetk' and ".$time." < '$timetj' and ".$fpdata,'number,fpdata','id desc');				$datac = $this->fullordertt->find_all($wheredata.$where.$time." > '$timetk' and ".$time." < '$timetj' and ".$fpdata,'number,fpdata','id desc');				$data = array_merge($dataa,$datab,$datac);				//echo $where."librarytime > '$timetk' and librarytime < '$timetj' and ".$fpdata;				//echo "<pre>";				//print_r($where);				//exit;				$cs = array();				$pd = '';		 		$p = $class;  				$resdata = array();  				foreach ($data as $val)  				{	  				$f = explode(';',trim($val['fpdata'],';'));	  				foreach ($f as $v)      				{						if($color)            			{                			if(stripos($v,'-'.$color.'-') === false)							{								continue;							}            			}						if($lowe != 'z')            			{                			if(stripos($v,'-'.$lowe.'-') === false)							{								continue;							}           		 		}						if($size)            			{                			if(stripos($v,$size.',') === false)							{								continue;							}            			}						if($grade)            			{                			if(stripos($v,'-'.$grade.'-') === false)							{								continue;							}            			}						if($lacetype != 'z')            			{							$cs[] = $lacetype;                			if(stripos($v,'-'.$lacetype.'-') === false)							{								continue;							}            			}						if($density != 'z')            			{                			if(stripos($v,'-'.$density.'-') === false)							{								continue;							}            			}						if($haircap != 'z')            			{                			if(stripos($v,'-'.$haircap.'-') === false)							{								continue;							}            			}						$i = 0;						foreach ($category as $value) 		            	{							if(stripos($v,'-'.$value.'-') !== false)							{								$i++;							}			        	}						if($i > 0)		   				{							$e = explode('|',$v);							$d = str_replace($p,'-',$e[0]);							$q = str_replace(array('-163-','-164-','-165-','-166-'),'-',$e[0]);							$q = explode('-',trim($q,'-'));							$c = explode(',',$e[0]);							if(!isset($resdata[$d]))							{			   					if(stripos($v,'-126-') !== false)			   					{									if(!isset($q[4]) || !isset($pm[$q[4]]))									{										continue;									}				                	@$resdata[$d] = array($e[2],rtrim($classdata[$c[0]],'inch'),$q[4],1);//数量、尺寸、曲度、无蕾丝颜色			  					}								else if(stripos($v,'-127-') !== false)			   					{			       					if(isset($q[9]))				   					{					   					$s = ($q[9] != 68 && $q[9] != 69)?1:2; 				   					}				   					else				  					{										$s = 1;				   					}				   					$bt = (!isset($q[8]))?$q[5]:$q[8];//360类型的蕾丝尺寸直接显示为类型名称				   					if($lx[$q[5]] == '27')//如果是发块类型				   					{				       					$resdata[$d] = array($e[2],rtrim($classdata[$c[0]],'inch'),$q[5],$bt,$s);//数量、尺寸、类型、蕾丝尺寸、蕾丝颜色				  					 }			  					}			   					else			   					{				   					if(isset($q[8]))				   					{					   					$s = ($q[8] != 68 && $q[8] != 69)?1:2; 				   					}				  					else				  					{					   					$s = 1;				   					}				   					if(@$lx[$q[5]] == '18')//如果是头套种类				   					{				       					$resdata[$d] = array($e[2],rtrim($classdata[$c[0]],'inch'),$q[5],$s);//数量、尺寸、头套种类、蕾丝颜色				   					}			   					}							}							else							{								if(isset($e[2]))								{							    	if(is_array($e[2]) || !is_numeric($e[2]))							    	{								    	$cw[] = $v;								    	continue;							    	}							    	else							    	{               					    	 $resdata[$d][0] += $e[2];							    	}								}							}		   				}	  				 } 				 }				 $data =  array();				 foreach ($resdata as $v)				 {					 if(isset($v[4]))					 {						 if(!isset($data[$v[1].$v[2].$v[3].$v[4]]))						 {						 	$data[$v[1].$v[2].$v[3].$v[4]] = array($v[0],$v[1],$pm[$v[2]],$classdata[$v[3]],$v[4]);//$classdata[$v[2]]英文名,$pm[$v[2]]中文名						 }						 else						 {						 	$data[$v[1].$v[2].$v[3].$v[4]][0] += $v[0];						 }					 }					 else					 {						 if(!isset($data[$v[1].$v[2].$v[3]]))						 {							 $data[$v[1].$v[2].$v[3]] = array($v[0],$v[1],$pm[$v[2]],$v[3]);//$classdata[$v[2]]英文名,$pm[$v[2]]中文名						 }						 else						 {						 	$data[$v[1].$v[2].$v[3]][0] += $v[0];						 }					 }				 }				 $list = array();				 foreach ($data as $v)				 {				 	$x = (isset($v[4]))?$v[3]:$v[2];	    			 if(!isset($list[$v[2]]))					 {						 $list[$v[2]] = array();						 if(!isset($list[$v[2]][$x]))		    			 {							 $list[$v[2]][$x] = array();							 $list[$v[2]][$x][] = $v;						 }						 else						 {						 	$list[$v[2]][$x][] = $v;						 }					 }					 else					 {						 if(!isset($list[$v[2]][$x]))		   				 {						 	$list[$v[2]][$x] = array();						 	$list[$v[2]][$x][] = $v;						 }						 else						 {						 	$list[$v[2]][$x][] = $v;						 }					 }				 }				 foreach ($list as $key=>$val)				 {					 foreach ($val as $k=>$va)    				 {						 $dd = array();						 foreach ($va as $v)        				 {		    			 	$ss = (!isset($v[4]))?$v[3]:$v[4];		   					 if(!isset($dd[$v['1']]))		    				 {			   				 	$dd[$v['1']] = array();							 	$dd[$v['1']][$ss] = $v;		   					 }		    				 else		    				 {			    			 	$dd[$v['1']][$ss] = $v;		    				 }						 }						 ksort($dd);						 $list[$key][$k] = $dd;    				 }				 }				 $warp[] = array($btpm,$list);			}			//echo count($list);			//echo "<pre>";			//print_r($warp);			//exit;			$str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">       	 	<head>        	<!--[if gte mso 9]><xml>        	<x:ExcelWorkbook>       		<x:ExcelWorksheets>       		<x:ExcelWorksheet>        	<x:Name>EXCEL</x:Name>       		<x:WorksheetOptions>        	<x:Print>        	<x:ValidPrinterInfo />        	</x:Print>        	</x:WorksheetOptions>        	</x:ExcelWorksheet>        	</x:ExcelWorksheets>        	</x:ExcelWorkbook>        	</xml>        	<![endif]-->        	</head><body>";			foreach ($warp as $list)			{			foreach ($list[1] as $key=>$val)			{				$btnum = count($val);				$str .= "<table border=1>           		<tr>";				foreach ($val as $k=>$v)            	{            		$str .="<td style='background-color: #ffff00;color: #F00;width:20px'>".$k.' '.$list[0]."</td>            		<td>中棕</td>            		<td>透明</td>";				}           		$str .=  "</tr>            	</table>"; 				$str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'><tr>"; 		   		foreach ($val as $k=>$v)           		{			   		$str .= "<td><table border=1>";			   		foreach ($v as $sk=>$s)               		{				   		$xk1 = (isset($s[1]))?$s[1][0]:0;				  		$xk2 = (isset($s[2]))?$s[2][0]:0;                   		$str .="<tr><td style='color: #F00;'>".$sk."</td><td>".$xk1."</td><td>".$xk2."</td></tr>";			   		}			   		$str .= "</table></td>";		    	}				$str .=  "</table>";        		 }			 }			 $str .= "</body></html>"; 			 header( "Content-Type: application/vnd.ms-excel; name='excel'" ); 			 header( "Content-type: application/octet-stream" ); 			 header( "Content-Disposition: attachment; filename=".time().'.xls' ); 			 header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); 			 header( "Pragma: no-cache" ); 			 header( "Expires: 0" ); 			 exit($str);		}	}			public function _hd()//区分HD和其他颜色	{		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);			$usp = $user;		    $fgshop = "";$sid = "";$excelshop="";		    $usersp = explode('|',trim($user['shop'],'|'));			foreach ($usersp as $value) 		    {				$fgshop .= " shop = ".$value." or";				$sid .= " id = ".$value." or";			}			$userexcel = explode('|',trim($user['excelshop'],'|'));			foreach ($userexcel as $value) 		    {				$excelshop .= " shop =  ".$value." or";			}			if($excelshop != "")			{				$excelshop = "(".rtrim($excelshop,'or').")";			}		}		$post = $this->input->post(NULL, TRUE);		if(isset($_GET['category']))		{			$timetk = $this->input->get('timetk',true);			$timetj = $this->input->get('timetj',true);			$color = $this->input->get('color',true);			$lowe = $this->input->get('lowe',true);			$size = $this->input->get('size',true);			$grade = $this->input->get('grade',true);			$lacetype = $this->input->get('lacetype',true);			$category = $this->input->get('category',true);			$haircap = $this->input->get('haircap',true);			$shop = $this->input->get('shop',true);			$density = $this->input->get('density',true);			$time = $this->input->get('time',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);						$cw = array();		 	$class = array();$classdata = array();$lx = array();$pm = array();			$a = $this->typeclass->find_all('classid=6 or classid=7 or classid=8 or classid=10 or classid=12 or classid=13 or classid=19 or classid=20 or classid=21 or classid=22 or classid=23 or classid=24'); 		 	foreach ($a as $val)			{				$class[] = '-'.$val['id'].'-';			}		 	$b = $this->typeclass->find_all(); 		 	foreach ($b as $val)			{				$classdata[$val['id']] = $val['title'];				$lx[$val['id']] = $val['classid'];				$pm[$val['id']] = $val['zh'];			}			//Closure  wigs			$fpdata = '';			$category = explode('|',trim($category,'|'));			foreach ($category as $value) 		    {				$fpdata .= "fpdata like '%".$value."%' or ";			}			if(count($category) > 1)			{				$fpdata = "(".trim($fpdata,' or ').")";			}			else			{				$fpdata = trim($fpdata,' or ');			}			$where = "";			if($color)            {                $where  .= "fpdata like '%$color%' and ";            }			if($size)            {                $where  .= "fpdata like '%$size%' and ";            }			if($grade)            {                $where  .= "fpdata like '%$grade%' and ";            }			if($shop)            {                $where  .= "shop = '$shop' and ";            }			else			{				$where  .= $excelshop." and ";			}			if($lowe)            {				$arraydata[] = explode(',',rtrim($lowe,','));            }			else			{				$arraydata[] = array('z');			}			if($density)            {                $arraydata[] = explode(',',rtrim($density,','));            }			else			{				$arraydata[] = array('z');			}			if($lacetype)            {                $arraydata[] = explode(',',rtrim($lacetype,','));            }			else			{				$arraydata[] = array('z');			}			if($haircap)            {                $arraydata[] = explode(',',rtrim($haircap,','));            }			else			{				$arraydata[] = array('z');			}			$res = array();            foreach ($arraydata as $k => $v) 			{                $res = $this->getCombinationToString($v);            }			$warp = array();$cs = array();			if(!$res)			{				$res[0] = 1; 			}			foreach ($res as $resval) 			{				$wheredata = '';$btpm = '';				$resval = explode(',',rtrim($resval,','));				$lowe = $resval[0];$density = $resval[1];$lacetype = $resval[2];$haircap = $resval[3];				if($lowe != 'z')				{					 $wheredata .= "fpdata like '%$lowe%' and ";					 $btpm .= $pm[$lowe];				}				if($density != 'z')				{					 $wheredata .= "fpdata like '%$density%' and ";					 $btpm .= $pm[$density];				}				if($lacetype != 'z')				{					 $wheredata .= "fpdata like '%$lacetype%' and ";				}				if($haircap != 'z')				{					 $wheredata .= "fpdata like '%$haircap%' and ";					 $btpm .= $pm[$haircap];				}		 		$dataa = $this->fullorder->find_all($wheredata.$where.$time." > '$timetk' and ".$time." < '$timetj' and ".$fpdata,'number,fpdata','id desc');		 		$datab = $this->fullordersmt->find_all($wheredata.$where.$time." > '$timetk' and ".$time." < '$timetj' and ".$fpdata,'number,fpdata','id desc');				$datac = $this->fullordertt->find_all($wheredata.$where.$time." > '$timetk' and ".$time." < '$timetj' and ".$fpdata,'number,fpdata','id desc');				$data = array_merge($dataa,$datab,$datac);				//echo $where."librarytime > '$timetk' and librarytime < '$timetj' and ".$fpdata;				//echo "<pre>";				//print_r($where);				//exit;				$cs = array();				$pd = '';		 		$p = $class;  				$resdata = array();  				foreach ($data as $val)  				{	  				$f = explode(';',trim($val['fpdata'],';'));	  				foreach ($f as $v)      				{						if($color)            			{                			if(stripos($v,'-'.$color.'-') === false)							{								continue;							}            			}						if($lowe != 'z')            			{                			if(stripos($v,'-'.$lowe.'-') === false)							{								continue;							}           		 		}						if($size)            			{                			if(stripos($v,$size.',') === false)							{								continue;							}            			}						if($grade)            			{                			if(stripos($v,'-'.$grade.'-') === false)							{								continue;							}            			}						if($lacetype != 'z')            			{							$cs[] = $lacetype;                			if(stripos($v,'-'.$lacetype.'-') === false)							{								continue;							}            			}						if($density != 'z')            			{                			if(stripos($v,'-'.$density.'-') === false)							{								continue;							}            			}						if($haircap != 'z')            			{                			if(stripos($v,'-'.$haircap.'-') === false)							{								continue;							}            			}						$i = 0;						foreach ($category as $value) 		            	{							if(stripos($v,'-'.$value.'-') !== false)							{								$i++;							}			        	}						if($i > 0)		   				{							$e = explode('|',$v);							$d = str_replace($p,'-',$e[0]);							$q = str_replace(array('-163-','-164-','-165-','-166-'),'-',$e[0]);							$q = explode('-',trim($q,'-'));							$c = explode(',',$e[0]);							if(!isset($resdata[$d]))							{			   					if(stripos($v,'-126-') !== false)			   					{									if(!isset($q[4]) || !isset($pm[$q[4]]))									{										continue;									}				                	@$resdata[$d] = array($e[2],rtrim($classdata[$c[0]],'inch'),$q[4],1);//数量、尺寸、曲度、无蕾丝颜色			  					}								else if(stripos($v,'-127-') !== false)			   					{			       					if(isset($q[9]))				   					{					   					$s = ($q[9] != 335)?1:2; 				   					}				   					else				  					{										$s = 1;				   					}				   					$bt = (!isset($q[8]))?$q[5]:$q[8];//360类型的蕾丝尺寸直接显示为类型名称				   					if($lx[$q[5]] == '27')//如果是发块类型				   					{				       					$resdata[$d] = array($e[2],rtrim($classdata[$c[0]],'inch'),$q[5],$bt,$s);//数量、尺寸、类型、蕾丝尺寸、蕾丝颜色				  					 }			  					}			   					else			   					{				   					if(isset($q[8]))				   					{					   					$s = ($q[8] != 335)?1:2; 				   					}				  					else				  					{					   					$s = 1;				   					}				   					if(@$lx[$q[5]] == '18')//如果是头套种类				   					{				       					$resdata[$d] = array($e[2],rtrim($classdata[$c[0]],'inch'),$q[5],$s);//数量、尺寸、头套种类、蕾丝颜色				   					}			   					}							}							else							{								if(isset($e[2]))								{							    	if(is_array($e[2]) || !is_numeric($e[2]))							    	{								    	$cw[] = $v;								    	continue;							    	}							    	else							    	{               					    	 $resdata[$d][0] += $e[2];							    	}								}							}		   				}	  				 } 				 }				 $data =  array();				 foreach ($resdata as $v)				 {					 if(isset($v[4]))					 {						 if(!isset($data[$v[1].$v[2].$v[3].$v[4]]))						 {						 	$data[$v[1].$v[2].$v[3].$v[4]] = array($v[0],$v[1],$pm[$v[2]],$classdata[$v[3]],$v[4]);//$classdata[$v[2]]英文名,$pm[$v[2]]中文名						 }						 else						 {						 	$data[$v[1].$v[2].$v[3].$v[4]][0] += $v[0];						 }					 }					 else					 {						 if(!isset($data[$v[1].$v[2].$v[3]]))						 {							 $data[$v[1].$v[2].$v[3]] = array($v[0],$v[1],$pm[$v[2]],$v[3]);//$classdata[$v[2]]英文名,$pm[$v[2]]中文名						 }						 else						 {						 	$data[$v[1].$v[2].$v[3]][0] += $v[0];						 }					 }				 }				 $list = array();				 foreach ($data as $v)				 {				 	$x = (isset($v[4]))?$v[3]:$v[2];	    			 if(!isset($list[$v[2]]))					 {						 $list[$v[2]] = array();						 if(!isset($list[$v[2]][$x]))		    			 {							 $list[$v[2]][$x] = array();							 $list[$v[2]][$x][] = $v;						 }						 else						 {						 	$list[$v[2]][$x][] = $v;						 }					 }					 else					 {						 if(!isset($list[$v[2]][$x]))		   				 {						 	$list[$v[2]][$x] = array();						 	$list[$v[2]][$x][] = $v;						 }						 else						 {						 	$list[$v[2]][$x][] = $v;						 }					 }				 }				 foreach ($list as $key=>$val)				 {					 foreach ($val as $k=>$va)    				 {						 $dd = array();						 foreach ($va as $v)        				 {		    			 	$ss = (!isset($v[4]))?$v[3]:$v[4];		   					 if(!isset($dd[$v['1']]))		    				 {			   				 	$dd[$v['1']] = array();							 	$dd[$v['1']][$ss] = $v;		   					 }		    				 else		    				 {			    			 	$dd[$v['1']][$ss] = $v;		    				 }						 }						 ksort($dd);						 $list[$key][$k] = $dd;    				 }				 }				 $warp[] = array($btpm,$list);			}			//echo count($list);			//echo "<pre>";			//print_r($warp);			//exit;			$str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">       	 	<head>        	<!--[if gte mso 9]><xml>        	<x:ExcelWorkbook>       		<x:ExcelWorksheets>       		<x:ExcelWorksheet>        	<x:Name>EXCEL</x:Name>       		<x:WorksheetOptions>        	<x:Print>        	<x:ValidPrinterInfo />        	</x:Print>        	</x:WorksheetOptions>        	</x:ExcelWorksheet>        	</x:ExcelWorksheets>        	</x:ExcelWorkbook>        	</xml>        	<![endif]-->        	</head><body>";			foreach ($warp as $list)			{			foreach ($list[1] as $key=>$val)			{				$btnum = count($val);				$str .= "<table border=1>           		<tr>";				foreach ($val as $k=>$v)            	{            		$str .="<td style='background-color: #ffff00;color: #F00;width:20px'>".$k.' '.$list[0]."</td>            		<td>其它</td>            		<td>HD</td>";				}           		$str .=  "</tr>            	</table>"; 				$str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'><tr>"; 		   		foreach ($val as $k=>$v)           		{			   		$str .= "<td><table border=1>";			   		foreach ($v as $sk=>$s)               		{				   		$xk1 = (isset($s[1]))?$s[1][0]:0;				  		$xk2 = (isset($s[2]))?$s[2][0]:0;                   		$str .="<tr><td style='color: #F00;'>".$sk."</td><td>".$xk1."</td><td>".$xk2."</td></tr>";			   		}			   		$str .= "</table></td>";		    	}				$str .=  "</table>";        		 }			 }			 $str .= "</body></html>"; 			 header( "Content-Type: application/vnd.ms-excel; name='excel'" ); 			 header( "Content-type: application/octet-stream" ); 			 header( "Content-Disposition: attachment; filename=".time().'.xls' ); 			 header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); 			 header( "Pragma: no-cache" ); 			 header( "Expires: 0" ); 			 exit($str);		}	}			public function _bh()	{		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);			$usp = $user;		    $fgshop = "";$sid = "";$exsp = "";$excelshop="";		    $usersp = explode('|',trim($user['shop'],'|'));			foreach ($usersp as $value) 		    {				$fgshop .= " shop = ".$value." or";				$sid .= " id = ".$value." or";			}			$userexcel = explode('|',trim($user['excelshop'],'|'));			foreach ($userexcel as $value) 		    {				$excelshop .= " shop =  ".$value." or";				$exsp .= " id = ".$value." or";			}			if($excelshop != "")			{				$excelshop = "(".rtrim($excelshop,'or').")";			}		}		$cs = array();//测试		$post = $this->input->post(NULL, TRUE);		if(isset($_GET['excel']))		{			$shop = $this->input->get('shop',true);			$color = $this->input->get('color',true);			$grade = $this->input->get('grade',true);			$lowe = $this->input->get('lowe',true);			$lacetype = $this->input->get('lacetype',true);			$time = $this->input->get('time',true);			$timetk = $this->input->get('timetk',true);			$timetj = $this->input->get('timetj',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$where = "fpdata like '%-128-%' and ";//头套			$fpdata = '';			if($lacetype)			{				$lacetypefp = '';				$lacetypedata = explode(',',trim($lacetype,','));			    foreach ($lacetypedata as $value) 		        {				    $lacetypefp .= "fpdata like '%-".$value."-%' or ";			    }				$fpdata .= " and (".rtrim($lacetypefp,' or').")";			}			if($lowe)            {                $lowefp = '';				$lowedata = explode(',',trim($lowe,','));			    foreach ($lowedata as $value) 		        {				    $lowefp .= "fpdata like '%-".$value."-%' or ";			    }				$fpdata .= " and (".rtrim($lowefp,' or').")";            }			if($shop)            {                $where  .= "shop = '$shop' and ";            }			else			{				$where  .= $excelshop." and ";			}			if($color)            {                $where  .= "fpdata like '%$color%' and ";            }			if($grade)            {                $where  .= "fpdata like '%$grade%' and ";            }			$density = array();			$size = array();			$haircap = array();			$md = $this->typeclass->find_all("classid = '10'");//密度			foreach ($md as $val)			{				$density[$val['id']] = '';			}			$cd = $this->typeclass->find_all("classid = '14'",'*','id asc');//长度 and id != '774' and bqsku < 32之前的限制			foreach ($cd as $val)			{				$size[$val['id']] = $density;			}			$fm = $this->typeclass->find_all("classid = '6'");			foreach ($fm as $val)			{				$haircap[$val['id']] = $size;			}			$dataa = $this->fullorder->find_all($where.$time." > '$timetk' and ".$time." < '$timetj'".$fpdata,'number,fpdata','id desc');		 	$datab = $this->fullordersmt->find_all($where.$time." > '$timetk' and ".$time." < '$timetj'".$fpdata,'number,fpdata','id desc');			$datac = $this->fullordertt->find_all($where.$time." > '$timetk' and ".$time." < '$timetj'".$fpdata,'number,fpdata','id desc');			$data = array_merge($dataa,$datab,$datac);			$fpdata = array();			foreach ($data as $val)			{				$f = explode(';',trim($val['fpdata'],';'));				foreach ($f as $v)			    {					if(stripos($v,'-128-') === false)					{						continue;					}					if($color)            		{                		if(stripos($v,'-'.$color.'-') === false)						{							continue;						}            		}					if($grade)            		{                		if(stripos($v,'-'.$grade.'-') === false)						{							continue;						}            		}					if($lowe)            		{						$arraylowe = explode(',',trim($lowe,','));						$i = 0;						foreach ($arraylowe as $vv)			            {                		    if(stripos($v,'-'.$vv.'-') === false)						    {							    $i++;						    }						}						if($i == count($arraylowe))						{							continue;						}           		 	}					if($lacetype)            		{						$arraylacetype = explode(',',trim($lacetype,','));						$i = 0;						foreach ($arraylacetype as $vv)			            {                		    if(stripos($v,'-'.$vv.'-') === false)						    {							    $i++;						    }						}						if($i == count($arraylacetype))						{							continue;						}           		 	}					$fdd =  explode('|',trim($v,'|'));					$fddf =  explode('-',trim($fdd[0],'-'));					if(isset($fddf[7]))					{						$fpdata[] = array($fddf[4],$fddf[5],$fddf[7],trim($fddf[0],','),$fddf[6],$fdd[2],$val['number']);//曲度,蕾丝种类,密度,长度,发帽大小,数量					}				}			}						$tc = array();			$qbtc = $this->typeclass->find_all();			foreach ($qbtc as $val)			{				$tc[$val['id']] = $val['bqsku'];			}			$zh = array();			$qbzh = $this->typeclass->find_all();			foreach ($qbzh as $val)			{				$zh[$val['id']] = $val['zh'];			}			$qd = array();$td = '';			$qddata = $this->typeclass->find_all("classid = '15'");			foreach ($qddata as $val)			{				$qd[$val['id']] = 0;				$td .= '<td>'.$val['bqsku'].'</td>';			}						$zdata = array();			foreach ($fpdata as $val)			{				if(isset($zdata[$val[0].'|'.$val[1]]))				{					if(isset($zdata[$val[0].'|'.$val[1]][$val[4]][$val[3]][$val[2]]))					{						if($zdata[$val[0].'|'.$val[1]][$val[4]][$val[3]][$val[2]] == '')						{							$zdata[$val[0].'|'.$val[1]][$val[4]][$val[3]][$val[2]] = $val[5];						}						else						{					        $zdata[$val[0].'|'.$val[1]][$val[4]][$val[3]][$val[2]] += $val[5];						}					}				}				else				{					$zdata[$val[0].'|'.$val[1]] = $haircap;					if(isset($zdata[$val[0].'|'.$val[1]][$val[4]][$val[3]][$val[2]]))					{					    $zdata[$val[0].'|'.$val[1]][$val[4]][$val[3]][$val[2]] = $val[5];					}				}			}			foreach ($zdata as $key=>$value) 			{				foreach ($value as $ke=>$va) 				{					foreach ($va as $kk=>$vv) 				    {					    $i = 0;					    foreach ($vv as $v) 				        {						    if($v == '')						    {							    $i++;						    }					    }						if($i == count($density))					    {						    unset($zdata[$key][$ke][$kk]);					    }					}		    	}			}			foreach ($zdata as $key=>$value) 			{				$i = 0;				foreach ($value as $ke=>$va) 				{					if(empty($va))					{						$i++;					}					if($i == count($value))					{						unset($zdata[$key]);					}				}			}			//sort($zdata);//排序			//echo count($list);			//echo "<pre>";			//print_r($zdata);			//exit;			$str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">       	 	<head>        	<!--[if gte mso 9]><xml>        	<x:ExcelWorkbook>       		<x:ExcelWorksheets>       		<x:ExcelWorksheet>        	<x:Name>EXCEL</x:Name>       		<x:WorksheetOptions>        	<x:Print>        	<x:ValidPrinterInfo />        	</x:Print>        	</x:WorksheetOptions>        	</x:ExcelWorksheet>        	</x:ExcelWorksheets>        	</x:ExcelWorkbook>        	</xml>        	<![endif]-->        	</head><body>";			foreach ($zdata as $key=>$value) 			{ 			    $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 14px;background-color: #e2efda;'>"; 			    $key =  explode('|',$key);		    	$str .= "<tr><th colspan='3' align='center'><h3>".$zh[$key[0]].' '.$zh[$key[1]]."<h3></th></tr><tr height='50'>";				$y = 0;				foreach ($value as $ke=>$va)				{					$y++;					if($y == 2)					{						$backgrounda = '#ffff00';						$backgroundb = '#bad5df';					}					else					{						$backgrounda = '#e2efda';						$backgroundb = '#9bc2e6';					}					$str .= "<td><table border=1 style='font-family: Microsoft Yahei;font-size: 14px;background-color: ".$backgrounda.";'><tr><th colspan='".(count($density)+1)."' align='center'><h3>".$zh[$ke]."<h3></th></tr>";					$str .= "<tr><td align='center' style='background-color: ".$backgroundb.";'>尺寸/密度</td>";				    foreach ($density as $kk=>$vv)				    {					    $str .= "<td align='center'>".$tc[$kk]."</td>";				    }				    $str .= "</tr>";		    	    foreach ($va as $kk=>$vv) 				    {					    $str .= "<tr height='50'><td align='center' style='background-color: ".$backgroundb.";'><b>".$tc[$kk]."</b></td>";					    foreach ($vv as $v) 				        {						    $str .= "<td align='center'>".$v."</td>";					    }					    $str .= "</tr>";		    	    }					$str .= "</table></td>";				}				$str .= "</tr></table><br><br>";			}			 $str .= "</body></html>"; 			 header( "Content-Type: application/vnd.ms-excel; name='excel'" ); 			 header( "Content-type: application/octet-stream" ); 			 header( "Content-Disposition: attachment; filename=".time().'.xls' ); 			 header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); 			 header( "Pragma: no-cache" ); 			 header( "Expires: 0" ); 			 exit($str);		}		$wlshop = $this->shop->find_all('1=1 and '.rtrim($exsp,'or'));		$this->data['wlshop'] = $wlshop;		$this->_Template('systemdownload_bh',$this->data);	}			public function _hsp()	{		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);			$usp = $user;		    $fgshop = "";$sid = "";$excelshop="";		    $usersp = explode('|',trim($user['shop'],'|'));			foreach ($usersp as $value) 		    {				$fgshop .= " shop = ".$value." or";				$sid .= " id = ".$value." or";			}			$userexcel = explode('|',trim($user['excelshop'],'|'));			foreach ($userexcel as $value) 		    {				$excelshop .= " shop =  ".$value." or";			}			if($excelshop != "")			{				$excelshop = "(".rtrim($excelshop,'or').")";			}		}		$lx = array();		$b = $this->typeclass->find_all(); 		foreach ($b as $val)		{			$lx[$val['id']] = $val['classid'];		}		$cs = array();//测试		$post = $this->input->post(NULL, TRUE);		if(isset($_GET['excel']))		{			$type = $this->input->get('type',true);			$lace = $this->input->get('lace',true);			$color = $this->input->get('color',true);			$lowe = $this->input->get('lowe',true);			$grade = $this->input->get('grade',true);			$density = $this->input->get('density',true);			$lacetype = $this->input->get('lacetype',true);			$lacecolor = $this->input->get('lacecolor',true);			$time = $this->input->get('time',true);			$timetk = $this->input->get('timetk',true);			$timetj = $this->input->get('timetj',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			if($type == 1)			{			    $where = "fpdata like '%-128-%' and ".$excelshop." and ";//头套			}			else			{				if($lace == 1)				{				    $where = "fpdata like '%-127-%' and fpdata NOT LIKE '%-335-%' and ".$excelshop." and ";				}				else				{					$where = "fpdata like '%-127-%' and fpdata like '%-335-%' and ".$excelshop." and ";				}			}			$fpdata = '';$px = array();$fl = array();			if($lacetype)			{				$lacetypefp = '';				$lacetypedata = explode(',',trim($lacetype,','));			    foreach ($lacetypedata as $value) 		        {					$value = explode('|',$value);					$px[$value[0]] = '';					$val = explode('-',$value[1]);					    foreach ($val as $k=>$v) 		                {						    $fl[$v] = $value[0];				            $lacetypefp .= " fpdata like '%-".$v."-%' or ";					    }			    }				$fpdata .= " and (".rtrim($lacetypefp,' or').")";			}			$colortitle = '';			if($color)            {				if($color == 'a')				{                    $where  .= " fpdata NOT like '%-57-%' and ";				}				else				{                    $where  .= " fpdata like '%-$color-%' and ";					$colortitle = $this->typeclass->read($color);					$colortitle = $colortitle['zh'];				}            }			if($lowe)            {                $where  .= " fpdata like '%-$lowe-%' and ";            }			if($grade)            {                $where  .= " fpdata like '%-$grade-%' and ";            }			if($density)            {                $where  .= " fpdata like '%-$density-%' and ";            }			if($lacecolor)            {				if($lacecolor == 'a')				{                    $where  .= " fpdata NOT like '%-2071-%' and fpdata NOT like '%-2076-%' and ";				}				if($lacecolor == 'b')				{                    $where  .= " (fpdata like '%-2071-%' or fpdata like '%-2076-%') and ";				}            }			$size = array();$cc = array();			$cd = $this->typeclass->find_all("classid = '14' and id != '774' and id != '6' and id != '99' and id != '100'",'*','id asc');//长度			foreach ($cd as $val)			{				$cc[] = $val['bqsku'];				$size[$val['id']] = 0;			}			$dataa = $this->fullorder->find_all($where." $time > '$timetk' and $time < '$timetj'".$fpdata,'number,fpdata','id desc');		 	$datab = $this->fullordersmt->find_all($where." $time > '$timetk' and $time < '$timetj'".$fpdata,'number,fpdata','id desc');			$datac = $this->fullordertt->find_all($where." $time > '$timetk' and $time < '$timetj'".$fpdata,'number,fpdata','id desc');			$data = array_merge($dataa,$datab,$datac);			$fpdata = array();$cs[] = array();$css = '';			foreach ($data as $val)			{				$f = explode(';',trim($val['fpdata'],';'));				foreach ($f as $v)			    {					$v = str_replace(array('-163-','-164-','-165-','-166-'),'-',$v);					if($type == 1 && stripos($v,'-128-') === false)					{						continue;					}					else if($type == 2 && stripos($v,'-127-') === false)					{						continue;					}					if($color)            		{						if($color == 'a')						{                    		 if(stripos($v,'-57-') !== false)						    {							    continue;						    }						}						else						{                		    if(stripos($v,'-'.$color.'-') === false)						    {							    continue;						    }						}            		}					if($lowe)            		{                		if(stripos($v,'-'.$lowe.'-') === false)						{							continue;						}            		}					if($grade)            		{                		if(stripos($v,'-'.$grade.'-') === false)						{							continue;						}            		}					if($density)            		{                		if(stripos($v,'-'.$density.'-') === false)						{							continue;						}            		}					if($lacecolor)            		{						if($lacecolor == 'a')						{                    		if(stripos($v,'-2071-') !== false || stripos($v,'-2076-') !== false)							{								continue;							}						}						if($lacecolor == 'b')						{							if(stripos($v,'-2071-') === false && stripos($v,'-2076-') === false)							{								continue;							}						}            		}					if($lacetype)            		{						$arraylacetype = explode(',',trim($lacetype,','));						$i = 0;$j = 0;						foreach ($arraylacetype as $vv)			            {							$value = explode('|',$vv);					        $value = explode('-',trim($value[1],'-'));							$j += count($value);							foreach ($value as $vvv)			                {                		        if(stripos($v,'-'.$vvv.'-') === false)						        {							        $i++;						        }							}						}						if($i == $j)						{							continue;						}           		 	}					$fdd =  explode('|',trim($v,'|'));					$fddf =  explode('-',trim($fdd[0],'-'));					if($type == 1)					{												foreach ($fddf as $vl)			            {							if(isset($lx[$vl]) && $lx[$vl] == 18)							{								$fpdata[] = array($fl[$vl],trim($fddf[0],','),$fdd[2]);//蕾丝种类,长度,数量							}						}					}					else if($type == 2)					{					    if(isset($fl[$fddf[8]]))					    {						    $fpdata[] = array($fl[$fddf[8]],trim($fddf[0],','),$fdd[2]);//蕾丝种类,长度,数量					    }					}				}			}			foreach ($fpdata as $val)			{				if(isset($zdata[$val[0]]))				{					if(isset($zdata[$val[0]][$val[1]]))					{						$zdata[$val[0]][$val[1]] += $val[2];					}				}				else				{					$zdata[$val[0]] = $size;					if(isset($zdata[$val[0]][$val[1]]))					{						$zdata[$val[0]][$val[1]] += $val[2];					}				}			}			/**			foreach ($zdata as $key=>$value) 			{				foreach ($value as $ke=>$va) 				{					if($va == '0')					    {						    unset($zdata[$key][$ke]);					    }		    	}			}			**/			$tc = array();			$qbtc = $this->typeclass->find_all();			foreach ($qbtc as $val)			{				$tc[$val['id']] = $val['bqsku'];			}			$zh = array();			$qbzh = $this->typeclass->find_all();			foreach ($qbzh as $val)			{				$zh[$val['id']] = $val['zh'];			}			//$px = array('13*4'=>'','4*4'=>'','5*5'=>'','6*6'=>'','13*6'=>'','360'=>'','HD13*4'=>'','HD4*4'=>'','HD5*5'=>'','HD6*6'=>'','HD13*6'=>'');			foreach ($zdata as $k=>$v) 			{				$px[$k] = $v;			}			foreach ($px as $k=>$v) 			{				if(!$v)				{					unset($px[$k]);				}			}			$zdata = $px;			//sort($zdata);//排序			//echo count($list);			//echo "<pre>";			//print_r($zdata);			//exit;			$str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">       	 	<head>        	<!--[if gte mso 9]><xml>        	<x:ExcelWorkbook>       		<x:ExcelWorksheets>       		<x:ExcelWorksheet>        	<x:Name>EXCEL</x:Name>       		<x:WorksheetOptions>        	<x:Print>        	<x:ValidPrinterInfo />        	</x:Print>        	</x:WorksheetOptions>        	</x:ExcelWorksheet>        	</x:ExcelWorksheets>        	</x:ExcelWorkbook>        	</xml>        	<![endif]-->        	</head><body>";						    $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 14px;'>"; 		    	$str .= "<tr><td colspan='".(count($zdata)+1)."' align='center' height='30' width='50'>".date('Y-m-d',$timetk).' ~ '.date('Y-m-d',$timetj).' <b>'.$colortitle."</b></td></tr><tr>";				$str .= "<td><table border=1 style='font-family: Microsoft Yahei;font-size: 14px;'>";				$str .= "<tr><td align='center' height='30' width='50'>". iconv("UTF-8", "GBK",  '尺寸')."</td></tr>";				foreach ($cc as $kk=>$vv) 				{					$str .= "<tr><td align='center' height='30' width='50'><b>".$vv."</b></td>";					$str .= "</tr>";		    	}				$str .= "</table></td>";				foreach ($zdata as $key=>$value) 			    { 				    //$str .= "<td><table border=1 style='font-family: Microsoft Yahei;font-size: 14px;'><tr><td align='center' height='30' width='50'><b>".$key."</b></td></tr>";				    				    $str .= "<td><table border=1 style='font-family: Microsoft Yahei;font-size: 14px;'><tr><td align='center' height='30' width='50'><b>". iconv("UTF-8", "GBK",  $key)."</b></td></tr>";				   					foreach ($value as $kk=>$vv) 				    {						if($vv == '0')						{							$str .= "<tr><td align='center' height='30' width='50'></td>";						}						else						{							$str .= "<tr><td align='center' height='30' width='50'>".$vv."</td>";						}					    $str .= "</tr>";		    	    }					$str .= "</table></td>";				}				$str .= "</tr></table><br><br>";									 $str .= "</body></html>";			 header( "Content-Type: application/vnd.ms-excel; name='excel'" );			 header( "Content-type: application/octet-stream" );			 header( "Content-Disposition: attachment; filename=".time().'.xls' ); 			 header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); 			 header( "Pragma: no-cache" ); 			 header( "Expires: 0" ); 			 exit($str);		}		$this->_Template('systemdownload_hsp',$this->data);	}			public function _qm()//曲度和密度	{		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);			$usp = $user;		    $fgshop = "";$sid = "";$excelshop="";		    $usersp = explode('|',trim($user['shop'],'|'));			foreach ($usersp as $value) 		    {				$fgshop .= " shop = ".$value." or";				$sid .= " id = ".$value." or";			}			$userexcel = explode('|',trim($user['excelshop'],'|'));			foreach ($userexcel as $value) 		    {				$excelshop .= " shop =  ".$value." or";			}			if($excelshop != "")			{				$excelshop = "(".rtrim($excelshop,'or').")";			}		}		$post = $this->input->post(NULL, TRUE);		if(isset($_GET['excel']))		{			$timetk = $this->input->get('timetk',true);			$timetj = $this->input->get('timetj',true);			//$lacetype = $this->input->get('lacetype',true);			$lacetype = '';			$time = $this->input->get('time',true);			$timetk = time()-30*24*3600;			$timetj = time();			$where = "fpdata like '%-128-%' and shop != '9' and shop != '26' and ".$excelshop." and ";//头套			$fpdata = '';			if($lacetype)			{				$lacetype = explode(',',trim($lacetype,','));			    foreach ($lacetype as $value) 		        {				    $fpdata .= "fpdata like '%-".$value."-%' or ";			    }				$fpdata = " and (".rtrim($fpdata,' or').")";			}						$dataa = $this->fullorder->find_all($where."librarytime > '$timetk' and librarytime < '$timetj'".$fpdata,'number,fpdata','id desc');		 	$datab = $this->fullordersmt->find_all($where."librarytime > '$timetk' and librarytime < '$timetj'".$fpdata,'number,fpdata','id desc');			$datac = $this->fullordertt->find_all($where."librarytime > '$timetk' and librarytime < '$timetj'".$fpdata,'number,fpdata','id desc');			$data = array_merge($dataa,$datab,$datac);			$fpdata = array();			foreach ($data as $val)			{				$f = explode(';',trim($val['fpdata'],';'));				foreach ($f as $v)			    {					if($lacetype)					{					    foreach ($lacetype as $vv)			            {					        if(stripos($v,'-'.$vv.'-') !== false)						    {							    $fdd =  explode('|',trim($val['fpdata'],'|'));							    $fddf =  explode('-',trim($fdd[0],'-'));							    if(isset($fddf[7]))							    {							        $fpdata[] = array($fddf[4],$fddf[5],$fddf[7]);//曲度,蕾丝种类,密度							    }						    }					   }					}					else					{						$fdd =  explode('|',trim($val['fpdata'],'|'));						$fddf =  explode('-',trim($fdd[0],'-'));						if(isset($fddf[7]))						{							$fpdata[] = array($fddf[4],$fddf[5],$fddf[7]);//曲度,蕾丝种类,密度						}					}				}			}			$tc = array();			$qbtc = $this->typeclass->find_all();			foreach ($qbtc as $val)			{				$tc[$val['id']] = $val['bqsku'];			}			$qd = array();$td = '';			$qddata = $this->typeclass->find_all("classid = '15'");			foreach ($qddata as $val)			{				$qd[$val['id']] = 0;				$td .= '<td>'.$val['bqsku'].'</td>';			}						$zdata = array();			foreach ($fpdata as $val)			{				/**				if(isset($zdata[$tc[$val[1]].' '.$tc[$val[2]]]))				{					if(isset($zdata[$tc[$val[1]].' '.$tc[$val[2]]][$val[0]]))					{					    $zdata[$tc[$val[1]].' '.$tc[$val[2]]][$val[0]] += 1;					}				}				else				{					$zdata[$tc[$val[1]].' '.$tc[$val[2]]] = $qd;				}				**/				if(isset($zdata[$val[1].'|'.$val[2]]))				{					if(isset($zdata[$val[1].'|'.$val[2]][$val[0]]))					{					    $zdata[$val[1].'|'.$val[2]][$val[0]] += 1;					}				}				else				{					$zdata[$val[1].'|'.$val[2]] = $qd;					if(isset($zdata[$val[1].'|'.$val[2]][$val[0]]))					{					    $zdata[$val[1].'|'.$val[2]][$val[0]] += 1;					}				}			}			//echo count($list);			//echo "<pre>";			//print_r($zdata);			//exit;			$str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">       	 	<head>        	<!--[if gte mso 9]><xml>        	<x:ExcelWorkbook>       		<x:ExcelWorksheets>       		<x:ExcelWorksheet>        	<x:Name>EXCEL</x:Name>       		<x:WorksheetOptions>        	<x:Print>        	<x:ValidPrinterInfo />        	</x:Print>        	</x:WorksheetOptions>        	</x:ExcelWorksheet>        	</x:ExcelWorksheets>        	</x:ExcelWorkbook>        	</xml>        	<![endif]-->        	</head><body>";			$str .= "<table border=1 style='background-color: #2ca8a1;font-weight: bold;color:#fff;font-size: 14px;table-layout:fixed'><tr height='50' align='center'>			<td align='left'>产品</td>			".$td."			</tr></table>";			$str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 14px;'>"; 			foreach ($zdata as $key=>$value) 			{ 			    $key =  explode('|',$key);		    	$str .= "<tr height='50'><td align='center'><b>".$tc[$key[0]].' '.$tc[$key[1]]."</b></td>";						    	foreach ($value as $ke=>$va) 				{						if($va > 0)						{				            $str .= "<td align='center'><b>".$va."</b></td>";						}						else						{							$str .= "<td align='center'>".$va."</td>";						}		    	}				$str .= "</tr>\n";			}			 $str .= "</body></html>"; 			 header( "Content-Type: application/vnd.ms-excel; name='excel'" ); 			 header( "Content-type: application/octet-stream" ); 			 header( "Content-Disposition: attachment; filename=".time().'.xls' ); 			 header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); 			 header( "Pragma: no-cache" ); 			 header( "Expires: 0" ); 			 exit($str);		}	}		public function _list()	{		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);			$usp = $user;		    $fgshop = "";$sid = "";		    $usersp = explode('|',trim($user['shop'],'|'));			foreach ($usersp as $value) 		    {				$fgshop .= " shop = ".$value." or";				$sid .= " id = ".$value." or";			}		}		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));		$this->data['wlshop'] = $wlshop;		$this->_Template('systemdownload_list',$this->data);	}		public function _listread()	{		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);			$usp = $user;		    $fgshop = "";$sid = "";$excelshop="";		    $usersp = explode('|',trim($user['shop'],'|'));			foreach ($usersp as $value) 		    {				$fgshop .= " shop = ".$value." or";				$sid .= " id = ".$value." or";			}			$userexcel = explode('|',trim($user['excelshop'],'|'));			foreach ($userexcel as $value) 		    {				$excelshop .= " shop =  ".$value." or";			}			if($excelshop != "")			{				$excelshop = "(".rtrim($excelshop,'or').")";			}		}		$post = $this->input->post(NULL, TRUE);		if(isset($_GET['category']))		{			$timetk = $this->input->get('timetk',true);			$timetj = $this->input->get('timetj',true);			$color = $this->input->get('color',true);			$lowe = $this->input->get('lowe',true);			$size = $this->input->get('size',true);			$grade = $this->input->get('grade',true);			$lacetype = $this->input->get('lacetype',true);			$category = $this->input->get('category',true);			$shop = $this->input->get('shop',true);			$time = $this->input->get('time',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);						$cw = array();		 	$class = array();$classdata = array();$lx = array();$pm = array();$ttzllist = array();$hxlist = array();			$a = $this->typeclass->find_all('classid=6 or classid=7 or classid=8 or classid=10 or classid=12 or classid=13 or classid=19 or classid=20 or classid=21 or classid=22 or classid=23 or classid=24'); 		 	foreach ($a as $val)			{				$class[] = '-'.$val['id'].'-';			}		 	$b = $this->typeclass->find_all(); 		 	foreach ($b as $val)			{				$classdata[$val['id']] = $val['title'];				$lx[$val['id']] = $val['classid'];				$pm[$val['id']] = $val['zh'];			}			$ttzl = $this->typeclass->find_all("classid = '18'"); 			foreach ($ttzl as $val)			{				$ttzllist[$val['id']] = $val['classid'];			}			$hx = $this->typeclass->find_all("classid = '15'");			foreach ($hx as $val)			{				$hxlist[$val['id']] = $val['classid'];			}			//Closure  wigs			$fpdata = '';			$category = explode('|',trim($category,'|'));			foreach ($category as $value) 		    {				$fpdata .= "fpdata like '%".$value."%' or ";			}			if(count($category) > 1)			{				$fpdata = "(".trim($fpdata,' or ').")";			}			else			{				$fpdata = trim($fpdata,' or ');			}			$where = "shop != '9' and shop != '26' and ";			if($color)            {                $where  .= "fpdata like '%$color%' and ";            }			if($lowe)            {                $where  .= "fpdata like '%$lowe%' and ";            }			if($size)            {                $where  .= "fpdata like '%$size%' and ";            }			if($grade)            {                $where  .= "fpdata like '%$grade%' and ";            }			if($lacetype)            {                $where  .= "fpdata like '%$lacetype%' and ";            }			if($shop)            {                $where  .= "shop = '$shop' and ";            }			else			{				$where  .= $excelshop." and ";			}		 	$dataa = $this->fullorder->find_all($where.$time." > '$timetk' and ".$time." < '$timetj' and ".$fpdata,'number,fpdata','id desc');		 	$datab = $this->fullordersmt->find_all($where.$time." > '$timetk' and ".$time." < '$timetj' and ".$fpdata,'number,fpdata','id desc');			$datac = $this->fullordertt->find_all($where.$time." > '$timetk' and ".$time." < '$timetj' and ".$fpdata,'number,fpdata','id desc');			$data = array_merge($dataa,$datab,$datac);						//echo $where."librarytime > '$timetk' and librarytime < '$timetj' and ".$fpdata;			//echo "<pre>";			//print_r($data);			//exit;						$pd = '';		 	$p = $class;  			$resdata = array();  			foreach ($data as $val)  			{	  			$f = explode(';',trim($val['fpdata'],';'));	  			foreach ($f as $v)      			{					if($color)            		{                		if(stripos($v,'-'.$color.'-') === false)						{							continue;						}            		}					if($lowe)            		{                		if(stripos($v,'-'.$lowe.'-') === false)						{							continue;						}           		 	}					if($size)            		{                		if(stripos($v,$size.',') === false)						{							continue;						}            		}					if($grade)            		{                		if(stripos($v,'-'.$grade.'-') === false)						{							continue;						}            		}					if($lacetype)            		{                		if(stripos($v,'-'.$lacetype.'-') === false)						{							continue;						}            		}					$i = 0;					foreach ($category as $value) 		            {						if(stripos($v,'-'.$value.'-') !== false)						{							$i++;						}			        }					if($i > 0)		   			{						$e = explode('|',$v);						$d = str_replace($p,'-',$e[0]);						$q = str_replace(array('-163-','-164-','-165-','-166-','-782-','-79-','-80-','-81-','-497-'),'-',$e[0]);						$fl = explode(',',$q);//分离出尺寸和其它内容						$cpkey = str_replace('-','',$fl[1]);						$tt = explode('-',trim($fl[1],'-'));						$title = '';$fla='';$flb='';						foreach ($tt as $value) 		                {							if(isset($ttzllist[$value]))							{								if($ttzllist[$value] == '18')							    {									$fla = $value;								}							}							if(isset($hxlist[$value]))							{								if($hxlist[$value] == '15')							    {									$flb = $value;								}							}						}						//$c = explode(',',$e[0]);						if(!isset($resdata[$fla.$flb]) && $fla != '' && $flb != '')						{							if(stripos($pm[$fla],'|') !== false)							{								$pm[$fla] = explode('|',$pm[$fla]);								$pm[$fla] = $pm[$fla][0];							}							if(stripos($pm[$flb],'|') !== false)							{								$pm[$flb] = explode('|',$pm[$flb]);								$pm[$flb] = $pm[$flb][0];							}							$title = $pm[$fla].' '. $pm[$flb];			   				$resdata[$fla.$flb] = array('t'=>$title,'82'=>0,'83'=>0,'84'=>0,'85'=>0,'86'=>0,'87'=>0,'88'=>0,'89'=>0,'90'=>0,'91'=>0,'92'=>0,'93'=>0,'94'=>0,'95'=>0,'96'=>0,'97'=>0,'98'=>0,'99'=>0,'100'=>0,'469'=>0);							if(isset($resdata[$fla.$flb][$fl[0]]))							{							    $resdata[$fla.$flb][$fl[0]] += $e[2]; 							}						}						else if ($fla != '' && $flb != '' && isset($resdata[$fla.$flb][$fl[0]]))						{							 $resdata[$fla.$flb][$fl[0]] += $e[2]; 						}		   			}	  			 } 			 }			 rsort($resdata);			//echo count($list);			//echo "<pre>";			//print_r($list);			//exit;            			$str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">       	 	<head>        	<!--[if gte mso 9]><xml>        	<x:ExcelWorkbook>       		<x:ExcelWorksheets>       		<x:ExcelWorksheet>        	<x:Name>EXCEL</x:Name>       		<x:WorksheetOptions>        	<x:Print>        	<x:ValidPrinterInfo />        	</x:Print>        	</x:WorksheetOptions>        	</x:ExcelWorksheet>        	</x:ExcelWorksheets>        	</x:ExcelWorkbook>        	</xml>        	<![endif]-->        	</head><body>";			$str .= "<table border=1 style='background-color: #2ca8a1;font-weight: bold;color:#fff;font-size: 14px;table-layout:fixed'><tr height='50' align='center'>			<td align='left'>产品</td>			<td>6</td>			<td>8</td>			<td>10</td>			<td>12</td>			<td>14</td>			<td>16</td>			<td>18</td>			<td>20</td>			<td>22</td>			<td>24</td>			<td>26</td>			<td>28</td>			<td>30</td>			<td>32</td>			<td>34</td>			<td>36</td>			<td>38</td>			<td>40</td>			<td>42</td>			<td>44</td>			</tr></table>";			$str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 14px;'>"; 			foreach ($resdata as $key=>$value) 			{ 		    	$str .= "<tr height='50'>";		    	foreach ($value as $ke=>$va) 				{					if(is_numeric($va))					{						if($va > 0)						{				            $str .= "<td align='center'><b>".$va."</b></td>";						}						else						{							$str .= "<td align='center'>".$va."</td>";						}					}					else					{						$str .= "<td>".$va."</td>";					}		    	}				$str .= "</tr>\n";			}			 $str .= "</body></html>"; 			 header( "Content-Type: application/vnd.ms-excel; name='excel'" ); 			 header( "Content-type: application/octet-stream" ); 			 header( "Content-Disposition: attachment; filename=".time().'.xls' ); 			 header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); 			 header( "Pragma: no-cache" ); 			 header( "Expires: 0" ); 			 exit($str);			 		}	}}
 |