| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982 | <?php defined('BASEPATH') OR exit('No direct script access allowed');class Transfer extends Start_Controller {	public function __construct(){		parent::__construct();		$this->load->library('session');		$this->load->_model('Model_user','user');		$this->load->_model('Model_transfer','transfer');		$this->load->_model('Model_typeclass','typeclass');		$this->load->_model('Model_warehouse','warehouse');		$this->load->_model('Model_systemtransfer','systemtransfer');		$this->load->_model('Model_excel','excel');		$this->load->_model('Model_fullorder','fullorder');		$this->load->_model('Model_fullordertt','fullordertt');		$this->load->_model('Model_fullordersmt','fullordersmt');		$this->load->_model('Model_purchase','purchase');		$this->load->_model('Model_classid','classid');		$this->load->_model('Model_express','express');		$this->load->_model('Model_apiyy','apiyy');		$this->load->_model('Model_shop','shop');		$this->load->_model('Model_systemtransfer_cr','systemtransfer_cr');	}	//定义方法的调用规则 获取URI第二段值    public function _remap($arg,$arg_array)    {		if($arg == 'add')        {             $this->_add();        }		else if($arg == 'edit')        {             $this->_edit($arg_array);        }		else if($arg == 'del')        {             $this->_del();        }		else if($arg == 'print')        {             $this->_print();        }		else if($arg == 'number')        {             $this->_number();        }		else if($arg == 'numberprint')        {             $this->_numberprint();        }		else if($arg == 'operate')        {             $this->_operate();        }		else if($arg == 'out')        {             $this->_out();        }		else if($arg == 'excel')        {             $this->_excel();        }		else if($arg == 'bdbb')        {             $this->_bdbb();        }		else if($arg == 'rk')        {             $this->_rk();        }		else if($arg == 'ck')        {             $this->_ck();        }		else if($arg == 'jgl')//交工率        {             $this->_jgl();        }        else if($arg == 'linqi')        {             $this->_linqi();        }        else if($arg == 'overtime_export'){             $this->_overtime_export();        }		else		{			 $this->_index();		}    }	//管理	public function _index()	{		$t = array();		$typeclass = $this->typeclass->find_all();		foreach ($typeclass as $v)		{			$t[$v['id']] = $v['title'];		}		$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($type)			{				$where .= "and type = '$type'";			}            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }            //取得信息列表            $info_list = $this->transfer->find_all($where,'id,title,orvertime,overtime_one,overtime_two',$order_str,$start,$perpage);		    $total = $this->transfer->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('transfer',$this->data);	}	//添加	public function _add()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['title']))		{			$title = $this->input->post('title',true);			if($this->transfer->find_all("title = '$title'"))			{				echo json_encode(array('msg'=>'名称重复!','success'=>false));exit;			}			if($this->transfer->insert($post))        	{         		echo json_encode(array('msg'=>'添加成功','success'=>true));exit;       	 	}       		else        	{           		echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;        	}		}		$this->_Template('transfer_add',$this->data);	}	//修改	public function _edit($arg_array)	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['id']))		{			$id = $this->input->post('id',true);			$title = $this->input->post('title',true);			if($this->transfer->find_all("title = '$title' and id != '".$id."'"))			{				echo json_encode(array('msg'=>'名称重复!','success'=>false));exit;			}			if($this->transfer->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];		$transfer = $this->transfer->read($arg_array);		$this->data['transfer'] = $transfer;		$this->_Template('transfer_edit',$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->transfer->remove($v);            }            echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));		}    }		public function _print()	{		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);			$usp = $user;		    $sid = "";$wid="";$wtype="";			$userwh = explode('|',trim($user['warehouse'],'|'));			foreach ($userwh as $value) 		    {				$wid .= " id = ".$value." or";				$wtype .= " type = ".$value." or";			}		}		$post = $this->input->post(NULL, TRUE);		$classid = $this->classid->sku();		$pm = $classid;		$scsku = $classid;			if(isset($post['category']))			{				$list = array();$num = "";$title = "";$features = "";				$order = 0;				$xbqnum = $this->input->post('xbqnum',true);//打印数量				$t = $this->input->post('t',true);//打印数量				if($xbqnum > 99)				{					echo json_encode(array('msg'=>'打印数量不可超过99!','success'=>false));exit;				}				if($xbqnum < 1)				{					echo json_encode(array('msg'=>'打印数量错误!','success'=>false));exit;				}				$post['purchase'] = $this->input->post('purchase',true);//所属工厂				$category = $this->input->post('category',true);			$list['category'] = $category;			$list['hairtype'] = $this->input->post('hairtype',true);			$list['grade'] = $this->input->post('grade',true);			$size = $this->input->post('size',true);			$xzsku = $this->input->post('xzsku',true);			$list['size'] = rtrim($size,',');			$list['hairnumber'] = $this->input->post('hairnumber',true);			$list['extension'] = $this->input->post('extension',true);			if($category == 1297)			{				$list['sywignumber'] = $this->input->post('sywignumber',true);			}			if($category == 1702)			{				$list['syhairnumber'] = $this->input->post('syhairnumber',true);				$list['syother'] = $this->input->post('syother',true);			}			if($category == 133)			{				$list['fittype'] = $this->input->post('fittype',true);				$list['acother'] = $this->input->post('acother',true);			}			$list['color'] = $this->input->post('color',true);			$list['lowe'] = $this->input->post('lowe',true);			if($category == 127)			{				$list['type'] = $this->input->post('type',true);				$list['headroad'] = $this->input->post('headroad',true);				$list['density'] = $this->input->post('density',true);				if($list['type'] == 195 || $list['type'] == 197 || $list['type'] == 199)				{					$list['lacesize'] = $this->input->post('lacesize',true);				}				$list['lacecolor'] = $this->input->post('lacecolor',true);				$list['lacetypes'] = $this->input->post('lacetypes',true);			}			if($category == 128)			{				$list['lacetype'] = $this->input->post('lacetype',true);				$list['haircap'] = $this->input->post('haircap',true);				$list['density'] = $this->input->post('density',true);				$list['lacecolor'] = $this->input->post('lacecolor',true);				$list['lacetypes'] = $this->input->post('lacetypes',true);				$list['wigother'] = $this->input->post('wigother',true);				$list['wigother2'] = $this->input->post('wigother2',true);			}			if($category == 129)			{				$list['wide'] = $this->input->post('wide',true);			}						if($category == 131)				{					$list['gifttype'] = $this->input->post('gifttype',true);					$list['giftother'] = $this->input->post('giftother',true);				}						if($category == 134)			{				$list['pieceweight'] = $this->input->post('pieceweight',true);			}			if($category == 1297)			{				$list['synthetictype'] = $this->input->post('synthetictype',true);				$list['sywigother'] = $this->input->post('sywigother',true);			}			if($category == 130 || $category == 133 || $category == 1702)			{				$list['items'] = $this->input->post('items',true);			}			if($category == 1702)			{				$list['syhairther'] = $this->input->post('syhairther',true);			}				foreach($list as $k=>$v)				{					if($v != 0)					{						$num .=$v;						$features .=$v.'-';						$post[$k] = $v;						$typeclass = $this->typeclass->read($v);						if(isset($pm[$typeclass['classid']]))						{						    $pm[$typeclass['classid']] = $typeclass['zh'];						}						$scsku[$typeclass['classid']] = $typeclass['bqsku'];						if($k != 'size')					    {			                $title .= $typeclass['title']." ";					    }				    }                }			$typeclass = $this->typeclass->read($list['size']);			$title .= $typeclass['title'];				$time = time();				$post['printtime'] = $time;				$post['title'] = rtrim($title,' ');				$post['number'] = $num;				$post['features'] = '-'.$features;				$featurespp = str_replace(array('-163-','-164-','-165-','-166-'),'-',$features);				$featurespp = explode('-',trim($featurespp,'-'));				if(isset($featurespp[5]))				{				    $post['featurespp'] = $featurespp[0].'-'.$featurespp[3].'-'.$featurespp[4].'-'.$featurespp[5];				}				else				{					$post['featurespp'] = $featurespp[0].'-'.$featurespp[3].'-'.$featurespp[4];				}				$post['time'] = $time;//操作时间				$scsku = implode("-",$scsku);				$zh = implode(" ",$pm);				$zh = str_replace('自然色 ','',trim($zh,' '));				$zh = str_replace(array('        ','       ','      ','     ','    ','   ','  '),' ',$zh);				$post['shipremarks'] = $zh;				$scsku = str_replace('- ','-',trim($scsku,'-'));				$scsku = str_replace(array('--------','-------','------','-----','----','---','--'),'-',$scsku);			$bqsku = (isset($b['title']))?$b['title'].'-'.$scsku:$scsku;					$post['sku'] = $bqsku;					$post['rk'] = "|1|";//默认配货 打印后直接入库					$post['rktime'] = "|".$time."|";					$rows = array();					$this->db->trans_begin();					for($i=0;$i<$xbqnum;$i++)					{					    $label = substr($time,1)*100;					    $post['label'] = $label+$i;						 $rows[] = array('num'=>$post['label'],'number'=>'','shipremarks'=>$zh,'ex'=>'','t'=>$t,'time'=>'布标打印时间:'.date('Y-m-d H:i:s',$time),'s'=>'('.($i+1).'/'.$xbqnum.')');						 $this->systemtransfer->insert($post);					}						if ($this->db->trans_status() === TRUE)       				    {							$this->db->trans_commit();							echo json_encode(array('rows'=>($rows),'success'=>true));exit;						}						else						{							$this->db->trans_rollback();							echo json_encode(array('msg'=>'错误,请重试!','success'=>false));exit;						}			}		$purchase = $this->purchase->find_all("yyid != ''");		$this->data['purchase'] = $purchase;		$this->_Template('transfer_print',$this->data);	}		public function _number()	{		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);			$pid = "";$tid="";$sid="";$wid="";			$purchase = explode('|',trim($user['purchase'],'|'));			$transfer = explode('|',trim($user['transfer'],'|'));			foreach ($purchase as $value) 			{				$pid .= " id = ".$value." or";			}			foreach ($transfer as $value) 			{				$tid .= " id = ".$value." or";			}		}		else		{			header('Location: /');exit;		}		$post = $this->input->post(NULL, TRUE);		if(isset($post['number']))  		{			$number = $this->input->post('number',true);			$type = $this->input->post('type',true);			$xbqnum = $this->input->post('xbqnum',true);//打印数量			$purchase = $this->input->post('purchase',true);			$f = 'fullorder';			$y  = $this->fullorder->get_number($number);			if(!$y)			{				$f = 'fullordersmt';				$y  = $this->fullordersmt->get_number($number);				if(!$y)			    {					$f = 'fullordertt';					$y  = $this->fullordertt->get_number($number);					if(!$y)			    	{						echo json_encode(array('msg'=>'没有找到此订单,请检查是否扫描错误','success'=>false));exit;					}				}			}			if($y['librarytime'] > 0)			{				echo json_encode(array('msg'=>'错误,此订单已出库!','success'=>false));exit;			}			$cp = array();$i = 0;$x=0;$byz = array();$znum = 0;$typeclass = array();			$classid = $this->classid->sku();			$tc = $this->typeclass->find_all();			foreach($tc as $v)			{				$typeclass[$v['id']] = $v;			}			$bm = '03';			$fpdata = explode(';',trim($y['fpdata'],';'));			$whlabelsc = explode('|',trim($y['whlabel'],'|'));			foreach($fpdata as $key=>$val)			{				$pm = $classid;		    	$jm = $classid;				$sku = $classid;				$bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');				$features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$val);				$jvnr = explode('|',trim($features,'|'));				if(stripos($jvnr[0],',') !== false)				{					$ft = explode(',',$jvnr[0]);			    	$features = explode('-',trim($ft[1],'-'));					array_splice($features,2,0,$ft[0]);				}				else				{					$features = explode('-',trim($jvnr[0],'-'));				}				$title = $jvnr[1];				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)					{						$sku[$typeclass[$v]['classid']] = $typeclass[$v]['bqsku'];						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);				$sku = array_filter($sku);//去除空值				$sku = implode("-",$sku);				$pm = array_filter($pm);//去除空值				$zh = implode(" ",$pm);				$zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));				$features = implode("-",$features);				$cp[] = array('ordernumber'=>$number,'title'=>$title,'sku'=>$sku,'jm'=>$jm,'zh'=>$zh,'n'=>$jvnr[2],'b'=>$y['shipremarks'],'data'=>json_encode(array('ordernumber'=>$number,'features'=>$features,'number'=>$number,'title'=>$title,'jm'=>$jm,'sku'=>$sku,'pm'=>$zh,'bm'=>$bm.implode("",$bmpx))));			}			echo json_encode(array('rows'=>$cp,'success'=>true));exit;		}		$purchase = $this->purchase->find_all("yyid != ''");		$this->data['purchase'] = $purchase;		$transfer = $this->transfer->find_all('1=1 and '.rtrim($tid,'or'));		$this->data['transfer'] = $transfer;		$this->_Template('transfer_number',$this->data);	}		public function _numberprint()	{		$time = time();		$post = $this->input->post(NULL);		$classid = $this->classid->sku();		$pm = $classid;		$scsku = $classid;			if(isset($post['data']))			{				$data = json_decode($post['data'],true);				$f = 'fullorder';				$y = $this->fullorder->get_number($data['ordernumber']);				if(!$y)				{					$f = 'fullordersmt';					$y  = $this->fullordersmt->get_number($data['ordernumber']);					if(!$y)			    	{						$f = 'fullordertt';						$y  = $this->fullordertt->get_number($data['ordernumber']);						if(!$y)			    		{							echo json_encode(array('msg'=>$data['ordernumber'].'没有找到此订单,请检查是否扫描错误'.$data['ordernumber'],'success'=>false));exit;						}					}				}				if($y['printtime'] == 0)			    {						echo json_encode(array('msg'=>'此单已重置,请询问梦体','success'=>false));exit;				}				$order = 0;$time = time();				$xbqnum = $this->input->post('n',true);//打印数量				if($xbqnum > 99)				{					echo json_encode(array('msg'=>'打印数量不可超过99!','success'=>false));exit;				}				if($xbqnum < 1)				{					echo json_encode(array('msg'=>'打印数量错误!','success'=>false));exit;				}				$transfer = $this->input->post('transfer',true);				$post['type'] = $this->input->post('type',true);				$post['shipremarks'] = $this->input->post('b',true);				$post['ph'] = $this->input->post('ph',true);				$is_jiaji = $this->input->post('is_jiaji',true);				if($is_jiaji == 2){					$post['is_jiaji'] = 2;				}else{					$post['is_jiaji'] = 0;				}				$zps = $this->input->post('zps',true);				$post['purchase'] = $this->input->post('purchase',true);//供应商		        $post['time'] = $time;//操作时间				$post['jm'] = $data['jm'];				$post['bm'] = $data['bm'];				$post['pm'] = $data['pm'];				$post['features'] = $data['features'];				$post['number'] = $data['number'];				$post['title'] = $data['title'];				$post['sku'] = $data['sku'];				$post['printtime'] = $y['printtime'];				$post['rk'] = "|12|";//默认订单中心 打印后直接入库				$post['ck'] = "|12|";				$post['rktime'] = "|".$time."|";				$post['cktime'] = $post['rktime'];				$post['ctime12'] = $time;				$express = $this->express->read($y['express']);				$rows = array();$t='';				$this->db->trans_begin();				$post['xbqnum'] = $xbqnum;				$kh = $this->shop->read($y['shop']);				$yy = $this->apiyy->_peihuo($post,$kh['yyid'],$y['number'],$post['xbqnum']);			    if($yy['c'] == 0)			    {					$post['scapi'] = '99';					$post['scid'] = $yy['scid'];					if(!$post['purchase'])					{						$post['purchase'] = '';					}					$mqsl = $this->systemtransfer->find_count("number = '".$data['number']."'");					//able_ext 实在打印小单布标时判断是否可以打印备货单 				    $able_ext = 0;				    $tmp_fetaures = explode('-',$data['features']);                    //只有头套和马尾才会要配货单    				if(in_array(128, $tmp_fetaures)){    					$able_ext = 1;    				}    				if(in_array(133, $tmp_fetaures)){    					if(in_array(673, $tmp_fetaures)){    						$able_ext = 1;    					}    				}					for($i=0;$i<$xbqnum;$i++)					{						if($post['zps'])						{							if($post['zps'] > 0)							{								$t = '总量:'.($mqsl+$i+1).'/'.$zps;							}						}						$label = substr($time,1)*100;						$post['label'] = $label+$i;				   		$rows[] = array('num'=>$post['label'],'number'=>$post['number'],'shipremarks'=>$post['shipremarks'],'ph'=>$post['ph'],'ex'=>$express['servicename'],'time'=>''.date('Y-m-d',$post['printtime']),'gtime'=>date('YmdH',time()),'s'=>'('.($i+1).'/'.$xbqnum.')','t'=>$t,'able_ext'=>$able_ext,'is_jiaji'=>$is_jiaji);						$this->systemtransfer->insert($post);					}			    }			    else			    {					$this->db->trans_rollback();				    echo json_encode(array('msg'=>$yy['error'],'a'=>1,'success'=>false));exit;			    }                if($this->db->trans_status() === TRUE)       			{					$this->db->trans_commit();					echo json_encode(array('rows'=>($rows),'success'=>true));exit;				}				else				{					$this->db->trans_rollback();					echo json_encode(array('msg'=>'错误,请重试!','success'=>false));exit;				}			}	}		public function _operate()	{		$post = $this->input->post(NULL, TRUE);	    if(isset($post['page']))  		{			$api = $this->input->post('api',true);		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',true);			$number = $this->input->post('number',true);			$color = $this->input->post('color',true);			$purchase = $this->input->post('purchase',true);			$transfer = $this->input->post('transfer',true);			$lx = $this->input->post('lx',true);			$type = $this->input->post('type',true);			$jiaji = $this->input->post('jiaji',true);			$xztime = $this->input->post('xztime',true);			$timetk = $this->input->post('timetk',true);			$timetj = $this->input->post('timetj',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$where = '1=1';			if($number)            {                $where  .= " and number = '$number'";            }			if($purchase)            {                $where  .= " and purchase = '$purchase'";            }			if($color)            {                $where  .= " and fpdata like '%-".$color."-%'";            }			if($lx)            {				if($lx == 1)				{                    $where  .= " and ordernumber = ''";				}				else				{					$where  .= " and ordernumber != ''";				}            }            if($jiaji){                if($jiaji == 1){                    $where  .= " and is_jiaji = 0";                }                if($jiaji == 2){                    $where  .= " and is_jiaji = 2";                }                            }            //数据排序            $order_str = "id desc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }						if($xztime == 'printtime')			{				$where  .= " and printtime > '$timetk' and printtime < '$timetj'";				if($type)            	{					$type = ($type==1)?'rk':'ck';					if($transfer)            		{						$where  .= " and $type like '%|".$transfer."|%'";            		}            	}				else				{					if($transfer)            		{						$where  .= " and rk like '%|".$transfer."|%'";            		}				}			}			else			{				$cr  = "time > '$timetk' and time < '$timetj'";				if($transfer)            	{                	$cr  .= " and lx = '".$transfer."'";            	}				if($type)            	{                	$cr  .= " and type = '".$type."'";            	}				$fid = '';				$info_list_cr = $this->systemtransfer_cr->find_all($cr);				foreach ($info_list_cr as $v)		    	{					$fid .= "id = '".$v['fid']."' or ";				}				if($fid)				{			    	$where  .= ' and ('.trim($fid,'or ').')';				}				else				{					$where  .= ' and id = 0';				}			}            //取得信息列表            $info_list = $this->systemtransfer->find_all($where,'id,number,is_jiaji,pm,shipremarks,printtime,time',$order_str,$start,$perpage);			$transfer = $this->transfer->find_all();			$t = array();			foreach ($transfer as $v)		    {				$t[$v['id']] = $v['title'];				$ot[$v['id']] = ($v['orvertime']>0)?$v['orvertime']*24*3600:0;			}			 //格式化数据            foreach ($info_list as $key=>$value)		    {		        if($value['is_jiaji'] == 2){		            $info_list[$key]['is_jiaji'] = "<a href='javascript:void(0)' style='color:red'>加急</a>";		        }else{		            $info_list[$key]['is_jiaji'] = "常规";		        }				$dd = $this->systemtransfer->read($value['id']);				$info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);				$rk = explode('|',trim($dd['rk'],'|'));				$rktime = explode('|',trim($dd['rktime'],'|'));				$ck = explode('|',trim($dd['ck'],'|'));				$cktime = explode('|',trim($dd['cktime'],'|'));				$info_list[$key]['time'] = '';				$data = $this->systemtransfer_cr->find_all("fid = '".$value['id']."'");				/**				for($i=0;$i<count($rk);$i++)		        {					if(count($rk)-1 == $i && $ot[$rk[$i]] > 0 && $rktime[$i] + $ot[$rk[$i]] < time())					{						$d = ' <em style="color: #fc5454;">'.$t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').' 超</em><br> ';					}					else					{						$d = $t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').'<br>';					}					$info_list[$key]['time'] .= $d;					if(isset($ck[$i]) && $ck[$i] != '')					{						$info_list[$key]['time'] .= $t[$ck[$i]].'出库 :'.date('Y-m-d H:i',$cktime[$i]).'<br>';					}				}				**/				$info_list[$key]['time'] = "订单出库 :".date('Y-m-d H:i',$value['printtime']).'<br>';				foreach ($data as $k=>$v)		        {				// 	$type = ($v['type']==1)?'入库':'出库';				// 	$info_list[$key]['time'] .= $t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']).'<br>';									    $type = ($v['type']==1)?'入库':'出库';								    if($v['orver_flag'] == 1){						if($v['is_over'] == 0){							$info_list[$key]['time'] .= "<a href='javascript:void(0);' style='color:#90f'>".$t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']) ." <l style='font-weight:900;'>即将超时 </l></a>".'<br>';							// $info_list[$key]['time'] .= '<i style="padding:10px;color:#90f;font-weight:bold;"> 即将超时</i>'.'<br>';						}else{							$info_list[$key]['time'] .= "<a href='javascript:void(0);' style='color:#000'>".$t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']) ."</a>".'<br>';						}					}elseif($v['orver_flag'] == 2){						$info_list[$key]['time'] .= "<a href='javascript:void(0);' style='color:#f33'>".$t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']) ." <l font-weight:900'>超时! </l></a>".'<br>';					}elseif($v['orver_flag'] == 3){						$info_list[$key]['time'] .= "<a href='javascript:void(0);' style='color:#06f'>".$t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']) ." <l font-weight:900'>【该单已取消】 </l></a>".'<br>';					}else{						$info_list[$key]['time'] .= "<a  href='javascript:void(0);' style='color:#000'>".$t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']) ."</a>".'<br>';					}				}				$info_list[$key]['time'] = trim($info_list[$key]['time'],'<br>');            }		    $total = $this->systemtransfer->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;		}		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);			$usp = $user;		    $pid = "";$tid="";$sid="";$wid="";		    $purchase = explode('|',trim($user['purchase'],'|'));			$transfer = explode('|',trim($user['transfer'],'|'));			$warehouse = explode('|',trim($user['warehouse'],'|'));			foreach ($purchase as $value) 		    {				$pid .= " id = ".$value." or";			}			foreach ($transfer as $value) 		    {				$tid .= " id = ".$value." or";			}			foreach ($warehouse as $value) 		    {				$wid .= " id = ".$value." or";			}		}		else		{			header('Location: /');exit;		}		$kx = '';$zjtab = '';		$warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");		$this->data['warehouse'] = $warehouse;		$purchase = $this->purchase->find_all("yyid != ''");		$this->data['purchase'] = $purchase;		$transfer = $this->transfer->find_all('1=1 and '.rtrim($tid,'or'));		$this->data['transfer'] = $transfer;		$this->data['vip'] = $user['vip'];		$transfer_ids = array_column($transfer,'id');		$transfer_str = implode(",",$transfer_ids);		$this->data['cz_1_num'] = $this->systemtransfer_cr->find_count("orver_flag = 1 and is_over = 0 and time > ".(time()-3600*24*7)  ." and lx in (".$transfer_str.")");		$this->data['cz_2_num'] = $this->systemtransfer_cr->find_count("orver_flag = 2 and is_over = 0 and time > ".(time()-3600*24*7)  ." and lx in (".$transfer_str.")");		$jiaji_num = 0;	    	    $jiaji_num = $this->systemtransfer->find_count(" is_jiaji = 2 and time > ".(time()-3600*24*7)." and rk not like '%|11|%'" );	    		$this->data['jiaji_num'] = $jiaji_num;		$this->_Template('transfer_operate',$this->data);	}		public function _out()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['label']))		{			$time = time();			$label = $this->input->post('label',true);			$cz = $this->input->post('cz',true);			$transfer = $this->input->post('transfer',true);			if(!$label)			{				echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;			}			if(!$transfer)			{				echo json_encode(array('msg'=>'请选择需对应的部门!','success'=>false));exit;			}			$lb = $this->systemtransfer->get_label($label);			if(!$lb)			{				echo json_encode(array('msg'=>'错误!未找到此条码','success'=>false));exit;			}			if($lb['number']!='')			{				$nu = $this->fullorder->get_number($lb['number']);				if(!$nu)				{					$nu = $this->fullordersmt->get_number($lb['number']);				    if(!$nu)				    {						$nu = $this->fullordertt->get_number($lb['number']);					}				}				//取消的订单还是要继续生产的 所以还允许继续扫入扫出 只是后续的出入库中不在限定时间				// if($nu['state'] == '214' || $nu['state'] == '217')				// {				// 	echo json_encode(array('msg'=>'错误,此单已取消!请联系店员核实','success'=>false));exit;				// }			}						$tdata = $this->transfer->find_all();			$t = array();			foreach ($tdata as $v)		    {				$t[$v['id']] = $v['title'];			}			/**			if($cz == 1 && stripos($lb['rk'],'|'.$transfer.'|') !== false)			{				echo json_encode(array('msg'=>'此条码已有入库操作!','success'=>false));exit;			}			if($cz == 2 && stripos($lb['ck'],'|'.$transfer.'|') !== false)			{				echo json_encode(array('msg'=>'此条码已有出库操作!','success'=>false));exit;			}			**/// 			if(stripos($lb['ck'],'|1|') === false && $transfer != 1 && stripos($nu['fpdata'],'-128-') !== false)// 			{// 				echo json_encode(array('msg'=>'必须有配货出库才可后续操作!','success'=>false));exit;// 			}           						//重新定义配货的原则问题			//先检测订单是否含有 128 头套 或者配件 如果有 133 进行下一步检测 			$sku_arr = explode("-",$lb['features']);			if(in_array(128,$sku_arr)||in_array(133,$sku_arr)){				// 145  Full Lace Wig				// 1170 HDFullLaceWig				// 1249 FullLaceBobwithBang				// 1484 FullLaceBob				//如果是这4中全蕾丝那么配货就不处理				if(in_array(145,$sku_arr) || in_array(1170,$sku_arr) || in_array(1249,$sku_arr) || in_array(1484,$sku_arr)){				}else{					if(stripos($lb['ck'],'|1|') === false && $transfer != 1 )					{						echo json_encode(array('msg'=>'头套和配件除了全蕾丝外必须走配货!','success'=>false));exit;					}				}			}			if($cz == 2 && stripos($lb['rk'],'|'.$transfer.'|') === false)			{				echo json_encode(array('msg'=>'此条码还未入库!','success'=>false));exit;			}			$lbrk = array_reverse(explode('|',trim($lb['rk'],'|')));			$lbck = array_reverse(explode('|',trim($lb['ck'],'|')));			if($transfer != 3 && $transfer != 11 && $transfer != 2)			{				if($cz == 1)				{			        if($lb['rk'] != $lb['ck'])//判断是否没走完流程就拿到下一步奏			        {				        echo json_encode(array('msg'=>$t[$lbrk[0]].'还未出库,无法入库!','success'=>false));exit;			        }				}				if($cz == 2 && $lbrk[0] != $transfer)//判断是否没走完流程就拿到下一步奏			    {				    echo json_encode(array('msg'=>$t[$transfer].'还未入库,无法出库!','success'=>false));exit;			    }			}			if($cz == 1)			{				$lb['rk'] .= $transfer.'|';				$lb['rktime'] .= $time.'|';				if($lbrk[0] == $transfer)				{					echo json_encode(array('msg'=>'已有入库记录,不可连续重复录入!','success'=>false));exit;				}			}			else if($cz == 2)			{				$lb['ck'] .= $transfer.'|';				$lb['cktime'] .= $time.'|';				if($lbck[0] == $transfer)				{					echo json_encode(array('msg'=>'已有出库记录,不可连续重复录入!','success'=>false));exit;				}			}			$cztime = 'ctime'.$transfer;				if(($transfer == 3 && $lb['dbapi'] < 99 && $cz == 2) || ($transfer == 13 && $lb['dbapi'] < 99 && $cz == 1))//出入库用这个			//if(($transfer == 8 || $transfer == 13) && $lb['dbapi'] < 99 && $cz == 1)//单入库			{				if($lb['type'] == 0)				{				    $s = $this->shop->read($nu['shop']);			        $lb['kh'] = $s['yyid'];				    $lb['ts'] = 1;			        $rk = $this->apiyy->_newrk($lb);				    if($rk['c'] == 0)				    {						$this->db->trans_begin();						$this->systemtransfer->save(array('rk'=>$lb['rk'],'rktime'=>$lb['rktime'],'ck'=>$lb['ck'],'cktime'=>$lb['cktime'],'time'=>$time,'gtime'=>date('YmdH',$time),'dbapi'=>99,'scid'=>$rk['scid'].time(),$cztime=>$time),$lb['id']);				 	    $this->systemtransfer_cr->insert(array('fid'=>$lb['id'],'lx'=>$transfer,'type'=>$cz,'time'=>$time));				 	    //处理定时任务每三分钟 执行一次的bug  在出库的时候直接同步相关信息            			if($cz == 2){            				$this->_doCheckIsOverTime($lb['id'],$transfer);            			}						if ($this->db->trans_status() === TRUE)        				{							$this->db->trans_commit();							if($nu['state'] == '216')				 	  	    {				     	  	    echo json_encode(array('msg'=>'数据已录入成功!提示:此订单已出库,可选择终止生产。','success'=>false));exit;				 	  	    }				 	  	    elseif(($nu['state'] == '217') || ($nu['state'] == '214')){            					//标记订单已经取消            					$this->_doCheckCancelFlag($lb['id']);            					echo json_encode(array('msg'=>'数据已录入成功!提示:【该单已取消】,可选择终止生产。','success'=>false));exit;            				}				 	  	    else				 	  	    {								if($lb['is_jiaji'] == 2){									echo json_encode(array('music'=>'1','is_jiaji'=>2,'success'=>true));exit;								}else{									echo json_encode(array('music'=>'1','success'=>true));exit;								}				     	  	    				 	  	    }						}						else						{							$this->db->trans_rollback();							echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;						}				    }				    else				    {						if(stripos($rk['error'],'DocNo') !== false)						{							$rk['error'] = '未找到对应的生产订单 '.$lb['scid'];						}						$this->systemtransfer->save(array('dbapi'=>$rk['dbapi'],'scid'=>$rk['scid']),$lb['id']);					    echo json_encode(array('msg'=>'订单号:'.$lb['number'].' 用友报错:'.$rk['error'],'success'=>false));exit;				    }				}				else				{					$scid = explode('~',$lb['scid']);					$rkdata = array('od'=>$scid[1],'ts'=>1,'title'=>$lb['title']);					$rk = $this->apiyy->get_bzsh($rkdata);					if(isset($rk['Data'][0]))		        	{						if($rk['Data'][0]['IsSucess'] == 1)				        {							$this->db->trans_begin();							$this->systemtransfer->save(array('rk'=>$lb['rk'],'rktime'=>$lb['rktime'],'ck'=>$lb['ck'],'cktime'=>$lb['cktime'],'time'=>$time,'gtime'=>date('YmdH',$time),'dbapi'=>99,'scid'=>$lb['scid'].'~'.$rk['Data'][0]['Code'],$cztime=>$time),$lb['id']);				 	    	$this->systemtransfer_cr->insert(array('fid'=>$lb['id'],'lx'=>$transfer,'type'=>$cz,'time'=>$time));				 	    	//处理定时任务每三分钟 执行一次的bug  在出库的时候直接同步相关信息                			if($cz == 2){                				$this->_doCheckIsOverTime($lb['id'],$transfer);                			}							if ($this->db->trans_status() === TRUE)        					{								$this->db->trans_commit();								if($nu['state'] == '216')				 	  	    	{				     	  	    	echo json_encode(array('msg'=>'数据已录入成功!提示:此订单已出库,可选择终止生产。','success'=>false));exit;				 	  	    	}				 	  	    	elseif(($nu['state'] == '217') || ($nu['state'] == '214')){                					//标记订单已经取消                					$this->_doCheckCancelFlag($lb['id']);                					echo json_encode(array('msg'=>'数据已录入成功!提示:【该单已取消】,可选择终止生产。','success'=>false));exit;                				}				 	  	    	else				 	  	    	{									if($lb['is_jiaji'] == 2){										echo json_encode(array('music'=>'1','is_jiaji'=>2,'success'=>true));exit;									}else{										echo json_encode(array('music'=>'1','success'=>true));exit;									}				 	  	   		}							}							else							{								$this->db->trans_rollback();								echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;							}			 	  	    }						else						{							echo json_encode(array('msg'=>$rk['Data'][0]['ErrorMsg'],'success'=>false));exit;						}			 	  	    					}					else				    {					    echo json_encode(array('msg'=>$rk,'success'=>false));exit;				    }										 }			}			//if($transfer == 11 && stripos($lb['rk'],'|8|') === false && stripos($lb['ck'],'|3|') === false &&  stripos($lb['rk'],'|13|') === false)//只入库			if($transfer == 11 && stripos($lb['ck'],'|3|') === false &&  stripos($lb['rk'],'|13|') === false)//改出入库			{				echo json_encode(array('msg'=>'工厂未出库,请退回工厂!','success'=>false));exit;			}			$this->systemtransfer->save(array('rk'=>$lb['rk'],'rktime'=>$lb['rktime'],'ck'=>$lb['ck'],'cktime'=>$lb['cktime'],'time'=>$time,'gtime'=>date('YmdH',$time),$cztime=>$time),$lb['id']);			$this->systemtransfer_cr->insert(array('fid'=>$lb['id'],'lx'=>$transfer,'type'=>$cz,'time'=>$time));			//处理定时任务每三分钟 执行一次的bug  在出库的时候直接同步相关信息			if($cz == 2){				$this->_doCheckIsOverTime($lb['id'],$transfer);			}			if ($this->db->trans_status() === TRUE)        	{				$this->db->trans_commit();											    if($nu['state'] == '216')				{					echo json_encode(array('msg'=>'数据已录入成功!提示:此订单已出库,可选择终止生产。','success'=>false));exit;				}				elseif(($nu['state'] == '217') || ($nu['state'] == '214')){					//标记订单已经取消					$this->_doCheckCancelFlag($lb['id']);					echo json_encode(array('msg'=>'数据已录入成功!提示:【该单已取消】,可选择终止生产。','success'=>false));exit;				}				else				{					if($lb['is_jiaji'] == 2){						echo json_encode(array('music'=>'1','is_jiaji'=>2,'success'=>true));exit;					}else{						echo json_encode(array('music'=>'1','success'=>true));exit;					}				}			}			else			{				$this->db->trans_rollback();				echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;			}		}	}	//检测取消标记是否添加 同时也检查下 该流转单是否被标记为取消单	private function _doCheckCancelFlag($fid){				$info = $this->systemtransfer->read($fid);		if($info['status'] != 11){			$this->systemtransfer->save(['status'=>11],$fid);		}		$list = $this->systemtransfer_cr->find_all("fid = ".$fid,'*','id desc');		if(empty($list)){			return;		}		$is_cancel = false;		foreach($list as $val){			if($val['orver_flag'] == 3){				$is_cancel = true;			}		}		if($is_cancel){			return ;		}		$this->systemtransfer_cr->save(['orver_flag'=>3],$list[0]['id']);			}		//检测是否超时  车间流转环节 	private function  _doCheckIsOverTime($fid,$transfer){		$list = $this->systemtransfer_cr->find_all("fid = ".$fid." and lx = ".$transfer." and is_over = 0","*",'id desc',0,2);		if(count($list) < 2){			return ;		}		if($list[0]['type'] != 2){			return;		}		if($list[1]['type'] != 1){			return;		}		if($list[1]['orver_flag'] == 2){			$this->systemtransfer_cr->save(array('is_over'=>1,'orver_flag'=>2),$list[0]['id']);		}else{			$this->systemtransfer_cr->save(array('is_over'=>1),$list[0]['id']);		}		$this->systemtransfer_cr->save(array('is_over'=>1),$list[1]['id']);	}			public function _bdbb()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['s']))  		{            $id_arr = $this->input->post('s');            $id_arr =  explode(',',trim($id_arr,','));            if(!$id_arr)            {                echo json_encode(array('msg'=>$v.' - 未查询到需要补打信息!','success'=>false));exit;            }            //循环删除记录            foreach ($id_arr as $v) 		    {                $t = $this->systemtransfer->read($v);				if(!isset($t['number']))				{					echo json_encode(array('msg'=>$v.' - 补打信息已被删除!','success'=>false));exit;				}				$y = $this->fullorder->get_number($t['number']);				if(!$y)				{					$y  = $this->fullordersmt->get_number($t['number']);					if(!$y)			    	{						$y  = $this->fullordertt->get_number($t['number']);						if(!$y)			    		{							echo json_encode(array('msg'=>$t['number'].'没有找到此订单','success'=>false));exit;						}					}				}				$express = $this->express->read($y['express']);				$rows[] = array('num'=>$t['label'],'number'=>$t['number'],'shipremarks'=>$t['shipremarks'],'ex'=>$express['servicename'],'time'=>''.date('Y-m-d',$t['printtime']),'gtime'=>date('YmdH',time()),'s'=>'1/1','t'=>"补打");            }            echo json_encode(array('rows'=>($rows),'success'=>true));exit;		}    }			public function _excel()	{		if(isset($_GET['fexcel']))  		{			$tc = array();$zh = array();			$typeclass = $this->typeclass->find_all();			foreach ($typeclass as $v) 			{				$tc[$v['id']] = $v;			}			$number = $this->input->get('number',true);			$color = $this->input->get('color',true);			$gs = $this->input->get('gs',true);			$transfer = $this->input->get('transfer',true);			$type = $this->input->get('type',true);			$timetk = $this->input->get('timetk',true);			$timetj = $this->input->get('timetj',true);			$purchase = $this->input->get('purchase',true);			$lx = $this->input->get('lx',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$where = "1=1";			$cr  = "time > '$timetk' and time < '$timetj'";			if($number)            {                $where  .= " and number = '$number'";            }			if($transfer)            {                $cr  .= " and lx = '".$transfer."'";            }			if($type)            {                $cr  .= " and type = '".$type."'";            }			if($purchase)            {                $where  .= " and purchase = '$purchase'";            }			if($color)            {                $where  .= " and fpdata like '%-".$color."-%'";            }			if($lx)            {				if($lx == 1)				{                    $where  .= " and ordernumber = ''";				}				else				{					$where  .= " and ordernumber != ''";				}            }			$fid = '';			$info_list_cr = $this->systemtransfer_cr->find_all($cr);			foreach ($info_list_cr as $v)		    {				$fid .= "id = '".$v['fid']."' or ";			}			if($fid)			{			    $where  .= ' and ('.trim($fid,'or ').')';			}			else			{				$where  .= ' and id = 0';			}			$data = array();			$datafy = array();			$j = 0;			$info_list = $this->systemtransfer->find_all($where,'id,number,pm,jm,shipremarks,printtime');			$lzbm = $this->transfer->find_all();			foreach ($info_list as $key=>$value)		    {				$dj = '';$ys = '';$cc = '';$hx = '';$md = '';				$d = $this->systemtransfer->read($value['id']);				$info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);				$info_list[$key]['shipremarks'] = str_replace(array('<','>'),array('<','>'),$d['shipremarks']);				$d['features'] = str_replace(array('163-','164-','165-','166-','-0-'),array('','','','','-'),$d['features']);				$cp = explode('-',trim($d['features'],'-'));				$rk = explode('|',trim($d['rk'],'|'));				$rktime = explode('|',trim($d['rktime'],'|'));				foreach ($cp as $v)		        {					if(isset($tc[$v]))					{						if($tc[$v]['classid'] == 13)						{							$dj = $tc[$v]['title'];						}						else if($tc[$v]['classid'] == 8)						{							$ys = $tc[$v]['title'];						}						else if($tc[$v]['classid'] == 14)						{							$cc = $tc[$v]['title'];						}						else if($tc[$v]['classid'] == 15)						{							$hx = $tc[$v]['title'];						}						else if($tc[$v]['classid'] == 10)						{							$md = $tc[$v]['title'];						}					}				}				$rt = array();				foreach ($rk as $k=>$v)		        {					$rt[$v+5] = date('Y-m-d H:i:s',$rktime[$k]);				}				$fpdata = array(array('0'=>$d['title'],'1'=>$cc,'2'=>$dj,'3'=>$ys,'4'=>$hx,'5'=>$md));				foreach ($lzbm as $v)		        {					if(isset($rt[count($fpdata[0])]))					{					    //$fpdata[0][count($fpdata[0])] = $rt[count($fpdata[0])];					    $num = $this->systemtransfer_cr->find_count("fid = ".$value['id']." and lx = ".$v['id']." and orver_flag = 2");						if($num > 0){							$fpdata[0][count($fpdata[0])] = "<span style='color:red;font-weight:bold;'>".$rt[count($fpdata[0])]."<span>";						}else{							$fpdata[0][count($fpdata[0])] = $rt[count($fpdata[0])];						}					}					else					{						$fpdata[0][count($fpdata[0])] = '';					}				}				$info_list[$key]['fpdata'] = $fpdata;//名称,尺寸,等级,颜色,花型,密度				unset($info_list[$key]['id']);            }			//echo "<pre>";print_r($info_list);exit;			$lzxq = '';			foreach ($lzbm as $v)		    {				$lzxq .= '<td>'.$v['title'].'</td>';			}			$title = date('Y-m-d',$timetk).'-'.date('Y-m-d',$timetj).' 统计表';             $titlename = "<table border=1>           <tr>            <td>订单编号</td>            <td>品名</td>			<td>简码</td>			<td>备注</td>            <td>打印时间</td>			<td>			<table border=1>            <tr><td colspan='6' align='center'>订单产品信息</td><td colspan='".count($lzbm)."' align='center'>货物流转时间</td></tr>            <tr>			<td>产品名称</td>			<td>尺寸</td>			<td>等级</td>			<td>颜色</td>			<td>花型</td>			<td>密度</td>			".$lzxq."            </tr>            </table>			</td>            </tr>            </table>";             $filename = $title.".xls"; 			$tail = "\n";            $this->excel->get_fz($info_list,$titlename,$filename,$tail,1);	    }	}		public function _rk()	{		$post = $this->input->post(NULL, TRUE);	    if(isset($post['page']))  		{			$api = $this->input->post('api',true);		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',true);			$number = $this->input->post('number',true);			$color = $this->input->post('color',true);			$purchase = $this->input->post('purchase',true);			$transfer = $this->input->post('transfer',true);			$lx = $this->input->post('lx',true);			$timetk = $this->input->post('timetk',true);			$timetj = $this->input->post('timetj',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$where = "1=1";			if($transfer)			{				$ctime = 'ctime'.$transfer;			    $where  .= " and $ctime > '$timetk' and $ctime < '$timetj'";			}			else			{				$where  .= " and time > '$timetk' and time < '$timetj'";			}			if($number)            {                $where  .= " and number = '$number'";            }			if($transfer)            {                $where  .= " and rk like '%|".$transfer."|%'";            }			if($purchase)            {                $where  .= " and purchase = '$purchase'";            }			if($color)            {                $where  .= " and fpdata like '%-".$color."-%'";            }			if($lx)            {				if($lx == 1)				{                    $where  .= " and ordernumber = ''";				}				else				{					$where  .= " and ordernumber != ''";				}            }            //数据排序            $order_str = "id desc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }            //取得信息列表            $info_list = $this->systemtransfer->find_all($where,'id,number,pm,shipremarks,printtime,time',$order_str,$start,$perpage);			$transfer = $this->transfer->find_all();			$t = array();			foreach ($transfer as $v)		    {				$t[$v['id']] = $v['title'];				$ot[$v['id']] = ($v['orvertime']>0)?$v['orvertime']*24*3600:0;			}			 //格式化数据            foreach ($info_list as $key=>$value)		    {				$dd = $this->systemtransfer->read($value['id']);				$info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);				$rk = explode('|',trim($dd['rk'],'|'));				$rktime = explode('|',trim($dd['rktime'],'|'));				$ck = explode('|',trim($dd['ck'],'|'));				$cktime = explode('|',trim($dd['cktime'],'|'));				$info_list[$key]['time'] = '';								for($i=0;$i<count($rk);$i++)		        {					if(count($rk)-1 == $i && $ot[$rk[$i]] > 0 && $rktime[$i] + $ot[$rk[$i]] < time())					{						$d = ' <em style="color: #fc5454;">'.$t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').' 超</em><br> ';					}					else					{						$d = $t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').'<br>';					}					$info_list[$key]['time'] .= $d;					if(isset($ck[$i]) && $ck[$i] != '')					{						$info_list[$key]['time'] .= $t[$ck[$i]].'出库 :'.date('Y-m-d H:i',$cktime[$i]).'<br>';					}				}				$info_list[$key]['time'] = trim($info_list[$key]['time'],'<br>');            }		    $total = $this->systemtransfer->find_count($where);		    $pagenum = ceil($total/$perpage);		    $over = $total-($start+$perpage);		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'cs'=>$where);		    echo json_encode($rows);exit;		}		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);			$usp = $user;		    $pid = "";$tid="";$sid="";$wid="";		    $purchase = explode('|',trim($user['purchase'],'|'));			$transfer = explode('|',trim($user['transfer'],'|'));			$warehouse = explode('|',trim($user['warehouse'],'|'));			foreach ($purchase as $value) 		    {				$pid .= " id = ".$value." or";			}			foreach ($transfer as $value) 		    {				$tid .= " id = ".$value." or";			}			foreach ($warehouse as $value) 		    {				$wid .= " id = ".$value." or";			}		}		else		{			header('Location: /');exit;		}		$transfer = $this->transfer->find_all('1=1 and '.rtrim($tid,'or'));		$this->data['transfer'] = $transfer;		$this->_Template('transfer_rk',$this->data);	}		public function _ck()	{		$post = $this->input->post(NULL, TRUE);	    if(isset($post['page']))  		{			$api = $this->input->post('api',true);		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',true);			$number = $this->input->post('number',true);			$color = $this->input->post('color',true);			$purchase = $this->input->post('purchase',true);			$transfer = $this->input->post('transfer',true);			$lx = $this->input->post('lx',true);			$timetk = $this->input->post('timetk',true);			$timetj = $this->input->post('timetj',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$where = "1=1";			if($transfer)			{				$ctime = 'ctime'.$transfer;			    $where  .= " and $ctime > '$timetk' and $ctime < '$timetj'";			}			else			{				$where  .= " and time > '$timetk' and time < '$timetj'";			}			if($number)            {                $where  .= " and number = '$number'";            }			if($transfer)            {                $where  .= " and ck like '%|".$transfer."|%'";            }			if($purchase)            {                $where  .= " and purchase = '$purchase'";            }			if($color)            {                $where  .= " and fpdata like '%-".$color."-%'";            }			if($lx)            {				if($lx == 1)				{                    $where  .= " and ordernumber = ''";				}				else				{					$where  .= " and ordernumber != ''";				}            }            //数据排序            $order_str = "id desc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }            //取得信息列表            $info_list = $this->systemtransfer->find_all($where,'id,number,pm,shipremarks,printtime,time',$order_str,$start,$perpage);			$transfer = $this->transfer->find_all();			$t = array();			foreach ($transfer as $v)		    {				$t[$v['id']] = $v['title'];				$ot[$v['id']] = ($v['orvertime']>0)?$v['orvertime']*24*3600:0;			}			 //格式化数据            foreach ($info_list as $key=>$value)		    {				$dd = $this->systemtransfer->read($value['id']);				$info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);				$rk = explode('|',trim($dd['rk'],'|'));				$rktime = explode('|',trim($dd['rktime'],'|'));				$ck = explode('|',trim($dd['ck'],'|'));				$cktime = explode('|',trim($dd['cktime'],'|'));				$info_list[$key]['time'] = '';								for($i=0;$i<count($rk);$i++)		        {					if(count($rk)-1 == $i && $ot[$rk[$i]] > 0 && $rktime[$i] + $ot[$rk[$i]] < time())					{						$d = ' <em style="color: #fc5454;">'.$t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').' 超</em><br> ';					}					else					{						$d = $t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').'<br>';					}					$info_list[$key]['time'] .= $d;					if(isset($ck[$i]) && $ck[$i] != '')					{						$info_list[$key]['time'] .= $t[$ck[$i]].'出库 :'.date('Y-m-d H:i',$cktime[$i]).'<br>';					}				}				$info_list[$key]['time'] = trim($info_list[$key]['time'],'<br>');            }		    $total = $this->systemtransfer->find_count($where);		    $pagenum = ceil($total/$perpage);		    $over = $total-($start+$perpage);		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'cs'=>$where);		    echo json_encode($rows);exit;		}		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);			$usp = $user;		    $pid = "";$tid="";$sid="";$wid="";		    $purchase = explode('|',trim($user['purchase'],'|'));			$transfer = explode('|',trim($user['transfer'],'|'));			$warehouse = explode('|',trim($user['warehouse'],'|'));			foreach ($purchase as $value) 		    {				$pid .= " id = ".$value." or";			}			foreach ($transfer as $value) 		    {				$tid .= " id = ".$value." or";			}			foreach ($warehouse as $value) 		    {				$wid .= " id = ".$value." or";			}		}		else		{			header('Location: /');exit;		}		$transfer = $this->transfer->find_all('1=1 and '.rtrim($tid,'or'));		$this->data['transfer'] = $transfer;		$this->_Template('transfer_ck',$this->data);	}			public function _jgl()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['printtime']))  		{		    $pt = $this->input->post('printtime',true);			$wt = $this->input->post('wgtime',true);			$printtime = strtotime($pt);			$wgtime = strtotime($wt);			$sy = $this->systemtransfer->find_count("printtime > '$printtime' and printtime < '".($printtime+24*3600)."'");			$wg = $this->systemtransfer->find_count("printtime > '$printtime' and printtime < '".($printtime+24*3600)."' and ctime11 < '$wgtime' and ctime11 != '0'");			if($printtime == $wgtime || $printtime > $wgtime)			{				echo json_encode(array('msg'=>"<p style='height:140px;line-height:140px'>时间选择错误</p>",'success'=>true));exit;			}			echo json_encode(array('msg'=>"<p style='height:140px;line-height:140px'>".(($wgtime-$printtime)/86400)."天 完工数量:".$wg.", 总数量:".$sy.", 完工率:".number_format(($wg/$sy*100),2)."%</p>",'success'=>true));exit;	    }		$this->_Template('transfer_wgl',$this->data);	}		public function _linqi(){		$post = $this->input->post(NULL, TRUE);	    if(isset($post['page']))  		{			$api = $this->input->post('api',true);		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',true);						$transfer = $this->input->post('transfer',true);			$transfer_ids = $this->input->post('transfer_ids',true);			$orver_flag = $this->input->post('orver_flag',true);						$timetk = $this->input->post('timetk',true);			$timetj = $this->input->post('timetj',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$transfer_list = $this->transfer->find_all();			$t = $transfer_list = array_column($transfer_list, 'title', 'id');			$where = 'type = 1 ';						$where .= " and is_over = 0 and orver_flag = ".$orver_flag." ";            //数据排序            $order_str = "id desc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }						if($transfer){				$where  .= " and lx = '$transfer'";			}else{			    $where .= " and lx in (".$transfer_ids.") ";			}						$where  .= " and time > '$timetk' and time < '$timetj'";						$list = $this->systemtransfer_cr->find_all($where,'*',$order_str,$start,$perpage);			$final_list = [];			foreach ($list as $key => $value) {			    				$info = $this->systemtransfer->read($value['fid']);				$final_list[$key]['id'] = $value['id'];				$final_list[$key]['number'] = isset($info['number'])?$info['number']:'';							if($info['is_jiaji'] == 2){		            $final_list[$key]['is_jiaji'] = "<a href='javascript:void(0)' style='color:red'>加急</a>";		        }else{		            $final_list[$key]['is_jiaji'] = "常规";		        }							$final_list[$key]['pm'] = $info['pm'];				$final_list[$key]['shipremarks'] = $info['shipremarks'];				$final_list[$key]['printtime'] = date('Y-m-d H:i:s',$info['printtime']);				$data = $this->systemtransfer_cr->find_all("fid = '".$info['id']."'");								$info_list[$key]['time'] = "订单出库 :".date('Y-m-d H:i',$info['printtime']).'<br>';				foreach ($data as $k=>$v)		        {					$type = ($v['type']==1)?'入库':'出库';															if($v['orver_flag'] == 1){						if($v['is_over'] == 0){							$info_list[$key]['time'] .= "<a href='javascript:void(0);' style='color:#90f'>".$t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']) ." <l style='padding-left:10px;font-weight:900;'> 即将超时 </l></a>".'<br>';							// $info_list[$key]['time'] .= '<i style="padding:10px;color:#90f;font-weight:bold;"> 即将超时</i>'.'<br>';						}else{							$info_list[$key]['time'] .= "<a href='javascript:void(0);' style='color:#000'>".$t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']) ."</a>".'<br>';						}					}elseif($v['orver_flag'] == 2){						$info_list[$key]['time'] .= "<a href='javascript:void(0);' style='color:#f33'>".$t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']) ." <l style='padding-left:10px;font-weight:900'> 超 时 ! </l></a>".'<br>';					}else{						$info_list[$key]['time'] .= "<a  href='javascript:void(0);' style='color:#000'>".$t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']) ."</a>".'<br>';					}				}								$final_list[$key]['time'] = trim($info_list[$key]['time'],'<br>');			}						$total = $this->systemtransfer_cr->find_count($where);		   		    $pagenum = ceil($total/$perpage);		    $over = $total-($start+$perpage);		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($final_list));		    echo json_encode($rows);exit;		}		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);			$usp = $user;		    $pid = "";$tid="";$sid="";$wid="";		    $purchase = explode('|',trim($user['purchase'],'|'));			$transfer = explode('|',trim($user['transfer'],'|'));			$warehouse = explode('|',trim($user['warehouse'],'|'));			foreach ($purchase as $value) 		    {				$pid .= " id = ".$value." or";			}			foreach ($transfer as $value) 		    {				$tid .= " id = ".$value." or";			}			foreach ($warehouse as $value) 		    {				$wid .= " id = ".$value." or";			}		}		else		{			header('Location: /');exit;		}		$kx = '';$zjtab = '';				$transfer = $this->transfer->find_all('1=1 and '.rtrim($tid,'or'));				$this->data['transfer'] = $transfer;		$transfer_ids = array_column($transfer, 'id');		$this->data['transfer_ids'] =implode(",",$transfer_ids) ;		$this->data['vip'] = $user['vip'];		$this->data['orver_flag'] = $this->input->get('orver_flag', TRUE);		$this->_Template('transfer_linqi',$this->data);	}	//按照条件导出超时车间	public function _overtime_export(){		$transfer_id = $this->input->get('transfer', TRUE);		$timetk = $this->input->get('timetk', TRUE);		$timetj = $this->input->get('timetj', TRUE);		$timetk = strtotime($timetk);		$timetj = strtotime($timetj);		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);			$transfer_ids = explode('|',trim($user['transfer'],'|'));			$tmp_transfer_list = $this->transfer->find_all();			$transfer_list = array_column($tmp_transfer_list, 'title', 'id');		}		else		{			header('Location: /');exit;		}		$where = " orver_flag =  2 and type = 1";				if(empty($transfer_id)){			$where .= " and lx in (".implode(',',$transfer_ids).")  ";		}else{			$where .= " and lx = ".$transfer_id." ";		}		$where  .= " and time > '$timetk' and time < '$timetj'";		$list = $this->systemtransfer_cr->find_all($where,'*');		$fid_list = array_column($list, 'fid');		if(empty($fid_list)){			echo "没有数据" ;			die ;		}		$order_list = $this->systemtransfer->find_all("id in (".implode(',',$fid_list).")");						$where_two = " orver_flag =  2 and type = 2";				if(empty($transfer_id)){			$where_two .= " and lx in (".implode(',',$transfer_ids).")  ";		}else{			$where_two .= " and lx = ".$transfer_id." ";		}		$where_two  .= " and time > '$timetk' and time < '$timetj'";		$list_two = $this->systemtransfer_cr->find_all($where_two,'*');		$final_list = [];// 		foreach($list as $k => $v){// 			$final_list[$v['fid']]['fid'] = $v['fid'];// 			$final_list[$v['fid']]['lx'] = $v['lx'];// 			$final_list[$v['fid']]['start_type'] = $v['type'];// 			$final_list[$v['fid']]['start_time'] = date('Y-m-d H:i:s',$v['time']);// 			$final_list[$v['fid']]['condition'] = json_decode($v['limit_time_str'],true);// 			$final_list[$v['fid']]['end_time'] = "";// 			$final_list[$v['fid']]['lx_name'] = isset($transfer_list[$v['lx']])?$transfer_list[$v['lx']]:'';// 		}		// 		foreach($order_list as $k=>$v){// 			if(isset($final_list[$v['id']])){// 				$final_list[$v['id']]['number'] = $v['number'];// 				$final_list[$v['id']]['pm'] = $v['pm'];// 			}// 		}		// 		foreach($list_two as $k => $v){// 			if(isset($final_list[$v['fid']])){// 				if($v['lx'] ==$final_list[$v['fid']]['lx']){// 					$final_list[$v['fid']]['end_time'] = date('Y-m-d H:i:s',$v['time']);// 				}				// 			}// 		}            foreach($list as $k => $v){			$final_list[] = [				'fid' => $v['fid'],				'lx' => $v['lx'],				'start_type' => $v['type'],				'start_time' => date('Y-m-d H:i:s',$v['time']),				'condition' => json_decode($v['limit_time_str'],true),				'end_time' => "",				'lx_name' => isset($transfer_list[$v['lx']])?$transfer_list[$v['lx']]:'',			];		}				foreach($order_list as $k=>$v){			foreach($final_list as $kk => $vv){				if($v['id'] == $vv['fid']){					$final_list[$kk]['number'] = $v['number'];					$final_list[$kk]['pm'] = $v['pm'];				}			}		}				foreach($list_two as $k => $v){			foreach($final_list as $kk => $vv){				if(($v['fid'] == $vv['fid']) && ($v['lx'] == $vv['lx'])){					$final_list[$kk]['end_time'] = date('Y-m-d H:i:s',$v['time']);				}			}					}        		$filename = date("Y-m-d")."超时单导出.xls";		$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: 13px;'>"; 		$str .= "<tr><td>订单编号</td><td>品名</td><td>车间</td><td>入库日期</td><td>出库日期</td></tr>";		foreach ($final_list as $key=>$value) 		{ 		    $str .= "<tr>";			$str .= "<td>". $value['number']. "</td>";			$str .= "<td>". $value['pm']. "</td>";				$str .= "<td>". $value['lx_name']. "</td>";				$str .= "<td>". $value['start_time']. "</td>";			$str .= "<td>". $value['end_time']. "</td>";			$str .= "</tr>";		}		$str .= "</table></body></html>"; 		header( "Content-Type: application/vnd.ms-excel; name='excel'" ); 		header( "Content-type: application/octet-stream" ); 		header( "Content-Disposition: attachment; filename=".$filename ); 		header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); 		header( "Pragma: no-cache" ); 		header( "Expires: 0" ); 		exit($str); 	}}
 |