| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278 | <?php defined('BASEPATH') OR exit('No direct script access allowed');header("Access-Control-Allow-Origin: *");class Aptsmt extends Start_Controller {	public function __construct(){		parent::__construct();		$this->load->library('session');		$this->load->_model('Model_whlabel','whlabel');		$this->load->_model('Model_warehouse','warehouse');		$this->load->_model('Model_productprice','productprice');		$this->load->_model('Model_excel','excel');		$this->load->_model('Model_fullorder','fullorder');		$this->load->_model('Model_fullordertt','fullordertt');		$this->load->_model('Model_fullordersmt','fullordersmt');		$this->load->_model('Model_express','express');		$this->load->_model('Model_shop','shop');		$this->load->_model('Model_typeclass','typeclass');		$this->load->_model('Model_country','country');		$this->load->_model('Model_warehouse','warehouse');		$this->load->_model('Model_kdniao','kdniao');		$this->load->_model('Model_notice','notice');		$this->load->_model('Model_dhl','dhl');		$this->load->_model('Model_usps','usps');		$this->load->_model('Model_shop','shop');		$this->load->_model('Model_user','user');		$this->load->_model('Model_whlabel','whlabel');		$this->load->helper('url');	}	//定义方法的调用规则 获取URI第二段值    public function _remap($arg,$arg_array)    {		if($arg == 'fout')//出库页        {             $this->_fout();        }		else if($arg == 'printing')//打印操作        {             $this->_printing();        }		else if($arg == 'print')//打印操作        {             $this->_print();        }		else if($arg == 'fhd')//打印操作        {             $this->_fhd($arg_array);        }		else if($arg == 'fhdusa')//打印操作        {             $this->_fhdusa($arg_array);        }		else if($arg == 'shop')        {             $this->_shop();        }		else if($arg == 'lowe')        {             $this->_lowe();        }		else if($arg == 'express')        {             $this->_express();        }		else if($arg == 'retreat')        {             $this->_retreat();        }		else if($arg == 'excel')        {             $this->_excel();        }		else		{			 $this->_index();		}    }	//管理	public function _index()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['userid']))		{			$userid = $this->input->post('userid',true);			$userpass = $this->input->post('userpass',true);			$password = sha1($userpass);			$user = $this->user->get_uid($userid,'dlz');			if($user)			{				if($user['type'] == 2)				{					echo json_encode(array('msg'=>"账户已停用",'success'=>false));exit;				}				if($user['userpass'] == $password)				{                    $this->user->get_land($user);  //更新登录数据					echo json_encode(array('url'=>'?id='.$user['api'],'success'=>true));exit;				}				else				{					echo json_encode(array('msg'=>"用户或密码不正确",'success'=>false));exit;				}			}			else			{				echo json_encode(array('msg'=>"用户不正确",'success'=>false));exit;			}		}	}	//出库	public function _fout()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['order']))  		{			$time = time();			$order = $this->input->post('order',true);			$y = $this->fullorder->get_waybill($order);			$fullorder_name = 'fullorder';			if(!$y)			{				$y = $this->fullorder->get_number($order);				if(!$y)				{					$fullorder_name = 'fullordersmt';					$y = $this->fullordersmt->get_waybill($order);					if(!$y)				    {						$y = $this->fullordersmt->get_number($order);						if(!$y)				        {							echo json_encode(array('msg'=>'无此数据','success'=>false));exit;						}					}				}			}			if($y['libraryconfirm'] == 1 || $y['state'] == 217)			{				echo json_encode(array('msg'=>$y['librarynot'],'success'=>false));exit;			}			if($y['library'] > 1)			{				echo json_encode(array('msg'=>'此数据 '.date('Y-m-d H:i:s',$y['librarytime']).' 已操作','success'=>false));exit;			}			if($y['type'] == 5)			{				$ckcg = 0;$save = array();				$pp = explode('|',trim($y['whlabel'],'|'));				foreach ($pp as $va)		        {					$uid = array();//储存可用出库产品的ID					$num = explode('-',$va);					$shopwhlabel = $this->whlabel->find_all("state = 0 and number = '$num[0]' and warehouse = '".$y['type']."' and shop !='' and shop like '%,".$y['shop'].",%'");					$whlabel = $this->whlabel->find_all("state = 0 and number = '$num[0]' and warehouse = '".$y['type']."' and (shop IS NULL or shop = '')");					if($shopwhlabel)					{						if(count($shopwhlabel) >= $num[1])//如果专用的条数大于需求						{							for($i=0;$i<$num[1];$i++)						    {							    $uid[] = $shopwhlabel[$i]['id'];						    }						    $save[] = $uid;						}						else if(count($shopwhlabel) < $num[1] && (count($whlabel)+count($shopwhlabel)) >= $num[1])//如果专用的条数小于需求,但专用的条数+通用的条数大于等于需求,判断为可用,有限扣减专用数						{							for($i=0;$i<count($shopwhlabel);$i++)						    {							    $uid[] = $shopwhlabel[$i]['id'];						    }							for($x=0;$x<($num[1]-count($shopwhlabel));$x++)						    {							    $uid[] = $whlabel[$x]['id'];						    }						    $save[] = $uid;						}						else						{							$ckcg++;						}					}					else if(!$whlabel || count($whlabel) < $num[1])				    {					    $ckcg++;				    }					else					{						for($i=0;$i<$num[1];$i++)						{							$uid[] = $whlabel[$i]['id'];						}						$save[] = $uid;					}				}				if($ckcg > 0)				{					echo json_encode(array('msg'=>'无法匹配库存或库存为0','success'=>false));exit;				}				else				{					foreach ($save as $vb)		            {						foreach ($vb as $vc)		                {					        $this->whlabel->save(array('state'=>1,'orderinfo'=>$y['orderinfo'],'waybill'=>$y['waybill'],'outk'=>$time,'time'=>$time),$vc);						}					}				}			}			if($this->$fullorder_name->save(array('library'=>2,'librarytime'=>$time),$y['id']))        	{         		echo json_encode(array('success'=>true));exit;				if($fullorder_name == 'fullordersmt' && $y['source'] != 1)//速卖通发货声明				{					$ex = $this->express->read($y['express']);					$shop = $shop->shop->read($y['shop']);					if($y['dlz'] == 1)//如果已经声明过需要操作修改声明					{						$obtain = $this->apismt->get_obtain($y['orderinfo'],$shop['code']);//修改声明先查询之前物流信息						$result = $this->apismt->get_editout($obtain['logistics_no'],$y['whlabel'],'all',$y['orderinfo'],$obtain['service_name'],$ex['servicetitle'],$shop['code']);						if($result['result_success'] == 'true')					    {							$this->db->trans_begin();						    $this->$fullorder_name->save(array('dlz'=>1),$y['id']);							if($y['merge'] != '0')							{								$hdata = $this->$fullorder_name->find_all("merge = '".$y['merge']."' and id != '".$y['id']."'");								foreach ($hdata as $v) 								{									$obtain = $this->apismt->get_obtain($v['orderinfo'],$shop['code']);//修改声明先查询之前物流信息						            $result = $this->apismt->get_editout($obtain['logistics_no'],$y['whlabel'],'all',$v['orderinfo'],$obtain['service_name'],$ex['servicetitle'],$shop['code']);									if($result['result_success'] == 'true')					                {									    $this->$fullorder_name->save(array('dlz'=>1),$v['id']);									}								}							}							if ($this->db->trans_status() === TRUE)            				{								$this->db->trans_commit();							}							else							{								$this->db->trans_rollback();							}					    }					    else					    {						     $this->$fullorder_name->save(array('dlz'=>2),$y['id']);					    }					}					else //未发货声明状态					{					    $result = $this->apismt->get_out($y['whlabel'],'all',$y['orderinfo'],$ex['servicetitle'],$shop['code']);						$shop = $this->shop->read($y['shop']);						$go = $this->notice->get_go($y,$shop,'logisticstatus',1);//速卖通发送订单留言:已揽收						$go = ($go==1)?'揽收留言发送成功':'揽收留言发送失败';						//速卖通出库后状态需要改为209:买家待收货状态					    if($result['result_success'] == 'true')					    {							$this->db->trans_begin();						    $this->$fullorder_name->save(array('dlz'=>1,'fscontent'=>$go,'state'=>209),$y['id']);							if($y['merge'] != '0')							{								$hdata = $this->$fullorder_name->find_all("merge = '".$y['merge']."' and id != '".$y['id']."'");								foreach ($hdata as $v) 								{									 $result = $this->apismt->get_out($y['whlabel'],'all',$v['orderinfo'],$ex['servicetitle'],$shop['code']);									 $go = $this->notice->get_go($v,$shop,'logisticstatus',1);//速卖通发送订单留言:已揽收						             $go = ($go==1)?'揽收留言发送成功':'揽收留言发送失败';									 if($result['result_success'] == 'true')					                 {									    $this->$fullorder_name->save(array('dlz'=>1,'fscontent'=>$go,'state'=>209),$v['id']);									}								}							}							if ($this->db->trans_status() === TRUE)            				{								$this->db->trans_commit();							}							else							{								$this->db->trans_rollback();							}					    }					    else					    {						    $this->$fullorder_name->save(array('dlz'=>2,'fscontent'=>$go,'state'=>209),$y['id']);					    }					}									}				$sp = $this->shop->read($y['shop']);				$this->notice->get_go($y,$sp,'ordertatus',209);//通知消息模板,是否有已发货需要发送内容       	 	}       		else        	{           		echo json_encode(array('msg'=>'出库失败,请重试','success'=>false));exit;        	}		}		if(isset($post['page']))  		{		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',true);			$timetk = $this->input->post('timetk',true);			$timetj = $this->input->post('timetj',true);			$shop = $this->input->post('shop',true);			$source = $this->input->post('source',true);			$orderinfo = $this->input->post('orderinfo',true);			$number = $this->input->post('number',true);			$library = $this->input->post('library',true);			$waybill = $this->input->post('waybill',true);			$express = $this->input->post('express',true);			$type = $this->input->post('type',true);			$lowe = $this->input->post('lowe',true);			$librarytime = $this->input->post('librarytime',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$cxtime = 'id';			$where = "library!=3 and libraryconfirm=2 and mergeid = 0 and print = 3";			if($timetk && $timetj && $library == 2 && $librarytime != 1)            {				$cxtime = 'reviewtime';                $where  .= " and librarytime > '$timetk' and librarytime < '$timetj'";            }			else if($timetk && $timetj && $library == 2 && $librarytime == 1)            {				$cxtime = 'librarytime';                $where  .= " and librarytime > '$timetk' and librarytime < '$timetj'";            }			if($shop)            {                $where  .= " and shop = '$shop'";            }			if($number)            {                $where  .= " and number = '$number'";            }			if($library)            {                $where  .= " and library = '$library'";            }			if($waybill)            {                $where  .= " and waybill = '$waybill'";            }			if($express)            {				$where  .= " and express = '$express'";            }			if($orderinfo)            {                $where  .= " and orderinfo = '$orderinfo'";            }			if($type)            {                $where  .= " and type = '$type'";            }			if($lowe)            {                $where  .= " and shipremarks like '%$lowe%'";            }            //数据排序            $order_str = $cxtime." desc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }            //取得信息列表            $info_list = $this->fullorder->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,library,librarytime,shipremarks',$order_str,$start,$perpage);			 //格式化数据            foreach ($info_list as $key=>$value)		    {				$shop = $this->shop->read($value['shop']);				$info_list[$key]['shop'] = $shop['shopname'];				if($value['waybill'] == 0)				{					$info_list[$key]['waybill'] = "";				}				$express = $this->express->read($value['express']);				$info_list[$key]['express'] = $express['servicename'];				$warehouse = $this->warehouse->read($value['type']);				$info_list[$key]['type'] = $warehouse['title'];				if($value['print'] == 1)				{					$info_list[$key]['print'] = '不可打印';				}				else if($value['print'] == 2)				{					$info_list[$key]['print'] = '未打印';				}				else if($value['print'] == 3)				{					$info_list[$key]['print'] = '已打印';				}				if($value['library'] == 1)				{					$info_list[$key]['library'] = '<em class="c">未出库</em>';				}				else if($value['library'] == 2)				{					$info_list[$key]['library'] = '<em class="c">已出库</em>';				}				else if($value['library'] == 3)				{					$info_list[$key]['library'] = '<em class="c">已退库</em>';				}				if($value['librarytime'] == '0')				{					$info_list[$key]['librarytime'] = '<em class="t"></em>';				}				else				{					$info_list[$key]['librarytime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['librarytime']).'</em>';				}            }			$info_list_smt = $this->fullordersmt->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,library,librarytime,shipremarks',$order_str,$start,$perpage);			 //格式化数据            foreach ($info_list_smt as $key=>$value) 		    {				$shop = $this->shop->read($value['shop']);				$info_list_smt[$key]['shop'] = $shop['shopname'];				if($value['waybill'] == 0)				{					$info_list_smt[$key]['waybill'] = "";				}				$express = $this->express->read($value['express']);				$info_list_smt[$key]['express'] = $express['servicename'];				$warehouse = $this->warehouse->read($value['type']);				$info_list_smt[$key]['type'] = $warehouse['title'];				if($value['print'] == 1)				{					$info_list_smt[$key]['print'] = '不可打印';				}				else if($value['print'] == 2)				{					$info_list_smt[$key]['print'] = '未打印';				}				else if($value['print'] == 3)				{					$info_list_smt[$key]['print'] = '已打印';				}				if($value['library'] == 1)				{					$info_list_smt[$key]['library'] = '<em class="c">未出库</em>';				}				else if($value['library'] == 2)				{					$info_list_smt[$key]['library'] = '<em class="c">已出库</em>';				}				else if($value['library'] == 3)				{					$info_list_smt[$key]['library'] = '<em class="c">已退库</em>';				}				if($value['librarytime'] == '0')				{					$info_list_smt[$key]['librarytime'] = '<em class="t"></em>';				}				else				{					$info_list_smt[$key]['librarytime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['librarytime']).'</em>';				}            }		    $total = $this->fullorder->find_count($where);			$total += $this->fullordersmt->find_count($where);		    $pagenum = ceil($total/$perpage);		    $over = $total-($start+$perpage);		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>(array_merge($info_list,$info_list_smt)));		    echo json_encode($rows);exit;		}		$this->data['express'] = $this->express->find_all();		$this->_Template('whlabel_fout',$this->data);	}	//退库	public function _retreat()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['order']))  		{			$time = time();			$order = $this->input->post('order',true);			$y = $this->fullorder->get_waybill($order);			$fullorder_name = 'fullorder';			if(!$y)			{				$y = $this->fullorder->get_number($order);				if(!$y)				{					$fullorder_name = 'fullordersmt';					$y = $this->fullordersmt->get_waybill($order);					if(!$y)				    {						$y = $this->fullordersmt->get_number($order);						if(!$y)				        {							echo json_encode(array('msg'=>'无此数据','success'=>false));exit;						}					}				}			}			if($y['library'] == 3)			{				echo json_encode(array('msg'=>'此数据 '.date('Y-m-d H:i:s',$y['retreattime']).' 已操作','success'=>false));exit;			}			if($y['library'] == 1)			{				echo json_encode(array('msg'=>'此数据未出库','success'=>false));exit;			}			if($y['type'] == 5)			{				$ckcg = 0;$save = array();				$pp = explode('|',trim($y['whlabel'],'|'));				foreach ($pp as $va)		        {					$uid = array();//储存可用出库产品的ID					$num = explode('-',$va);					$whlabel = $this->whlabel->find_all("state = 1 and number = '$num[0]' and warehouse = '".$y['type']."' and orderinfo = '".$y['orderinfo']."' and waybill = '".$y['waybill']."'");					if(!$whlabel || count($whlabel) != $num[1])				    {					    $ckcg++;				    }					else					{						for($i=0;$i<$num[1];$i++)						{							$uid[] = $whlabel[$i]['id'];						}						$save[] = $uid;					}				}				if($ckcg > 0)				{					echo json_encode(array('msg'=>'有产品无出库信息','success'=>false));exit;				}				else				{					foreach ($save as $vb)		            {						foreach ($vb as $vc)		                {					        $this->whlabel->save(array('state'=>2,'retreat'=>$time,'time'=>$time),$vc);						}					}				}			}			if($this->$fullorder_name->save(array('library'=>3,'retreattime'=>$time),$y['id']))        	{         		echo json_encode(array('success'=>true));exit;       	 	}       		else        	{           		echo json_encode(array('msg'=>'退库失败,请重试','success'=>false));exit;        	}		}		if(isset($post['page']))  		{		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',true);			$timetk = $this->input->post('timetk',true);			$timetj = $this->input->post('timetj',true);			$shop = $this->input->post('shop',true);			$source = $this->input->post('source',true);			$orderinfo = $this->input->post('orderinfo',true);			$number = $this->input->post('number',true);			$waybill = $this->input->post('waybill',true);			$express = $this->input->post('express',true);			$type = $this->input->post('type',true);			$lowe = $this->input->post('lowe',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$where = "library=3 and gtime > 20190127";			if($timetk && $timetj)            {                $where  .= " and retreattime > '$timetk' and retreattime < '$timetj'";            }			if($shop)            {                $where  .= " and shop = '$shop'";            }			if($orderinfo)            {                $where  .= " and orderinfo = '$orderinfo'";            }			if($number)            {                $where  .= " and number = '$number'";            }			if($waybill)            {                $where  .= " and waybill = '$waybill'";            }			if($express)            {				$where  .= " and express = '$express'";            }			if($orderinfo)            {                $where  .= " and orderinfo = '$orderinfo'";            }			if($type)            {                $where  .= " and type = '$type'";            }			if($lowe)            {                $where  .= " and shipremarks like '%$lowe%'";            }            //数据排序			 $order_str = "retreattime desc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }            //取得信息列表            $info_list = $this->fullorder->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,state,retreattime,shipremarks',$order_str,$start,$perpage);			 //格式化数据            foreach ($info_list as $key=>$value) 		    {				$shop = $this->shop->read($value['shop']);				$info_list[$key]['shop'] = $shop['shopname'];				if($value['waybill'] == 0)				{					$info_list[$key]['waybill'] = "";				}				$express = $this->express->read($value['express']);				$info_list[$key]['express'] = $express['servicename'];				$warehouse = $this->warehouse->read($value['type']);				$info_list[$key]['type'] = $warehouse['title'];				$typeclass = $this->typeclass->read($value['state']);				$info_list[$key]['state'] = $typeclass['spare'];				if($value['print'] == 1)				{					$info_list[$key]['print'] = '不可打印';				}				else if($value['print'] == 2)				{					$info_list[$key]['print'] = '未打印';				}				else if($value['print'] == 3)				{					$info_list[$key]['print'] = '已打印';				}				if($value['retreattime'] == '0')				{					$info_list[$key]['retreattime'] = '<em class="t"></em>';				}				else				{					$info_list[$key]['retreattime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['retreattime']).'</em>';				}				            }			$info_list_smt = $this->fullordersmt->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,state,retreattime,shipremarks',$order_str,$start,$perpage);			 //格式化数据            foreach ($info_list_smt as $key=>$value) 		    {				$shop = $this->shop->read($value['shop']);				$info_list_smt[$key]['shop'] = $shop['shopname'];				if($value['waybill'] == 0)				{					$info_list_smt[$key]['waybill'] = "";				}				$express = $this->express->read($value['express']);				$info_list_smt[$key]['express'] = $express['servicename'];				$warehouse = $this->warehouse->read($value['type']);				$info_list_smt[$key]['type'] = $warehouse['title'];				$typeclass = $this->typeclass->read($value['state']);				$info_list_smt[$key]['state'] = $typeclass['spare'];				if($value['print'] == 1)				{					$info_list_smt[$key]['print'] = '不可打印';				}				else if($value['print'] == 2)				{					$info_list_smt[$key]['print'] = '未打印';				}				else if($value['print'] == 3)				{					$info_list_smt[$key]['print'] = '已打印';				}				if($value['retreattime'] == '0')				{					$info_list_smt[$key]['retreattime'] = '<em class="t"></em>';				}				else				{					$info_list_smt[$key]['retreattime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['retreattime']).'</em>';				}				            }		    $total = $this->fullorder->find_count($where);			$total += $this->fullordersmt->find_count($where);		    $pagenum = ceil($total/$perpage);		    $over = $total-($start+$perpage);		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>(array_merge($info_list,$info_list_smt)));		    echo json_encode($rows);exit;		}		$this->data['express'] = $this->express->find_all();		$this->_Template('whlabel_fout',$this->data);	}	//打印页面	public function _print()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['page']))  		{		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',true);			$timetk = $this->input->post('timetk',true);			$timetj = $this->input->post('timetj',true);			$shop = $this->input->post('shop',true);			$print = $this->input->post('print',true);			$express = $this->input->post('express',true);			$waybill = $this->input->post('waybill',true);			$printtype = $this->input->post('printtype',true);			$orderinfo = $this->input->post('orderinfo',true);			$number = $this->input->post('number',true);            $type = $this->input->post('type',true);			$lowe = $this->input->post('lowe',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$where = "1=1";			if($print == 3)            {                $where  .= " and printtime > '$timetk' and printtime < '$timetj' and print = 3";            }			else			{				$where  .= " and express != 0 and printtype > 0 and printtype < 3 and print = 2 and review > 4 and library = 1 and state = 207";			}			if($shop)            {                $where  .= " and shop = '$shop'";            }			if($express)            {				$where  .= " and express = '$express'";            }			if($printtype)            {                $where  .= " and printtype = '$printtype'";            }			if($orderinfo)            {                $where  .= " and orderinfo = '$orderinfo'";            }			if($number)            {                $where  .= " and number = '$number'";            }			if($waybill)            {                $where  .= " and waybill = '$waybill'";            }            if($type)            {                $where  .= " and type = '$type'";            }			if($lowe)            {                $where  .= " and shipremarks like '%$lowe%'";            }            //数据排序            $order_str = ($print != 3)?"id desc":"printtime desc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }            //取得信息列表            $info_list = $this->fullorder->find_all($where,'id,shop,orderinfo,number,express,waybill,print,printtype,printnumber,printtime,shipremarks',$order_str,$start,$perpage);			 //格式化数据            foreach ($info_list as $key=>$value) 		    {				$shop = $this->shop->read($value['shop']);				$info_list[$key]['shop'] = $shop['shopname'];				$express = $this->express->read($value['express']);				if($express)				{				    $info_list[$key]['express'] = $express['servicename'];				}				else				{					$info_list[$key]['express'] = '未选择';				}				if($value['printtime'] != 0)				{				    $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);				}				else				{					$info_list[$key]['printtime'] = '无';				}				if($value['print'] == 1)				{					$info_list[$key]['print'] = "禁止打印";				}				else if($value['print'] == 2)				{					$info_list[$key]['print'] = "未打印";				}				else if($value['print'] == 3)				{					$info_list[$key]['print'] = "已打印";				}				if($value['printtype'] == 1)				{					$info_list[$key]['printtype'] = "运单";				}				else if($value['printtype'] == 2)				{					$info_list[$key]['printtype'] = "发货单";				}				else if($value['printtype'] == 0)				{					$info_list[$key]['printtype'] = "未选择";				}            }			$info_list_smt = $this->fullordersmt->find_all($where,'id,shop,orderinfo,number,express,waybill,print,printtype,printnumber,printtime,shipremarks',$order_str,$start,$perpage);			 //格式化数据            foreach ($info_list_smt as $key=>$value) 		    {				$shop = $this->shop->read($value['shop']);				$info_list_smt[$key]['shop'] = $shop['shopname'];				$express = $this->express->read($value['express']);				if($express)				{				    $info_list_smt[$key]['express'] = $express['servicename'];				}				else				{					$info_list_smt[$key]['express'] = '未选择';				}				if($value['printtime'] != 0)				{				    $info_list_smt[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);				}				else				{					$info_list_smt[$key]['printtime'] = '无';				}				if($value['print'] == 1)				{					$info_list_smt[$key]['print'] = "禁止打印";				}				else if($value['print'] == 2)				{					$info_list_smt[$key]['print'] = "未打印";				}				else if($value['print'] == 3)				{					$info_list_smt[$key]['print'] = "已打印";				}				if($value['printtype'] == 1)				{					$info_list_smt[$key]['printtype'] = "运单";				}				else if($value['printtype'] == 2)				{					$info_list_smt[$key]['printtype'] = "发货单";				}				else if($value['printtype'] == 0)				{					$info_list_smt[$key]['printtype'] = "未选择";				}            }		    $total = $this->fullorder->find_count($where);			$total += $this->fullordersmt->find_count($where);		    $pagenum = ceil($total/$perpage);		    $over = $total-($start+$perpage);		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>(array_merge($info_list,$info_list_smt)));		    echo json_encode($rows);exit;		}		$this->_Template('whlabel_print',$this->data);	}	//打印	public function _printing()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['s']))  		{			$v = $this->input->post('s');			$va = explode(',',rtrim($v,','));			$n = $this->input->post('n');			$type = 3;$text = '';$time = time();			if($va[$n] < 100000)			{				$fullorder_name = 'fullordersmt';			}			else			{                $fullorder_name = 'fullorder';			}			$fullorder = $this->$fullorder_name->read($va[$n]);			if(isset($va[$n+1]))			{				$sf = $this->$fullorder_name->read($va[$n+1]);			    if($sf['printtype'] == 1 && $fullorder['printtype'] == 2)			    {				    sleep(9);			    }			}			$fullorder = $this->_text($fullorder);//获取所需信息			$fullorder['printtime'] = date('Y-m-d H:i',$time);//打印用时间			if($fullorder['printtype'] == 1 && $fullorder['library'] != 2)			{				if($fullorder['servicecode'] == "DHLGF")//如果打印过那么重新获取运单				{					sleep(3);				    $barcode = $this->dhl->get_data($fullorder);//获取DHL快递信息					if(isset($barcode['AirwayBillNumber']))					{						$bctime = date('Ymd',$time);						$Hwaybill = $barcode['AirwayBillNumber'];						$Hfp = $this->_pdf($barcode['LabelImage']['MultiLabels']['MultiLabel']['DocImageVal'],'f-'.$Hwaybill,$bctime);					    $Hyd = $this->_pdf($barcode['LabelImage']['OutputImage'],'y-'.$Hwaybill,$bctime);						if(isset($Hfp) && isset($Hyd) && isset($Hwaybill))						{							if($fullorder['waybill'] != "")//如果已有运单号							{								$oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];							}							else							{								$oldwaybill = $fullorder['oldwaybill'];							}							$fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删							if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill),$va[$n]))				   		 	{								$type = 1;								$text = array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','data'=>$fullorder);							}						}					}					else					{						$failed = (isset($barcode['Response']['Status']['Condition']['ConditionData'])?$barcode['Response']['Status']['Condition']['ConditionData']:$barcode['Response']['Status']['Condition'][0]['ConditionData']);						$this->$fullorder_name->save(array('print'=>1,'failed'=>$failed),$va[$n]);					}				}				else if($fullorder['servicecode'] == "USPS")				{					sleep(10);				    $barcode = $this->usps->get_data($fullorder);//获取DHL快递信息					if(isset($barcode['LabelImage']))					{						$bctime = date('Ymd',$time);						$Hwaybill = $barcode['BarcodeNumber'];					    $Hyd = $this->_pdf($barcode['LabelImage'],'y-'.$Hwaybill,$bctime);						if(isset($barcode['LabelImage']) && isset($Hwaybill))						{							if($fullorder['waybill'] != "")//如果已有运单号							{								$oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];							}							else							{								$oldwaybill = $fullorder['oldwaybill'];							}							$fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删							if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill),$va[$n]))				   		 	{								$type = 1;								$text = array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','data'=>$fullorder,'id'=>$fullorder['id'],'pt'=>$fullorder_name);							}						}					}					else					{						$failed = $barcode['Description'];//错误提示						$this->$fullorder_name->save(array('print'=>1,'failed'=>$failed),$va[$n]);					}				}				else				{					$this->$fullorder_name->save(array('print'=>1,'failed'=>'未找到此快递运单接口'),$va[$n]);				}				$rows = array('type'=>$type,'n'=>$n-1,'data'=>$v,'text'=>$text);			    echo json_encode(array('rows'=>($rows),'success'=>true));exit;			}			else if($fullorder['printtype'] == 2 && $fullorder['library'] != 2)			{sleep(4);$fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删				if($this->$fullorder_name->save(array('libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3),$va[$n]))				{					$type = 2;					$text = array('data'=>$fullorder);				}				$rows = array('type'=>$type,'n'=>$n-1,'data'=>$v,'text'=>$text);			    echo json_encode(array('rows'=>($rows),'success'=>true));exit;			}			else			{				$rows = array('type'=>$type,'n'=>$n-1,'data'=>$v,'text'=>$text);			    echo json_encode(array('msg'=>'该订单已出库,无法打印!','success'=>false));exit;			}		}	}	public function _excel()	{		if(isset($_GET['fexcel']))  		{			$dowid = $this->input->get('a');			$wid = "";			if($dowid != "")			{				$id_arr =  explode(',',rtrim($dowid,','));				foreach ($id_arr as $v) 		        {					$wid  .= " id = 0 or";                    $wid  .= " id = '$v' or";                }				$wid = " and".rtrim($wid,'or');			}		    $t = $this->input->get('t',true);			$timetk = $this->input->get('timetk',true);			$timetj = $this->input->get('timetj',true);			$shop = $this->input->get('shop',true);			$source = $this->input->get('source',true);			$orderinfo = $this->input->get('orderinfo',true);			$number = $this->input->get('number',true);			$library = $this->input->get('library',true);			$waybill = $this->input->get('waybill',true);			$express = $this->input->get('express',true);			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$where = "library!=3 and libraryconfirm=2 and mergeid = 0 and print = 3";			if($timetk && $timetj && $library == 2)            {                $where  .= " and librarytime > '$timetk' and librarytime < '$timetj'";            }			if($shop)            {                $where  .= " and shop = '$shop'";            }			if($number)            {                $where  .= " and number = '$number'";            }			if($library)            {                $where  .= " and library = '$library'";            }			if($waybill)            {                $where  .= " and waybill = '$waybill'";            }			if($express)            {				$where  .= " and express = '$express'";            }			if($orderinfo)            {                $where  .= " and orderinfo = '$orderinfo'";            }            //数据排序			$order_str = ($print != 3)?"id desc":"librarytime desc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }            //取得信息列表            $info_list = $this->fullorder->find_all($where.$wid,'shop,type,orderinfo,number,waybill,express,print,library,librarytime,shipremarks',$order_str);			 //格式化数据            foreach ($info_list as $key=>$value) 		    {				$shop = $this->shop->read($value['shop']);				$info_list[$key]['shop'] = $shop['shopname'];				if($value['waybill'] == 0)				{					$info_list[$key]['waybill'] = "";				}				$express = $this->express->read($value['express']);				$info_list[$key]['express'] = $express['servicename'];				$warehouse = $this->warehouse->read($value['type']);				$info_list[$key]['type'] = $warehouse['title'];				if($value['print'] == 1)				{					$info_list[$key]['print'] = '不可打印';				}				else if($value['print'] == 2)				{					$info_list[$key]['print'] = '未打印';				}				else if($value['print'] == 3)				{					$info_list[$key]['print'] = '已打印';				}				if($value['library'] == 1)				{					$info_list[$key]['library'] = '<em class="c">未出库</em>';				}				else if($value['library'] == 2)				{					$info_list[$key]['library'] = '<em class="c">已出库</em>';				}				else if($value['library'] == 3)				{					$info_list[$key]['library'] = '<em class="c">已退库</em>';				}				if($value['librarytime'] == '0')				{					$info_list[$key]['librarytime'] = '<em class="t"></em>';				}				else				{					$info_list[$key]['librarytime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['librarytime']).'</em>';				}            }			 //取得信息列表            $info_list_smt = $this->fullordersmt->find_all($where.$wid,'shop,type,orderinfo,number,waybill,express,print,library,librarytime,shipremarks',$order_str);			 //格式化数据            foreach ($info_list_smt as $key=>$value) 		    {				$shop = $this->shop->read($value['shop']);				$info_list_smt[$key]['shop'] = $shop['shopname'];				if($value['waybill'] == 0)				{					$info_list_smt[$key]['waybill'] = "";				}				$express = $this->express->read($value['express']);				$info_list_smt[$key]['express'] = $express['servicename'];				$warehouse = $this->warehouse->read($value['type']);				$info_list_smt[$key]['type'] = $warehouse['title'];				if($value['print'] == 1)				{					$info_list_smt[$key]['print'] = '不可打印';				}				else if($value['print'] == 2)				{					$info_list_smt[$key]['print'] = '未打印';				}				else if($value['print'] == 3)				{					$info_list_smt[$key]['print'] = '已打印';				}				if($value['library'] == 1)				{					$info_list_smt[$key]['library'] = '<em class="c">未出库</em>';				}				else if($value['library'] == 2)				{					$info_list_smt[$key]['library'] = '<em class="c">已出库</em>';				}				else if($value['library'] == 3)				{					$info_list_smt[$key]['library'] = '<em class="c">已退库</em>';				}				if($value['librarytime'] == '0')				{					$info_list_smt[$key]['librarytime'] = '<em class="t"></em>';				}				else				{					$info_list_smt[$key]['librarytime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['librarytime']).'</em>';				}            }            $title = '订单出库-'.date('Ymd',time());            $titlename = "<table border=1>".$t."</table>";			$tail = "\n";            $filename = $title.".xls";            $this->excel->get_fz2(array_merge($info_list,$info_list_smt),$titlename,$filename,$tail);		}	}	public function _fhd($arg_array)    {		if(isset($arg_array[0]))		{			$fullorder = $this->fullorder->read($arg_array[0]);			$fullorder = $this->_text($fullorder);//获取所需信息			$this->data['data'] = $fullorder;		    $this->_Template('apt_fhd',$this->data);		}	}	public function _fhdusa($arg_array)    {		if(isset($arg_array[0]))		{			if($arg_array[0] < 100000)			{				$fullorder_name = 'fullordersmt';			}			else			{                $fullorder_name = 'fullorder';			}			$fullorder = $this->$fullorder_name->read($arg_array[0]);			$fullorder = $this->_text($fullorder);//获取所需信息			$fullorder['printtime'] = date('Y-m-d H:i:s',$fullorder['printtime']);			$this->data['data'] = $fullorder;		    $this->_Template('apt_fhdusa',$this->data);		}	}	public function _text($fullorder)    {		/** 发票地址信息暂时无用 		$fullorder['baddress'] = explode(',',$fullorder['baddress']);		$fullorder['baddress'] = array_reverse($fullorder['baddress']);		$fullorder['baddress'][1] = $country['ename'];		**/		//获取所用相关信息		$warehouse = $this->warehouse->read($fullorder['type']);		$country = $this->country->read($fullorder['country']);//订单国家信息		$fcountry = $this->country->read($warehouse['country']);//仓库国家信息		$warehouse['country'] = $fcountry['ename'];//仓库国家名		$warehouse['lb'] = $fcountry['lb'];//仓库国家编码		$fullorder['warehouse'] = $warehouse;//仓库数据加入订单		$fullorder['lb'] = $country['lb'];//订单国家编码加入		$fullorder['country'] = $country['ename'];//订单国家名		$express = $this->express->read($fullorder['express']);		$fullorder['express'] = $express['servicename'];		$fullorder['account'] = $express['account'];		$fullorder['servicecode'] = $express['servicecode'];		$fullorder['time'] = date('Y-m-d',time());		$fullorder['times'] = date('Y-m-d H:i',time());		$fullorder['sbbm']= ($fullorder['sbpm'] == 'Hair Sample') ? 67042000 : 67041100;		$fullorder['address'] = str_replace(array('&'),array('&'),$fullorder['address']);		$shop = $this->shop->read($fullorder['shop']);		$fullorder['shop'] = $shop['shopname'];		return $fullorder;    }	public function _shop()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['shop']))  		{		    $shop = $this->shop->find_all();		    echo json_encode(array('msg'=>$shop));exit;		}	}	public function _lowe()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['lowe']))  		{		    $lowe = $this->typeclass->find_all('classid = 15 and id != 105 and id != 107 and id != 108 and id != 112 and id != 114 and id != 115 and id != 116 and id != 117 and id != 118 and id != 119 and id != 120 and id != 121 and id != 122 and id != 123 and id != 124 and id != 125 and id != 292 and id != 63 and id != 289 and id != 290 and id != 181 and id != 273 and id != 148 and id != 38 and id != 291 and id != 55 and id != 271 and id != 285 and id != 186 and id != 187 and id != 188 and id != 189');		    echo json_encode(array('msg'=>$lowe));exit;		}	}	public function _express()	{		$post = $this->input->post(NULL, TRUE);		if(isset($post['express']))  		{		    $express = $this->express->find_all();		    echo json_encode(array('msg'=>$express));exit;		}	}	public function _pdf($pdf,$title,$bctime)    {    	$pdf_path = './data/pdf/'.$bctime.'/';        $file_base64 = $pdf;         $file_base64 = preg_replace('/data:.*;base64,/i', '', $file_base64);          $file_base64 = base64_decode($file_base64);		if(!is_dir($pdf_path))mkdir($pdf_path,0777); //上传目录不存在则创建        file_put_contents($pdf_path.$title.'.pdf',$file_base64);		return $bctime;    }}
 |