load->library('session');
		$this->load->_model('Model_whlabel','whlabel');
		$this->load->_model('Model_warehouse','warehouse');
		$this->load->_model('Model_purchase','purchase');
		$this->load->_model('Model_excel','excel');
		$this->load->_model('Model_fullorder','fullorder');
		$this->load->_model('Model_fullordertt','fullordertt');
		$this->load->_model('Model_fullorder_smt','fullorder_smt');
		$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_shop','shop');
		$this->load->_model('Model_fullorderexcel','fullorderexcel');
		$this->load->_model('Model_ljg','ljg');
		$this->load->_model('Model_usps','usps');
		$this->load->_model('Model_specialstock','specialstock');
		$this->load->_model('Model_whlabellabel','whlabellabel');
		$this->load->_model('Model_whlabelwz','whlabelwz');
		$this->load->_model('Model_whlabelbarcode','whlabelbarcode');
		$this->load->_model('Model_whlabeltransport','whlabeltransport');
		$this->load->_model('Model_orderurl','orderurl');
		$this->load->_model('Model_brand','brand');
		$this->load->_model('Model_classid','classid');
		$this->load->_model('Model_apiyy','apiyy');
		$this->load->_model('Model_power','power');
		$this->load->_model('Model_whlabel_type','whlabel_type');
		$this->load->_model('Model_company','company');
		$this->load->_model('Model_whlabel_list','whlabel_list');
	}
	//定义方法的调用规则 获取URI第二段值
    public function _remap($arg,$arg_array)
    {
		if($arg == 'existence')//在库标签
        {
             $this->_existence();
        }
		else if($arg == 'cpbqdc')//在库标签
        {
             $this->_cpbqdc();
        }
		else if($arg == 'type')//进销存浏览
        {
             $this->_type();
        }
		else if($arg == 'typedy')//进销存浏览店员页面
        {
             $this->_typedy($arg_array);
        }
		else if($arg == 'typedy_ck')//进销存浏览店员页面
        {
             $this->_typedy_ck($arg_array);
        }
		else if($arg == 'typeck')
        {
             $this->_typeck($arg_array);
        }
		else if($arg == 'whlabeckdc')
        {
             $this->_whlabeckdc($arg_array);
        }
		else if($arg == 'usatype')//美仓进销存浏览
        {
             $this->_usatype();
        }
		else if($arg == 'usatypeapp')//美仓APP进销存浏览
        {
             $this->_usatypeapp();
        }
		else if($arg == 'enteradd')//入库操作
        {
             $this->_enteradd();
        }
		else if($arg == 'enteredit')//修改
        {
             $this->_enteredit($arg_array);
        }
		else if($arg == 'enter')//入库浏览
        {
             $this->_enter();
        }
		else if($arg == 'out')//出库浏览
        {
             $this->_out();
        }
		else if($arg == 'label')//出库标签浏览
        {
             $this->_label();
        }
		else if($arg == 'outorder')//独立站出库订单
        {
             $this->_outorder();
        }
		else if($arg == 'soutorder')//速卖通出库订单
        {
             $this->_soutorder();
        }
		else if($arg == 'toutorder')//TT出库订单
        {
             $this->_toutorder();
        }
		else if($arg == 'retreat')//退库订单
        {
             $this->_retreat();
        }
		else if($arg == 'retreatlk')//退库订单
        {
             $this->_retreatlk();
        }
		else if($arg == 'change')//更换标签
        {
             $this->_change();
        }
		else if($arg == 'del')//删除
        {
             $this->_del();
        }
		else if($arg == 'exceljxc')//进销存信息导出
        {
             $this->_exceljxc();
        }
		else if($arg == 'excelr')//入库信息导出
        {
             $this->_excelr();
        }
		else if($arg == 'excelct')//出库、退库信息导出
        {
             $this->_excelct();
        }
		else if($arg == 'dccrtype')//根据出入库类型导出
        {
             $this->_dccrtype();
        }
		else if($arg == 'excelcr')//出库、退库信息导出
        {
             $this->_excelcr();
        }
		else if($arg == 'kcyz')//库存验证
        {
             $this->_kcyz();
        }
		else if($arg == 'kj')//库存扣减
        {
             $this->_kj($arg_array);
        }
		else if($arg == 'presetout')//预设库存导入
        {
             $this->_presetout($arg_array);
        }
		else if($arg == 'presetedit')//预设库存导入
        {
             $this->_presetedit($arg_array);
        }
		else if($arg == 'summary')//汇总导出
        {
             $this->_summary($arg_array);
        }
		else if($arg == 'manifest')//usps发货清单
        {
             $this->_manifest();
        }
		else if($arg == 'abnormal')//占单异常
        {
             $this->_abnormal();
        }
		else if($arg == 'error')//0库存SKU
        {
             $this->_error();
        }
		else if($arg == 'errorexcel')//0库存SKU导出
        {
             $this->_errorexcel();
        }
		else if($arg == 'db')
        {
             $this->_db();
        }
		else if($arg == 'dbrk')
        {
             $this->_dbrk();
        }
		else if($arg == 'whlabelczdc')
        {
             $this->_whlabelczdc();
        }
		else if($arg == 'print')
        {
             $this->_print($arg_array);
        }
		else if($arg == 'usaprint')
        {
             $this->_usaprint($arg_array);
        }
		else if($arg == 'printck')
        {
             $this->_printck($arg_array);
        }
		else if($arg == 'printrk')
        {
             $this->_printrk($arg_array);
        }
		else if($arg == 'printxzrk')
        {
             $this->_printxzrk($arg_array);
        }
		else if($arg == 'printexcel')
        {
             $this->_printexcel($arg_array);
        }
		else if($arg == 'uck')
        {
             $this->_uck();
        }
		else if($arg == 'whlabelexcelzh')
        {
             $this->_whlabelexcelzh();
        }
		else if($arg == 'fc')
        {
             $this->_fc();
        }
		else if($arg == 'fcmb')
        {
             $this->_fcmb();
        }
		else if($arg == 'fcexcel')
        {
             $this->_fcexcel();
        }
		else if($arg == 'fcjxc')
        {
             $this->_fcjxc($arg_array);
        }
		else if($arg == '0kcdel')
        {
             $this->_0kcdel();//导表删除0库存
        }
		else if($arg == 'gbhtype')
        {
             $this->_gbhtype();//更改备货状态
        }
		else
		{
			 $this->_index();
		}
    }
	//管理
	public function _index()
	{
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$sku = $this->input->post('sku',true);
			$number = $this->input->post('number',true);
			$warehouse = $this->input->post('warehouse',true);
			$purchase = $this->input->post('purchase',true);
			$orderinfo = $this->input->post('orderinfo',true);
			$waybill = $this->input->post('waybill',true);
			$category = $this->input->post('category',true);
			$size = $this->input->post('size',true);
			$grade = $this->input->post('grade',true);
			$color = $this->input->post('color',true);
			$lowe = $this->input->post('lowe',true);
			$state = $this->input->post('state',true);
			$label = $this->input->post('label',true);
			$timetk = $this->input->post('timetkk',true);
			$timetj = $this->input->post('timetjj',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			$where = "1=1 ";
			if($timetk && $timetj)
            {
                $where .= " and time > '$timetk' and time < '$timetj'";
            }
			if($sku)
            {
                $where  .= " and sku = '$sku'";
            }
			if($number)
            {
                $where  .= " and number = '$number'";
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($orderinfo)
            {
                $where  .= " and orderinfo = '$orderinfo'";
            }
			if($waybill)
            {
                $where  .= " and waybill = '$waybill'";
            }
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($label)
            {
                $where  .= " and label = '$label'";
            }
			if($state != '')
            {
                $where  .= " and state = '$state'";
            }
            //数据排序
            $order_str = "time desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            $info_list = $this->whlabel->find_all($where,'id,state,purchase,sku,title,label,printing,enter,warehouse,outk,orderinfo,waybill,text,time',$order_str,$start,$perpage);
			foreach ($info_list as $key=>$value) 
		    {
				$warehouse = $this->warehouse->read($value['warehouse']);
				$info_list[$key]['warehouse'] = $warehouse['title'];
				$purchase = $this->purchase->read($value['purchase']);
				$info_list[$key]['purchase'] = $purchase['title'];
				if($value['enter'] != 0)
				{
					$info_list[$key]['enter'] = '
'.date('Y-m-d',$value['enter']).'
'.date('H:i:s',$value['enter']).'
';
				}
				else
				{
					$info_list[$key]['enter'] = "";
				}
				if($value['outk'] != 0)
				{
					$info_list[$key]['outk'] = ''.date('Y-m-d',$value['outk']).'
'.date('H:i:s',$value['outk']).'
';
				}
				else
				{
					$info_list[$key]['outk'] = "";
				}
				if($value['printing'] != 0)
				{
					$info_list[$key]['printing'] = ''.date('Y-m-d',$value['printing']).'
'.date('H:i:s',$value['printing']).'
';
				}
				else
				{
					$info_list[$key]['printing'] = "";
				}
				if($value['orderinfo'] == 0)
				{
					$info_list[$key]['orderinfo'] = "";
				}
				if($value['waybill'] == 0)
				{
					$info_list[$key]['waybill'] = "";
				}
				if($value['state'] == 0)
				{
					$info_list[$key]['state'] = "在库";
				}
				else if($value['state'] == 1)
				{
					$info_list[$key]['state'] = "出库";
				}
				else if($value['state'] == 2)
				{
					$info_list[$key]['state'] = "退库";
				}
				else if($value['state'] == 3)
				{
					$info_list[$key]['state'] = "调拨中";
				}
				else if($value['state'] == 4)
				{
					$info_list[$key]['state'] = "再加工";
				}
				else if($value['state'] == 5)
				{
					$info_list[$key]['state'] = "维修中";
				}
				else if($value['state'] == 6)
				{
					$info_list[$key]['state'] = "盘亏";
				}
				else if($value['state'] == 7)
				{
					$info_list[$key]['state'] = "更换标签";
				}
				else if($value['state'] == 8)
				{
					$info_list[$key]['state'] = "其它";
				}
				else if($value['state'] == 9)
				{
					$info_list[$key]['state'] = "预设";
				}
				else if($value['state'] == 10)
				{
					$info_list[$key]['state'] = "美店零售";
				}
				if($value['text'] == "")
				{
					$info_list[$key]['text'] = "";
				}
				$info_list[$key]['time'] = ''.date('Y-m-d',$value['time']).'
'.date('H:i:s',$value['time']).'
';
		    }
		    $total = $this->whlabel->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($post['outsku']))  
		{
			$cz = $this->input->post('cz',true);
			if($cz == '1')
			{
				$sku = $this->input->post('outsku',true);
				if($sku)
				{
			    	$data = $this->whlabel->find_all("sku = '$sku' and zd = '' and state = '0' and warehouse = '5'");
			    	if(count($data) < 1)
			    	{
				     	echo json_encode(array('msg'=>'库存不足!','success'=>false));exit;
			    	}
			    	$this->whlabel->save(array('state'=>10,'outk'=>time(),'time'=>time(),'cktype'=>1),$data[0]['id']);
			    	echo json_encode(array('success'=>true));exit;
				}
			}
			else
			{
				$sku = $this->input->post('outsku',true);
				if($sku)
				{
			    	$data = $this->whlabel->find_all("sku = '$sku' and state = '10' and warehouse = '5'");
			    	if(count($data) < 1)
			    	{
				     	echo json_encode(array('msg'=>'没有此SKU出库数据!','success'=>false));exit;
			    	}
			    	$this->whlabel->save(array('state'=>0,'outk'=>0,'time'=>time()),$data[0]['id']);
			    	echo json_encode(array('success'=>true));exit;
				}
			}
		}
		$this->data['url'] = str_replace('/','',$this->uri->slash_segment(2));
		$this->_Template('whlabel',$this->data);
	}
	//在库标签
	public function _existence()
	{
		$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) 
		    {
				$sid = $this->whlabel->read($v);
				$count = $this->whlabel->find_count("state = 0 and sku =  '".$sid['sku']."' and warehouse = '".$sid['warehouse']."' and zd != ''");
				if($count > 0)
				{
					echo json_encode(array('msg'=>'有占单,需要先解除占单!','success'=>true));exit;
				}
				$zt = $this->whlabeltransport->find_all('sku = "'.$sid['sku'].'" and warehouse = "'.$sid['warehouse'].'" and features = "'.$sid['features'].'" and cz = "0"');
				if(count($zt) > 0)
				{
					echo json_encode(array('msg'=>'有在途库存无法删除!','success'=>false));exit;
				}
                $this->whlabel->remove($v);
            }
            echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));exit;
		}
		if(isset($post['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$warehouse = $this->input->post('warehouse',true);
			$label = $this->input->post('label',true);
			
			$where = "1=1 and state = 0";
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($label)
            {
                $where  .= " and label = '$label'";
            }
            //数据排序
            $order_str = "time asc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            $info_list = $this->whlabel->find_all($where,'id,sku,title,label,printing,enter',$order_str,$start,$perpage);
			foreach ($info_list as $key=>$value) 
		    {
				if($value['enter'] != 0)
				{
					$info_list[$key]['enter'] = date('Y-m-d H:i:s',$value['enter']);
				}
				else
				{
					$info_list[$key]['enter'] = "";
				}
				if($value['printing'] != 0)
				{
					$info_list[$key]['printing'] = date('Y-m-d H:i:s',$value['printing']);
				}
				else
				{
					$info_list[$key]['printing'] = "";
				}
				
		    }
		    $total = $this->whlabel->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('whlabel_existence',$this->data);
	}
	//进销存浏览
	public function _typedy($arg_array)
	{
		$prc = array();
		$purchase = $this->purchase->find_all();
		foreach($purchase as $k=>$v)
		{
			$prc[$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);
			$category = $this->input->post('category',true);
			$size = $this->input->post('size',true);
			$grade = $this->input->post('grade',true);
			$color = $this->input->post('color',true);
			$lowe = $this->input->post('lowe',true);
			$sku = $this->input->post('sku');
			$title = $this->input->post('title');
			$warehouse = $this->input->post('warehouse',true);
			$usa = $this->input->post('usa',true);
			$purchase = $this->input->post('purchase',true);
			$lacetype = $this->input->post('lacetype',true);
			$haircap = $this->input->post('haircap',true);
			$density = $this->input->post('density',true);
			$details = $this->input->post('details',true);
			$state = $this->input->post('state',true);
			$lacecolor = $this->input->post('lacecolor',true);
			$hairnumber = $this->input->post('hairnumber',true);
			$cklx = $this->input->post('cklx',true);
			$ktime = $this->input->post('ktime',true);
			$jtime = $this->input->post('jtime',true);
			$ktime = strtotime($ktime);
			$jtime = strtotime($jtime);
			$where = "1=1";$gj = "";$ck = "";
			
			if($usa)
            {
				if(!$warehouse)
				{
                    $where  .= " and (warehouse = '5' or warehouse = '8')";
				}
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($details)
            {
                $where  .= " and details = '$details'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($state)
            {
                $where  .= " and state = '$state'";
            }
			if($lacetype)
            {
                $where  .= " and features like '%-$lacetype-%'";
            }
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($haircap)
            {
                $where  .= " and features like '%-$haircap-%'";
            }
			if($density)
            {
                $where  .= " and features like '%-$density-%'";
            }
			if($lacecolor)
            {
                $where  .= " and features like '%-$lacecolor-%'";
            }
			if(!empty($hairnumber)){
				$where  .= " and  features like '%-128-%' ";
				if($hairnumber < 0){
					$class_list = $this->typeclass->find_all('classid = 43');
					foreach($class_list as $v){
						$where .= " and  features not like '%-".$v['id']."-%'";
					}
				}else{
					$where  .= " and features like '%-$hairnumber-%'";
				}
			}
			$where_add = '';
			if($cklx)
            {
				$shop = $this->shop->read($cklx);
                $where_add  .= " and zd like '".$shop['shortname']."%' and state = 0";
            }
			if($ktime && $jtime)
            {
                $gj  = " and enter > '$ktime' and enter < '$jtime'";
				$ck  = " and outk > '$ktime' and outk < '$jtime'";
            }
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
			if($sku)
            {
				$sku = trim($sku,' ');
				$sku = trim($sku,'	');
                $where  .= " and sku like '%$sku%'";
				$info_list = $this->whlabel->find_pc($where.$where_add,'sku,features,warehouse','id,warehouse,purchase,sku,title,details,shop,cpbz,features,number,sm',$order_str,$start,$perpage);
            }
			else if($title)
            {
				$title = trim($title,' ');
				$title = trim($title,'	');
                $where  .= " and title like '%$title%'";
				$info_list = $this->whlabel->find_pc($where.$where_add,'sku,features,warehouse','id,warehouse,purchase,sku,title,details,shop,cpbz,features,number,sm',$order_str,$start,$perpage);
            }
			else
			{
				//$where  .= " and time > '$ktime' and time < '$jtime'";
				$info_list = $this->whlabel->find_pc($where.$where_add,'sku,features,warehouse','id,warehouse,purchase,sku,title,details,shop,cpbz,features,number,sm',$order_str,$start,$perpage);
			}
            //取得信息列表
           
			$rows = array();$list = array();
			foreach ($info_list as $key=>$value) 
		    {
				$warehouse = $this->warehouse->read($value['warehouse']);
				$info_list[$key]['purchase'] = (isset($prc[$value['purchase']]))?$prc[$value['purchase']]:'未知';
				$c = $this->whlabel->find_all($where.' and sku = "'.$value['sku'].'" and state = 0 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"','details,cpid');
				$z = $this->whlabel->find_all($where.' and sku = "'.$value['sku'].'" and zd != "" and state = 0 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
				$info_list[$key]['cpbz'] = ''.$value['cpbz'].'
'.$value['sm'].'
';
				$number = $value['number'];$ftime = time()-15*24*3600;
				$info_list[$key]['warehouse'] = $warehouse['title'];
				$info_list[$key]['features'] = count($c);
				$z = count($z);//查看订单号
				$zt = $this->whlabeltransport->find_all('sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'" and cz = "0"');
				$ztdata = '';
				if(count($zt) > 0)
				{
					foreach ($zt as $vv) 
		            {
						$ztdata .= ''.$vv['num'].' - '.date('Y-m-d',$vv['stime']).'
';	
					}
				}
				$info_list[$key]['number'] = $ztdata;
				$info_list[$key]['sm'] = $z;
				$details = array();
				$cpid = array();
				foreach ($c as $k=>$v) 
		    	{
					$details[$v['details']] = $v['details'];
					if($v['cpid'] != 0)
					{
					    $cpid[$v['cpid']] = $v['cpid'];
					}
				}
				$info_list[$key]['details'] = ($cpid)?implode(" ",$details).''.implode(" ",$cpid).'
':implode(" ",$details);
				if($value['shop'] != '')
				{
				    $shop = explode(',',trim($value['shop'],','));
				    $shop = $this->shop->read($shop[0]);
				     $info_list[$key]['shop'] = $shop['shopname'];
				}
		    }
			$total = count($this->whlabel->find_pc($where.$where_add,'sku,features,warehouse','id,warehouse,sku,title,features,number'));
		    $pagenum = ceil($total/$perpage);
		    $over = $total-($start+$perpage);
		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'CS'=>$warehouse);
		    echo json_encode($rows);exit;
		}
		$this->data['warehouse'] = (isset($arg_array[0]))?$arg_array[0]:5;
		$this->_Template('whlabel_typedy',$this->data);
	}
	
	//进销存浏览
	public function _typedy_ck($arg_array)
	{
		$prc = array();
		$purchase = $this->purchase->find_all();
		foreach($purchase as $k=>$v)
		{
			$prc[$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);
			$category = $this->input->post('category',true);
			$size = $this->input->post('size',true);
			$grade = $this->input->post('grade',true);
			$color = $this->input->post('color',true);
			$lowe = $this->input->post('lowe',true);
			$sku = $this->input->post('sku');
			$title = $this->input->post('title');
			$warehouse = $this->input->post('warehouse',true);
			$usa = $this->input->post('usa',true);
			$purchase = $this->input->post('purchase',true);
			$lacetype = $this->input->post('lacetype',true);
			$haircap = $this->input->post('haircap',true);
			$density = $this->input->post('density',true);
			$details = $this->input->post('details',true);
			$state = $this->input->post('state',true);
			$lacecolor = $this->input->post('lacecolor',true);
			$cklx = $this->input->post('cklx',true);
			$ktime = $this->input->post('ktime',true);
			$jtime = $this->input->post('jtime',true);
			$ktime = strtotime($ktime);
			$jtime = strtotime($jtime);
			$where = "1=1";$gj = "";$ck = "";
			if($lacetype)
            {
                $where  .= " and features like '%-$lacetype-%'";
            }
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($haircap)
            {
                $where  .= " and features like '%-$haircap-%'";
            }
			if($density)
            {
                $where  .= " and features like '%-$density-%'";
            }
			if($lacecolor)
            {
                $where  .= " and features like '%-$lacecolor-%'";
            }
			if($usa)
            {
				if(!$warehouse)
				{
                    $where  .= " and (warehouse = '5' or warehouse = '8')";
				}
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($details)
            {
                $where  .= " and details = '$details'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($state)
            {
                $where  .= " and state = '$state'";
            }
			$where_add = '';
			if($cklx)
            {
				$shop = $this->shop->read($cklx);
                $where_add  .= " and zd like '".$shop['shortname']."%' and state = 0";
            }
			if($ktime && $jtime)
            {
                $gj  = " and enter > '$ktime' and enter < '$jtime'";
				$ck  = " and outk > '$ktime' and outk < '$jtime'";
            }
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
			if($sku)
            {
				$sku = trim($sku,' ');
				$sku = trim($sku,'	');
                $where  .= " and sku like '%$sku%'";
				$info_list = $this->whlabel->find_pc($where.$where_add,'sku,features,warehouse','id,warehouse,purchase,sku,title,details,shop,cpbz,features,number',$order_str,$start,$perpage);
            }
			else if($title)
            {
				$title = trim($title,' ');
				$title = trim($title,'	');
                $where  .= " and title like '%$title%'";
				$info_list = $this->whlabel->find_pc($where.$where_add,'sku,features,warehouse','id,warehouse,purchase,sku,title,details,shop,cpbz,features,number',$order_str,$start,$perpage);
            }
			else
			{
				//$where  .= " and time > '$ktime' and time < '$jtime'";
				$info_list = $this->whlabel->find_pc($where.$where_add.' and zd != ""','sku,features,warehouse','id,warehouse,purchase,sku,title,details,shop,cpbz,features,zd,COUNT(CASE WHEN zd != "" and state = 0 THEN 1 ELSE NULL END) AS zd','zd desc',$start,$perpage);
			}
            //取得信息列表
           
			$rows = array();$list = array();
			foreach ($info_list as $key=>$value) 
		    {
				$warehouse = $this->warehouse->read($value['warehouse']);
				$info_list[$key]['purchase'] = (isset($prc[$value['purchase']]))?$prc[$value['purchase']]:'未知';
				$c = $this->whlabel->find_all($where.' and sku = "'.$value['sku'].'" and state = 0 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"','details,cpid,text');
				//$z = $this->whlabel->find_all($where.' and sku = "'.$value['sku'].'" and zd != "" and state = 0 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
				$info_list[$key]['cpbz'] = ''.$value['cpbz'].'
'.$c[0]['text'].'
';
				$ftime = time()-15*24*3600;
				$info_list[$key]['warehouse'] = $warehouse['title'];
				$info_list[$key]['features'] = count($c)<10?"".count($c)."":count($c);
				//$z = count($z);//查看订单号
				//$info_list[$key]['zd'] = $z;
				$details = array();
				$cpid = array();
				foreach ($c as $k=>$v) 
		    	{
					$details[$v['details']] = $v['details'];
					if($v['cpid'] != 0)
					{
					    $cpid[$v['cpid']] = $v['cpid'];
					}
				}
				$info_list[$key]['details'] = ($cpid)?implode(" ",$details).''.implode(" ",$cpid).'
':implode(" ",$details);
				if($value['shop'] != '')
				{
				    $shop = explode(',',trim($value['shop'],','));
				    $shop = $this->shop->read($shop[0]);
				     $info_list[$key]['shop'] = $shop['shopname'];
				}
		    }
			
			$total = count($this->whlabel->find_pc($where.$where_add,'sku,features,warehouse','id,warehouse,sku,title,features,number'));
		    $pagenum = ceil($total/$perpage);
		    $over = $total-($start+$perpage);
		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'CS'=>$warehouse);
		    echo json_encode($rows);exit;
		}
		$this->data['warehouse'] = (isset($arg_array[0]))?$arg_array[0]:5;
		$this->_Template('whlabel_typedy_ck',$this->data);
	}
	
	
	public function _typeck($arg_array)
	{
		$prc = array();
		$purchase = $this->purchase->find_all();
		foreach($purchase as $k=>$v)
		{
			$prc[$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);
			$category = $this->input->post('category',true);
			$size = $this->input->post('size',true);
			$grade = $this->input->post('grade',true);
			$color = $this->input->post('color',true);
			$lacecolor = $this->input->post('lacecolor',true);
			$lowe = $this->input->post('lowe',true);
			$sku = $this->input->post('sku');
			$title = $this->input->post('title');
			$warehouse = 13;
			$usa = $this->input->post('usa',true);
			$purchase = $this->input->post('purchase',true);
			$lacetype = $this->input->post('lacetype',true);
			$haircap = $this->input->post('haircap',true);
			$density = $this->input->post('density',true);
			$details = $this->input->post('details',true);
			$state = $this->input->post('state',true);
			$ktime = $this->input->post('ktime',true);
			$jtime = $this->input->post('jtime',true);
			$ktime = strtotime($ktime);
			$jtime = strtotime($jtime);
			$where = "1=1";$gj = "";$ck = "";
			if($lacetype)
            {
                $where  .= " and features like '%-$lacetype-%'";
            }
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lacecolor)
            {
                $where  .= " and features like '%-$lacecolor-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($haircap)
            {
                $where  .= " and features like '%-$haircap-%'";
            }
			if($density)
            {
                $where  .= " and features like '%-$density-%'";
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($details)
            {
                $where  .= " and details = '$details'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($state)
            {
                $where  .= " and state = '$state'";
            }
			if($ktime && $jtime)
            {
                $gj  = " and enter > '$ktime' and enter < '$jtime'";
				$ck  = " and outk > '$ktime' and outk < '$jtime'";
            }
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
			if($sku)
            {
				$sku = trim($sku,' ');
				$sku = trim($sku,'	');
                $where  .= " and sku like '%$sku%'";
            }
			else if($title)
            {
				$title = trim($title,' ');
				$title = trim($title,'	');
                $where  .= " and title like '%$title%'";
            }
			$info_list = $this->whlabel->find_pc($where,'sku,purchase,features,warehouse','id,warehouse,purchase,sku,sm,details,cpbz,features,number,',$order_str,$start,$perpage);
            //取得信息列表
			$t = array();
            $typeclass = $this->typeclass->find_all();
		    foreach ($typeclass as $v) 
		    {
				$t[$v['id']] = $v;
			}
			$rows = array();$list = array();
			foreach ($info_list as $key=>$value) 
		    {
				$info_list[$key]['purchase'] = (isset($prc[$value['purchase']]))?$prc[$value['purchase']]:'未知';
				$mc = $this->whlabel->find_all("sku = '".$value['sku']."' and features = '".$value['features']."' and warehouse = '".$value['warehouse']."'",'cpbz','id desc',0,1);
				$warehouse = $this->warehouse->read($value['warehouse']);
				$c = $this->whlabel->find_all($where.' and purchase = "'.$value['purchase'].'" and sku = "'.$value['sku'].'" and state = 0 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"','details,cpid');
				$z = $this->whlabel->find_all($where.' and purchase = "'.$value['purchase'].'" and sku = "'.$value['sku'].'" and zd != "" and state = 0 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
				$info_list[$key]['cpbz'] = ''.$value['cpbz'].'
'.$value['sm'].'
';
				$number = $value['number'];$ftime = time()-15*24*3600;
				$z = count($z);//查看订单号
				$info_list[$key]['warehouse'] = $warehouse['title'];
				$info_list[$key]['features'] = count($c);
				$info_list[$key]['number'] = $z;
				//$info_list[$key]['cpbz'] = $mc[0]['cpbz'];
				$details = array();
				$cpid = array();
				foreach ($c as $k=>$v) 
		    	{
					$details[$v['details']] = $v['details'];
					if($v['cpid'] != 0)
					{
					    $cpid[$v['cpid']] = $v['cpid'];
					}
				}
				$info_list[$key]['details'] = ($cpid)?implode(" ",$details).''.implode(" ",$cpid).'
':implode(" ",$details);
				$classid = $this->classid->sku();
		        $pm = $classid;
				$features = explode('-',trim($value['features'],'-'));
				foreach($features as $v)
				{
					$zh = explode('|',trim($t[$v]['zh'],'|'));
					$pm[$t[$v]['classid']] = $zh[0];
				}
				$zh = implode(" ",$pm);
				$zh = str_replace('自然色 ','',rtrim($zh,' '));
				$zh = str_replace(array('        ','       ','      ','     ','    ','   ','  '),' ',$zh);
				$info_list[$key]['sm'] = $zh;
				
		    }
			$total = count($this->whlabel->find_pc($where,'sku,features,warehouse','id,warehouse,sku,title,features,number'));
		    $pagenum = ceil($total/$perpage);
		    $over = $total-($start+$perpage);
		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'CS'=>$warehouse);
		    echo json_encode($rows);exit;
		}
		$this->data['warehouse'] = (isset($arg_array[0]))?$arg_array[0]:5;
		$this->_Template('whlabel_typeck',$this->data);
	}
	//进销存导出
	public function _whlabeckdc()
	{
		$prc = array();
		$purchase = $this->purchase->find_all();
		foreach($purchase as $k=>$v)
		{
			$prc[$v['id']] = $v['title'];
		}
		if(isset($_GET['excel']))  
		{
			$where = "sku != 'Preset'";
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
			$category = $this->input->get('category',true);
			$color = $this->input->get('color',true);
			$lowe = $this->input->get('lowe',true);
			$lacetype = $this->input->get('lacetype',true);
			$size = $this->input->get('size',true);
			$density = $this->input->get('density',true);
			$haircap = $this->input->get('haircap',true);
			$sku = $this->input->get('sku',true);
			$details = $this->input->get('details',true);
			$warehouse = 13;
			$excelid = $this->input->get('sid',true);
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($lacetype)
            {
                $where  .= " and features like '%-$lacetype-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($density)
            {
                $where  .= " and features like '%-$density-%'";
            }
			if($haircap)
            {
                $where  .= " and features like '%-$haircap-%'";
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($sku)
            {
                $where  .= " and sku like '%$sku%'";
            }
			if($details)
            {
                $where  .= " and details = '$details'";
            }
			$xzid = '';
			if($excelid)
            {
				$excelid = explode(',',trim($excelid,','));
				foreach ($excelid as $key=>$value) 
		        {
					$xzid .= " id = ".$value." or";
				}
                $xzid = " and (".rtrim($xzid,'or').")";;
            }
            //取得信息列表
			/**
           $info_list = $this->whlabel->find_all($where.$xzid,'*');
			$rows = array();$list = array();
			foreach ($info_list as $key=>$value) 
		    {
				$rows[strtolower($value['sku']).$value['features'].$value['warehouse']] = $value;//所有数据sku
		    }
			**/
			$wh = array();
			$w = $this->warehouse->find_all('1=1','id,title');
			foreach ($w as $v) 
			{
				$wh[$v['id']] = $v['title'];
			}
			$tc = array();$tcdata = array();
            $typeclass = $this->typeclass->find_all();
		    foreach ($typeclass as $v) 
		    {
				$tc[$v['id']] = $v;
			}
			$list = array();
			$rows = $this->whlabel->find_pc($where,'sku,features,warehouse','warehouse,purchase,details,cpid,sku,cpbz,cs,title,dbcontent,number,features');
			foreach ($rows as $key=>$value) 
		    {
				$bm = '03';
				$bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
				$rows[$key]['purchase'] = (isset($prc[$value['purchase']]))?$prc[$value['purchase']]:'未知';
				$classid = $this->classid->sku();
		        $pm = $classid; 
				$jm = $classid; 
				$features = explode('-',trim($value['features'],'-'));
				foreach($features as $v)
				{
					if(isset($tc[$v]) && isset($bmpx[$tc[$v]['classid']]))
					{
						if($tc[$v]['bm'] != '')
						{
						    $bmpx[$tc[$v]['classid']] = $tc[$v]['bm'];
						}
					}
					if(isset($tc[$v]))
					{
					    $zh = explode('|',trim($tc[$v]['zh'],'|'));
					    $pm[$tc[$v]['classid']] = $zh[0];
					}
					if(isset($tc[$v]))
					{
					    if(isset($jm[$tc[$v]['classid']]))
						{
						       $jm[$tc[$v]['classid']] = $tc[$v]['jm'];
							
						}
					}
				}
				$zh = implode(" ",$pm);
				$zh = str_replace('自然色 ','',rtrim($zh,' '));
				$zh = str_replace(array('        ','       ','      ','     ','    ','   ','  '),' ',$zh);
				$rows[$key]['dbcontent'] = $zh;
				$rows[$key]['cpbz'] = $bm.implode("",$bmpx);
				$jm = array_filter($jm);
				$rows[$key]['cs'] = implode("-",$jm);
				$sd = $this->whlabel->find_all($where.' and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"','details,cpid,cpbz,state');
				$details = array();
				$cpid = array();
				$cpbz = array();
				$c = 0;$g = 0;$x = 0;$t = 0;$s = 0;$q = 0;
				foreach ($sd as $k=>$v) 
		    	{
					if($v['state'] == 0)
					{
						$c++;
					}
					if($v['state'] != 9)
					{
						$g++;
					}
					if($v['state'] == 1)
					{
						$x++;
					}
					if($v['state'] == 2)
					{
						$t++;
					}
					if($v['state'] == 8)
					{
						$s++;
					}
					if($v['state'] == "3" || $v['state'] == "4" || $v['state'] == "5" || $v['state'] == "6" || $v['state'] == "7")
					{
						$q++;
					}
					$details[$v['details']] = $v['details'];
					if($v['cpid'] != 0)
					{
					    $cpid[$v['cpid']] = $v['cpid'];
					}
					if($v['cpbz'] != '')
					{
					    $cpbz[$v['cpbz']] = $v['cpbz'];
					}
				}
				$rows[$key]['details'] = implode("、",$details);
				$rows[$key]['cpid'] = ($cpid)?implode(" ",$cpid):'';
				$number = $value['number'];
				$ftime = time()-15*24*3600;
				$rows[$key]['warehouse'] = $wh[$value['warehouse']];
				$rows[$key]['number'] = $g;
				$rows[$key]['features'] = $c;
				$rows[$key]['x'] = $x;
				$rows[$key]['t'] = $t;
				$rows[$key]['s'] = $s;
				$rows[$key]['q'] = $q;
				$rows[$key]['wzsl'] = count($details);
		    }
            $title = "进销存统计表".date('Y-m-d',time()); 
            $titlename = "
            | ".$title." | 
|---|
            
			| 仓库 | 供应商 | 位置 | 库存编码 | SKU | 用友编码 | 用友料号 | 产品英文名 | 产品中文名 | 入库总量 | 库存数量 | 销售数量 | 退货数量 | 删除数量 | 其它操作 | 位置数量 | 
            
";
            $filename = $title.".xls";
			$tail = "";
            $this->excel->get_fz2($rows,$titlename,$filename,$tail);
	    }
	}
	
	public function _type()
	{
		$vip = 0;
		if(isset($_SESSION['api']))
		{
			$user = $this->user->get_api($_SESSION['api']);
			$fgshop = "";$sid = "";
		    $usersp = explode('|',trim($user['shop'],'|'));
			foreach ($usersp as $value) 
		    {
				$fgshop .= " shop = ".$value." or";
				$sid .= " id = ".$value." or";
			}
			if($user['vip'] == 1)
			{
				$vip = 1;
			}
		}
		else
		{
			header('Location: /');exit;
		}
		$prc = array();
		$purchase = $this->purchase->find_all();
		foreach($purchase as $k=>$v)
		{
			$prc[$v['id']] = $v['title'];
		}
		$company = array();
		$ct = $this->company->find_all();
		foreach($ct as $k=>$v)
		{
			$company[$v['id']] = $v['title'];
		}
		$sp = array();
		$s = $this->shop->find_all('1=1','id,shopname');
		foreach ($s as $v) 
		{
			$sp[$v['id']] = $v['shopname'];
		}
		$wh = array();
		$w = $this->warehouse->find_all('1=1','id,title');
		foreach ($w as $v) 
		{
			$wh[$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);
			$category = $this->input->post('category',true);
			$size = $this->input->post('size',true);
			$grade = $this->input->post('grade',true);
			$color = $this->input->post('color',true);
			$lowe = $this->input->post('lowe',true);
			$sku = $this->input->post('sku');
			$title = $this->input->post('title');
			$warehouse = $this->input->post('warehouse',true);
			$usa = $this->input->post('usa',true);
			$purchase = $this->input->post('purchase',true);
			$lacetype = $this->input->post('lacetype',true);
			$haircap = $this->input->post('haircap',true);
			$density = $this->input->post('density',true);
			$details = $this->input->post('details',true);
			$state = $this->input->post('state',true);
			$shop = $this->input->post('shop',true);
			$lacecolor = $this->input->post('lacecolor',true);
			$hairnumber = $this->input->post('hairnumber',true);
			$type = $this->input->post('type',true);
			$ktime = $this->input->post('ktime',true);
			$jtime = $this->input->post('jtime',true);
			$ktime = strtotime($ktime);
			$jtime = strtotime($jtime);
			$cpbz = $this->input->post('cpbz',true);
			$where = "1=1";$gj = "";$ck = "";
			
			if($usa)
            {
				if(!$warehouse)
				{
                    $where  .= " and (warehouse = '5' or warehouse = '8')";
				}
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($details)
            {
                $where  .= " and details = '$details'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($state)
            {
                $where  .= " and state = '$state'";
            }
			if($shop)
            {
                $where  .= " and shop like '%$shop%'";
            }
			
			if($type)
            {
                $where  .= " and type = '$type'";
            }
			if($ktime && $jtime)
            {
                $gj  = " and enter > '$ktime' and enter < '$jtime'";
				$ck  = " and outk > '$ktime' and outk < '$jtime'";
            }
			if($cpbz){
				$where .= " and cpbz like '%$cpbz%' ";
			}
			if($lacecolor)
            {
                $where  .= " and features like '%-$lacecolor-%'";
            }
			if($lacetype)
            {
                $where  .= " and features like '%-$lacetype-%'";
            }
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($haircap)
            {
                $where  .= " and features like '%-$haircap-%'";
            }
			if($density)
            {
                $where  .= " and features like '%-$density-%'";
            }
			if(!empty($hairnumber)){
				$where  .= " and  features like '%-128-%' ";
				if($hairnumber < 0){
					$class_list = $this->typeclass->find_all('classid = 43');
					foreach($class_list as $v){
						$where .= " and  features not like '%-".$v['id']."-%'";
					}
				}else{
					$where  .= " and features like '%-$hairnumber-%'";
				}
			}
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
			$fjnr = '';
			if($sku)
            {
				$sku = trim($sku,' ');
				$sku = trim($sku,'	');
                $fjnr  .= " and sku like '%$sku%'";
            }
			if($title)
            {
				$title = trim($title,' ');
				$title = trim($title,'	');
                $fjnr  .= " and title like '%$title%'";
            }
			$wt = array();
			$whlabel_type = $this->whlabel_type->find_all();
			foreach ($whlabel_type as $v) 
			{
				$wt[$v['id']] = $v['title'];
			}
		
			//$where  .= " and time > '$ktime' and time < '$jtime'";
			$info_list = $this->whlabel->find_pc($where.$fjnr,'sku,purchase,features,warehouse','id,warehouse,purchase,sku,title,details,shop,cpbz,type,features,number,sm',$order_str,$start,$perpage);//改这需要修改_gbhtype
			
            //取得信息列表
           
			$rows = array();$list = array();
			foreach ($info_list as $key=>$value) 
		    {
				if(isset($wt[$value['type']]))
				{
					$info_list[$key]['type'] = $wt[$value['type']];
				}
				else
				{
					$info_list[$key]['type'] = '未设置';
				}
				$info_list[$key]['purchase'] = (isset($prc[$value['purchase']]))?$prc[$value['purchase']]:'未知';
				$zt = $this->whlabeltransport->find_all('sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'" and cz = "0"');
				$ztdata = '';
				if(count($zt) > 0)
				{
					foreach ($zt as $vv) 
		            {
						$ztdata .= ''.$vv['num'].' - '.date('Y-m-d',$vv['stime']).'
';	
					}
				}
				$qbdata = $this->whlabel->find_all($where.' and sku = "'.$value['sku'].'" and purchase = "'.$value['purchase'].'" and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
				$cdata = array_filter($qbdata, function($item) {
    			return $item['state'] < 1; 
			    });
				$c = array_sum(array_column($cdata, 'jnum'));
				
				$gdata = array_filter($qbdata, function($item) use ($ktime, $jtime)  {
    			return $item['state'] < 100 && $item['enter'] > $ktime && $item['enter'] < $jtime;
			    });
				$g = array_sum(array_column($gdata, 'jnum'));
				
				$xdata = array_filter($qbdata, function($item) use ($ktime, $jtime) {
    			return $item['state'] == 1 && $item['outk'] > $ktime && $item['outk'] < $jtime;
			    });
				$x = array_sum(array_column($xdata, 'jnum'));
				
				$tdata = array_filter($qbdata, function($item) use ($ktime, $jtime) {
    			return $item['retreat'] > 0 && $item['outk'] > $ktime && $item['outk'] < $jtime;
			    });
				$t = array_sum(array_column($tdata, 'jnum'));
				
				$zdata = array_filter($qbdata, function($item) {
    			return $item['zd'] != "" && $item['state'] < 1;
			    });
				$z = array_sum(array_column($zdata, 'jnum'));
				
				$zdata = array_filter($qbdata, function($item) {
    			return $item['zd'] != "" && $item['state'] < 1;
			    });
				$z = array_sum(array_column($zdata, 'jnum'));
				
				//$c = $this->whlabel->find_all($where.' and sku = "'.$value['sku'].'" and state = 0 and purchase = "'.$value['purchase'].'" and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"','details,cpid');
				//$g = $this->whlabel->find_count($where.$gj.' and sku = "'.$value['sku'].'" and state < 100 and purchase = "'.$value['purchase'].'" and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
				//$x = $this->whlabel->find_count($where.$ck.' and sku = "'.$value['sku'].'" and state = 1 and purchase = "'.$value['purchase'].'" and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
				//$t = $this->whlabel->find_count($where.$ck.' and sku = "'.$value['sku'].'" and retreat > 0 and purchase = "'.$value['purchase'].'" and warehouse = "'.$value['warehouse'].'"');
				//$z = $this->whlabel->find_all($where.' and sku = "'.$value['sku'].'" and zd != "" and state = 0 and purchase = "'.$value['purchase'].'" and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
				$details = array();
				$cpid = array();
				$od = array();$odid = '';
				$companytitle = '';
				foreach ($qbdata as $v) 
		    	{
					if($v['zd'] != "" && $v['state'] < 1)
					{
					    if(!isset($od[$v['zd']]))
					    {
					        $od[$v['zd']] = 1;//所有数据sku
					    }
					    else
					    {
						    $od[$v['zd']] = $od[$v['zd']]+1;
					    }
					}
					if($v['state'] < 1)
					{
					    $details[$v['details']] = $v['details'];
					    if($v['cpid'] != 0)
					    {
					        $cpid[$v['cpid']] = $v['cpid'];
					    }
					}
					if($v['companytitle'] != '' &&  stripos($companytitle,$company[$v['companytitle']]) === false)
					{
						$companytitle .= ''.$company[$v['companytitle']].'
';
					}
		    	}
				foreach ($od as $k=>$vv) 
		    	{
					$odid .= $k.'数量'.$vv;
		    	}
				$info_list[$key]['cpbz'] = ''.$value['cpbz'].'
'.$value['sm'].'
';
				$number = $value['number'];$ftime = time()-15*24*3600;
				$z = $z.'('.$odid.')';//查看订单号
				$info_list[$key]['warehouse'] = isset($wh[$value['warehouse']])?$wh[$value['warehouse']]:'无';
				$info_list[$key]['features'] = $c;
				$info_list[$key]['number'] = $ztdata;
				$info_list[$key]['sm'] = $g;
				$info_list[$key]['x'] = $x;
				$info_list[$key]['t'] = $t;
				$info_list[$key]['z'] = $z;		
				/**
				foreach ($cdata as $k=>$v) 
		    	{
					$details[$v['details']] = $v['details'];
					if($v['cpid'] != 0)
					{
					    $cpid[$v['cpid']] = $v['cpid'];
					}
				}
				**/
				$info_list[$key]['shop'] = '';
				$info_list[$key]['details'] = ($cpid)?implode(" ",$details).''.implode(" ",$cpid).'
':implode(" ",$details);
				if($value['shop'] != '')
				{
				    $shop = explode(',',trim($value['shop'],','));
				    $info_list[$key]['shop'] = ''.$sp[$shop[0]].'
';
				}
				 $info_list[$key]['shop'] .= $companytitle;
				/**
				$companytitle = $this->whlabel->find_pc($where.$fjnr,'companytitle','companytitle');
				if(isset($companytitle[0]))
				{
					foreach ($companytitle as $k=>$v) 
		    	    {
						if($v['companytitle'] != '')
						{
							$info_list[$key]['shop'] .= ''.$company[$v['companytitle']].'
';
						}
				    }
				}
				**/
		    }
		    $total = count($this->whlabel->find_pc($where.$fjnr,'sku,purchase,features,warehouse','id,warehouse,sku,title,features,number'));
		    $pagenum = ceil($total/$perpage);
		    $over = $total-($start+$perpage);
		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
		    echo json_encode($rows);exit;
		}
		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
		$this->data['shop'] = $wlshop;
		$this->data['vip'] = $vip;
		$this->_Template('whlabel_type',$this->data);
	}
	
	//美仓进销存浏览
	public function _usatype()
	{
		if(isset($_SESSION['api']))
		{
			$user = $this->user->get_api($_SESSION['api']);
			$usp = $user;
		    $fgshop = "";$sid = "";$wid="";$wtype="";
			$userwh = explode('|',trim($user['warehouse'],'|'));
			foreach ($userwh as $value) 
		    {
				$wid .= " id = ".$value." or";
				$wtype .= " type = ".$value." or";
			}
		}
		$prc = array();
		$purchase = $this->purchase->find_all();
		foreach($purchase as $k=>$v)
		{
			$prc[$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);
			$category = $this->input->post('category',true);
			$size = $this->input->post('size',true);
			$grade = $this->input->post('grade',true);
			$color = $this->input->post('color',true);
			$lowe = $this->input->post('lowe',true);
			$sku = $this->input->post('sku');
			$title = $this->input->post('title');
			$warehouse = $this->input->post('warehouse',true);
			$usa = $this->input->post('usa',true);
			$purchase = $this->input->post('purchase',true);
			$lacetype = $this->input->post('lacetype',true);
			$haircap = $this->input->post('haircap',true);
			$density = $this->input->post('density',true);
			$details = $this->input->post('details',true);
			$state = $this->input->post('state',true);
			$lacecolor = $this->input->post('lacecolor',true);
			$cklx = $this->input->post('cklx',true);
			$ktime = $this->input->post('ktime',true);
			$jtime = $this->input->post('jtime',true);
			$ktime = strtotime($ktime);
			$jtime = strtotime($jtime);
			$where = "1=1";$gj = "";$ck = "";
			if($lacetype)
            {
                $where  .= " and features like '%-$lacetype-%'";
            }
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($haircap)
            {
                $where  .= " and features like '%-$haircap-%'";
            }
			if($density)
            {
                $where  .= " and features like '%-$density-%'";
            }
			if($lacecolor)
            {
                $where  .= " and features like '%-$lacecolor-%'";
            }
			if($usa)
            {
				if(!$warehouse)
				{
                    $where  .= " and (warehouse = '5' or warehouse = '8')";
				}
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($details)
            {
                $where  .= " and details = '$details'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($state)
            {
                $where  .= " and state = '$state'";
            }
			$where_add = '';
			if($cklx)
            {
				$shop = $this->shop->read($cklx);
                $where_add  .= " and zd like '".$shop['shortname']."%' and state = 0";
            }
			if($ktime && $jtime)
            {
                $gj  = " and enter > '$ktime' and enter < '$jtime'";
				$ck  = " and outk > '$ktime' and outk < '$jtime'";
            }
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
			if($sku)
            {
				$sku = trim($sku,' ');
				$sku = trim($sku,'	');
                $where  .= " and sku like '%$sku%'";
				$info_list = $this->whlabel->find_pc($where.$where_add,'sku,features,warehouse','id,sku,title,features,warehouse',$order_str,$start,$perpage);
            }
			else if($title)
            {
				$title = trim($title,' ');
				$title = trim($title,'	');
                $where  .= " and title like '%$title%'";
				$info_list = $this->whlabel->find_pc($where.$where_add,'sku,features,warehouse','id,sku,title,features,warehouse',$order_str,$start,$perpage);
            }
			else
			{
				//$where  .= " and time > '$ktime' and time < '$jtime'";
				$info_list = $this->whlabel->find_pc($where.$where_add,'sku,features,warehouse','id,sku,title,features,warehouse',$order_str,$start,$perpage);
			}
            //取得信息列表
           
			$rows = array();$list = array();
			foreach ($info_list as $key=>$value) 
		    {
				$warehouse = $this->warehouse->read($value['warehouse']);
				$c = $this->whlabel->find_count($where.' and sku = "'.$value['sku'].'" and state = 0 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
				$g = $this->whlabel->find_count($where.$gj.' and sku = "'.$value['sku'].'" and state < 100 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
				$x = $this->whlabel->find_count($where.$ck.' and sku = "'.$value['sku'].'" and state = 1 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
				$t = $this->whlabel->find_count($where.$ck.' and sku = "'.$value['sku'].'" and retreat > 0 and warehouse = "'.$value['warehouse'].'"');
				$z = $this->whlabel->find_all($where.' and sku = "'.$value['sku'].'" and zd != "" and state = 0 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
				$od = array();$odid = '';
				foreach ($z as $v) 
		    	{
					if(!isset($od[$v['zd']]))
					{
					    $od[$v['zd']] = 1;//所有数据sku
					}
					else
					{
						$od[$v['zd']] = $od[$v['zd']]+1;
					}
		    	}
				foreach ($od as $k=>$vv) 
		    	{
					$odid .= $k.'数量'.$vv.' ';
		    	}
				$z = count($z).'('.$odid.')';//查看订单号
				$info_list[$key]['features'] = $c;
				$zt = $this->whlabeltransport->find_all('sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'" and cz = "0"');
				$ztdata = '';
				if(count($zt) > 0)
				{
					foreach ($zt as $vv) 
		            {
						$ztdata .= ''.$vv['num'].' - '.date('Y-m-d',$vv['stime']).'
';	
					}
				}
				$info_list[$key]['warehouse'] = $ztdata;
				$info_list[$key]['g'] = $g;
				$info_list[$key]['x'] = $x;
				$info_list[$key]['t'] = $t;
				$info_list[$key]['z'] = $z;
		    }
			$total = count($this->whlabel->find_pc($where.$where_add,'sku,features,warehouse','id,warehouse,sku,title'));
		    $pagenum = ceil($total/$perpage);
		    $over = $total-($start+$perpage);
		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'CS'=>$warehouse);
		    echo json_encode($rows);exit;
		}
		$warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");
		$this->data['warehouse'] = $warehouse;
		$this->_Template('whlabel_typeusa',$this->data);
	}
	//美仓进销存浏览
	public function _usatypeapp()
	{
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$sku = $this->input->post('sku',true);
			$warehouse = 5;
			$title = $this->input->post('title',true);
			$state = $this->input->post('state',true);
			
			$ktime = $this->input->post('ktime',true);
			$jtime = $this->input->post('jtime',true);
			$ktime = strtotime($ktime);
			$jtime = strtotime($jtime);
			$where = "1=1";$gj = "";$ck = "";
			if($title)
            {
				$st = explode(' ',trim($title,' '));
				foreach ($st as $v)
		        {
                    $where  .= " and title like '%$v%'";
				}
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($state)
            {
                $where  .= " and state = '$state'";
            }
			if($sku)
            {
                $where  .= " and sku like '%$sku%'";
            }
			if($ktime && $jtime)
            {
                $gj  = " and enter > '$ktime' and enter < '$jtime'";
				$ck  = " and outk > '$ktime' and outk < '$jtime'";
            }
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            $info_list = $this->whlabel->find_all($where.' and '.rtrim($wid,'or'),'*');
			$rows = array();$list = array();
			foreach ($info_list as $key=>$value) 
		    {
				$rows[strtolower($value['sku']).'warehouse'.$value['warehouse']] = $value;//所有数据sku
		    }
			$rowsdq = array_slice($rows,$start,$perpage);
			foreach ($rowsdq as $value) 
		    {
				$warehouse = $this->warehouse->read($value['warehouse']);
				$c = $this->whlabel->find_count($where.' and sku = "'.$value['sku'].'" and state = 0 and warehouse = "'.$value['warehouse'].'"');
				$x = $this->whlabel->find_count($where.' and sku = "'.$value['sku'].'" and state = 1 and warehouse = "'.$value['warehouse'].'"');
				$t = $this->whlabel->find_count($where.' and sku = "'.$value['sku'].'" and retreat > 0 and warehouse = "'.$value['warehouse'].'"');
				$od = array();$odid = '';
				$list[] = array('id'=>$value['id'],'sku'=>$value['sku'],'title'=>$value['title'],'c'=>$c,'x'=>$x,'t'=>$t);
		    }
		    $total = count($rows);
		    $pagenum = ceil($total/$perpage);
		    $over = $total-($start+$perpage);
		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
		    echo json_encode($rows);exit;
		}
		$this->_Template('phone/p_usatypeapp',$this->data);
	}
	//入库操作
	public function _enteradd()
	{
		$dt = 0;
		if(isset($_SESSION['api']))
		{
			$user = $this->user->get_api($_SESSION['api']);
			$usp = $user;
		    $fgshop = "";$sid = "";
		    $user = explode('|',trim($user['shop'],'|'));
			foreach ($user as $value) 
		    {
				$fgshop .= " shop = ".$value." or";
				$sid .= " id = ".$value." or";
			}
		}
		$tc = $this->typeclass->find_all();
		$typeclass = array();
		foreach ($tc as $v)
		{
			$tcjm[$v['id']] = array($v['jm'],$v['classid']);
			$typeclass[$v['id']] = array('zh'=>$v['zh'],'classid'=>$v['classid'],'bm'=>$v['bm'],'title'=>$v['title'],'bqsku'=>$v['bqsku']);
		}
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['sku']))
		{
			$list = array();$num = "";$title = "";$features = "";
			$order = $this->input->post('order',true);
			$shop = $this->input->post('shop',true);
			$post['shop'] = ($shop!="")?','.$shop:"";
			$sku = $this->input->post('sku',true);
			$post['sm'] = $this->input->post('sm',true);
			$post['warehouse'] = $this->input->post('warehouse',true);
			$post['purchase'] = $this->input->post('purchase',true);
			$post['retreatwarehouse'] = $post['warehouse'];
			$post['state'] = $this->input->post('state',true);
			$post['rktype'] = $this->input->post('rktype',true);
			$post['text'] = $this->input->post('text',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(!$post['purchase'])
			{
				$post['purchase'] = 1;
			}
			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);
				$list['weight'] = $this->input->post('weight',true);
			}
			if($category == 1702)
			{
				$list['syhairther'] = $this->input->post('syhairther',true);
			}
			$classid = $this->classid->sku();
			$scsku = $classid;
			$pm = $classid;
			foreach($list as $k=>$v)
			{
				if($v != 0)
				{
					$num .=$v;
					$features .=$v.'-';
					$post[$k] = $v;
					$scsku[$typeclass[$v]['classid']] = $typeclass[$v]['bqsku'];
					if($k != 'size')
					{
			            $title .= $typeclass[$v]['title']." ";
					}
					if(isset($pm[$typeclass[$v]['classid']]))
					{
						if($typeclass[$v]['title'] == '9A')
						{
							$pm[$typeclass[$v]['classid']] = '9A';
						}
						else if($typeclass[$v]['title'] == '10A')
						{
							$pm[$typeclass[$v]['classid']] = '10A';
						}
						else
						{
							$clzh = $typeclass[$v]['zh'];
							if(stripos($typeclass[$v]['zh'],'|') !== false)
							{
								$clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
								$clzh = $clzh[0];
							}
							$pm[$typeclass[$v]['classid']] = $clzh;
						}
					}
				}
            }
			$zh = implode(" ",$pm);
			$zh = str_replace(array('        ','       ','      ','     ','    ','   ','  '),' ',$zh);
			$zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
			if($list['size'])
			{
			    $typeclass = $this->typeclass->read($list['size']);
			    $title .= $typeclass['title'];
			}
			$time = time();
			if($xzsku)
			{
				$scsku = implode("-",$scsku);
				$scsku = str_replace('- ','-',trim($scsku,'-'));
				$scsku = str_replace(array('--------','-------','------','-----','----','---','--'),'-',$scsku);
				$post['sku'] = trim($scsku,' ');
			}
			else
			{
				$post['sku'] = $sku;
			}
			//$post['sku'] = trim($sku,' ');
			$post['title'] = rtrim($title,' ');
			$post['number'] = $num;
			$post['features'] = '-'.$features;
			$post['enter'] = $time;
			$post['time'] = $time;//操作时间
			$yza = $this->whlabel->find_all("sku =  '".$post['sku']."' and warehouse = '".$post['warehouse']."' and shop = '".$post['shop']."'");
				if($yza)
				{
					if($post['features'] != $yza[0]['features'])
					{
						echo json_encode(array('msg'=>'此SKU的产品信息和现有不一致!','new'=>$post['features'].'-'.$post['sku'],'old'=>$yza[0]['features'],'success'=>false));exit;
					}
				}
				$yzb = $this->whlabel->find_all("features =  '".$post['features']."' and warehouse = '".$post['warehouse']."' and shop = '".$post['shop']."'");
				if($yzb)
				{
					if($post['sku'] != $yzb[0]['sku'])
					{
						echo json_encode(array('msg'=>'此产品信息的SKU和现有'.$yzb[0]['sku'].'不一致!','success'=>false));exit;
					}
				}
			if(isset($yza[0]) && $post['warehouse'] == 5 && $yza[0]['shop'] != $post['shop'])
			{
				echo json_encode(array('msg'=>'此产品店铺信息和现有不一致!','success'=>false));exit;
			}
			if($post['rktype'] != 1 && $post['text'] == '' && $post['warehouse'] == 5)
			{
				echo json_encode(array('msg'=>'非采购入库必须填写入库分类备注!','success'=>false));exit;
			}
			if($post['rktype'] == '' && $post['warehouse'] == 5)
			{
				echo json_encode(array('msg'=>'美仓必须填写入库分类!','success'=>false));exit;
			}
			$yz = $this->whlabel->find_all("sku =  '".$post['sku']."' and features =  '".$post['features']."' and warehouse = '".$post['warehouse']."' and shop = '".$post['shop']."'",'type');
			if(isset($yz[0]['type']))
			{
				$post['type'] = $yz[0]['type'];
			}
			if($post['state'] == 9)//如果选择预设库存
			{
				$this->whlabel->insert($post);
			}
			else
			{
				/**
				$ljg = $this->ljg->get_enteradd(array('sku'=>$post['sku'],'title'=>$post['title'],'number'=>$order));
				if($ljg == 1)
				{
				    for($i=0;$i<$order;$i++)
			        {
				        $post['label'] = time().rand(100,999).$i;//产品标签 辨别各个产品,暂不使用
				        $this->whlabel->insert($post);
			        }
				}
				**/
			//if($post['warehouse'] == '5')
			//{
				
			//}
			$yydata = $post;
			$yydata['zh'] = $zh;
			/**
			$wl = $this->apiyy->get_cjlp($yydata);
			if(!isset($wl['Data'][0]['m_isSucess']) || $wl['Data'][0]['m_isSucess'] != 1)
			{
				echo json_encode(array('msg'=>'用友ERP写入失败,请重试','success'=>false));exit;
			}
			if($wl['Data'][0]['m_isSucess'] != 1)
			{
				echo json_encode(array('msg'=>$wl['Data'][0]['m_errorMsg'],'success'=>false));exit;
			}
			**/
				for($i=0;$i<$order;$i++)
			    {
					$post['label'] = time().rand(100,999).$i;//产品标签 辨别各个产品,暂不使用
				    $this->whlabel->insert($post);
			    }
			}
			echo json_encode(array('msg'=>'入库成功','success'=>true));exit;
		}
		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
		$this->data['wlshop'] = $wlshop;
		$this->_Template('whlabel_enteradd',$this->data);
	}
	//修改产品
	public function _enteredit($arg_array)
	{
		$dt = 0;
		if(isset($_SESSION['api']))
		{
			$user = $this->user->get_api($_SESSION['api']);
			$usp = $user;
		    $fgshop = "";$sid = "";
		    $user = explode('|',trim($user['shop'],'|'));
			foreach ($user as $value) 
		    {
				$fgshop .= " shop = ".$value." or";
				$sid .= " id = ".$value." or";
			}
		}
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['sku']))
		{
			$list = array();$num = "";$title = "";$features = "";
			$id = $this->input->post('id',true);
			$order = $this->input->post('order',true);
			$shop = $this->input->post('shop',true);
			$post['shop'] = ($shop!="")?','.$shop:"";
			$post['sku'] = $this->input->post('sku',true);
			$post['sm'] = $this->input->post('sm',true);
			$post['warehouse'] = $this->input->post('warehouse',true);
			$post['purchase'] = $this->input->post('purchase',true);
			$post['retreatwarehouse'] = $post['warehouse'];
			$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);
			$list['size'] = rtrim($size,',');
			$post['rktype'] = $this->input->post('rktype',true);
			$post['text'] = $this->input->post('text',true);
			$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(!$post['purchase'])
			{
				$post['purchase'] = 1;
			}
			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);
				$list['weight'] = $this->input->post('weight',true);
			}
			if($category == 1702)
			{
				$list['syhairther'] = $this->input->post('syhairther',true);
			}
			foreach($list as $k=>$v)
			{
				if($v != 0)
				{
					$num .=$v;
					$features .=$v.'-';
					$typeclass = $this->typeclass->read($v);
			       if($k != 'size')
					{
			            $title .= $typeclass['title']." ";
					}
				}
            }
			$typeclass = $this->typeclass->read($list['size']);
			$title .= $typeclass['title'];
			$time = time();
			$post['title'] = rtrim($title,' ');
			$post['number'] = $num;
			$post['features'] = '-'.$features;
			$post['time'] = $time;//操作时间
			if($post['rktype'] == '' && $post['warehouse'] == 5)
			{
				echo json_encode(array('msg'=>'美仓必须填写入库分类!','success'=>false));exit;
			}
			if($post['rktype'] != 1 && $post['text'] == '' && $post['warehouse'] == 5)
			{
				echo json_encode(array('msg'=>'非采购入库必须填写入库分类备注!','success'=>false));exit;
			}
			$uid = $this->whlabel->read($id);
			$datanum = $this->whlabel->find_count("state = 0 and sku =  '".$uid['sku']."' and warehouse = '".$uid['warehouse']."' and zd != ''");
			if($datanum > 0)
			{
				echo json_encode(array('msg'=>'此SKU有占单,请解除占单后再修改!','success'=>false));exit;
			}
			if($post['warehouse'] != '99999')//现在所有仓都检测,之前只有美仓5检测
			{
				$yza = $this->whlabel->find_all("sku =  '".$post['sku']."' and warehouse = '".$post['warehouse']."'");
				if($yza)
				{
					if($post['features'] != $yza[0]['features'])
					{
						echo json_encode(array('msg'=>'此SKU的产品信息和现有不一致!','success'=>false));exit;
					}
				}
				$yzb = $this->whlabel->find_all("features =  '".$post['features']."' and warehouse = '".$post['warehouse']."'");
				if($yzb)
				{
					if($post['sku'] != $yzb[0]['sku'])
					{
						echo json_encode(array('msg'=>'此产品信息的SKU和现有不一致!','success'=>false));exit;
					}
				}
				if($post['warehouse'] == 5 && $yza[0]['shop'] != $post['shop'])
				{
					echo json_encode(array('msg'=>'此产品店铺信息和现有不一致!','success'=>false));exit;
				}
				$data = $this->whlabel->find_all("sku =  '".$uid['sku']."' and warehouse = '".$uid['warehouse']."'");// and enter = '".$uid['enter']."'
				foreach ($data as $v)
		    	{
					$post['id'] = $v['id'];
			    	$this->whlabel->save($post,$v['id']);
				}
			}
			else
			{
				$data = $this->whlabel->find_count("state = 0 and sku =  '".$uid['sku']."' and warehouse = '".$uid['warehouse']."' and zd != ''");
				if($data > 0)
				{
					echo json_encode(array('msg'=>'此产品有占单,无法修改!','success'=>false));exit;
				}
				else
				{
					$data = $this->whlabel->find_all("sku =  '".$uid['sku']."' and warehouse = '".$uid['warehouse']."'");// and enter = '".$uid['enter']."'
				    foreach ($data as $v)
		    	    {
					    $post['id'] = $v['id'];
			    	    $this->whlabel->save($post,$v['id']);
				    }
				}
			}
			echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
		}
		$uid = $this->whlabel->read($arg_array[0]);
		$uid['order'] = $this->whlabel->find_count('enter = "'.$uid['enter'].'" and sku = "'.$uid['sku'].'" and state = "0"');
		$this->data['enter'] = $uid ;
		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
		$this->data['wlshop'] = $wlshop;
		$this->_Template('whlabel_enteredit',$this->data);
	}
	//入库浏览
	public function _enter()
	{
		$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)
		    {
				$sid = $this->whlabel->read($v);
				$count = $this->whlabel->find_count("state = 0 and sku =  '".$sid['sku']."' and warehouse = '".$sid['warehouse']."' and zd != ''");
				if($count > 0)
				{
					echo json_encode(array('msg'=>'有占单,需要先解除占单!','success'=>true));exit;
				}
				$info_list = $this->whlabel->find_all('enter ='.$sid['enter']);
				foreach ($info_list as $va)
		        {
					$this->whlabel->remove($va['id']);
				}
            }
            echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));exit;
		}
		$sp = array();
		$s = $this->shop->find_all('1=1','id,shopname');
		foreach ($s as $v) 
		{
			$sp[$v['id']] = $v['shopname'];
		}
		$wh = array();
		$w = $this->warehouse->find_all('1=1','id,title');
		foreach ($w as $v) 
		{
			$wh[$v['id']] = $v['title'];
		}
		if(isset($post['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$category = $this->input->post('category',true);
			$size = $this->input->post('size',true);
			$grade = $this->input->post('grade',true);
			$color = $this->input->post('color',true);
			$lowe = $this->input->post('lowe',true);
			$sku = $this->input->post('sku',true);
			$warehouse = $this->input->post('warehouse',true);
			$purchase = $this->input->post('purchase',true);
			$ktime = $this->input->post('ktime',true);
			$jtime = $this->input->post('jtime',true);
			$ktime = strtotime($ktime);
			$jtime = strtotime($jtime);
			$where = "1=1";$gj = "";$ck = "";
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($sku)
            {
                $where  .= " and sku like '%$sku%'";
            }
			if($ktime && $jtime)
            {
                $where .= " and enter > '$ktime' and enter < '$jtime'";
            }
            //数据排序
            $order_str = "enter desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            $info_list = $this->whlabel->find_pc($where,'enter,warehouse,sku','id,warehouse,shop,sku,title,enter',$order_str,$start,$perpage);
			foreach ($info_list as $k=>$v) 
		    {
				$info_list[$k]['warehouse'] = $wh[$v['warehouse']];
				if($v['shop']=='')
				{
					$s = '通用';
				}
				else
				{
					$info_list[$k]['shop'] = '';
					foreach (explode(',',trim($v['shop'],',')) as $val) 
		            {
						$info_list[$k]['shop'] .= $sp[$val].'';
					}
				}
				$info_list[$k]['enter'] = date('Y-m-d H:i:s',$v['enter']);
				$g = $this->whlabel->find_count($where.' and enter = "'.$v['enter'].'" and sku = "'.$v['sku'].'" and warehouse = "'.$v['warehouse'].'"');
				$info_list[$k]['g'] = $g;
		    }
		    $total = count($this->whlabel->find_pc($where,'sku,features,warehouse','id,warehouse,sku,title,features,number'));
		    $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('whlabel_enter',$this->data);
	}
	//出库浏览
	public function _out()
	{
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$category = $this->input->post('category',true);
			$size = $this->input->post('size',true);
			$grade = $this->input->post('grade',true);
			$color = $this->input->post('color',true);
			$lowe = $this->input->post('lowe',true);
			$sku = $this->input->post('sku',true);
			$warehouse = $this->input->post('warehouse',true);
			$purchase = $this->input->post('purchase',true);
			$state = $this->input->post('state',true);
			$ktime = $this->input->post('ktime',true);
			$jtime = $this->input->post('jtime',true);
			$ktime = strtotime($ktime);
			$jtime = strtotime($jtime);
			$where = "state=3";$gj = "";$ck = "";
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($state)
            {
                $where  .= " and state = '$state'";
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($sku)
            {
                $where  .= " and sku = '$sku'";
            }
			if($ktime && $jtime)
            {
                $where  .= " and outk > '$ktime' and outk < '$jtime'";
            }
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            $info_list = $this->whlabel->find_all($where,'sku');
			$rows = array();$list = array();
			foreach ($info_list as $key=>$value) 
		    {
				$rows[] = $value['sku'].'warehouse'.$value['warehouse'];//所有数据sku
		    }
			$rows = array_unique($rows);//删除重复记录
			foreach ($rows as $key=>$value) 
		    {
				$data = $this->whlabel->get_sku($value);//获取目前sku的所有数据
				$ck = $this->warehouse->read($data['warehouse']);
				$warehouse = $ck['title'];
				$gy = $this->purchase->read($data['purchase']);
				$purchase = $gy['purchase'];
				$g = $this->whlabel->find_count($where.' and sku = "'.$value.'" and state = 3');
				$list[] = array('id'=>$data['id'],'warehouse'=>$warehouse,'purchase'=>$purchase,'sku'=>$data['sku'],'title'=>$data['title'],'time'=>date('Y-m-d H:i:s',$data['enter']),'number'=>$g);
		    }
		    $total = count($list);
		    $pagenum = ceil($total/$perpage);
		    $over = $total-($start+$perpage);
			$list = array_slice($list,$start,$perpage);//数组中提取分页指定的内容 +true key排序不变
		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
		    echo json_encode($rows);exit;
		}
		$this->_Template('whlabel_out',$this->data);
	}
	
	//出库标签浏览
	public function _label()
	{
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$sku = $this->input->post('sku',true);
			$warehouse = $this->input->post('warehouse',true);
			$purchase = $this->input->post('purchase',true);
			$orderinfo = $this->input->post('orderinfo',true);
			$waybill = $this->input->post('waybill',true);
			$category = $this->input->post('category',true);
			$size = $this->input->post('size',true);
			$grade = $this->input->post('grade',true);
			$color = $this->input->post('color',true);
			$lowe = $this->input->post('lowe',true);
			
			$where = "state=1";
			if($sku)
            {
                $where  .= " and sku = '$sku'";
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($orderinfo)
            {
                $where  .= " and orderinfo = '$orderinfo'";
            }
			if($waybill)
            {
                $where  .= " and waybill = '$waybill'";
            }
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
            //数据排序
            $order_str = "outk desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            $info_list = $this->whlabel->find_all($where,'id,warehouse,sku,title,label,purchase,orderinfo,waybill,outk',$order_str,$start,$perpage);
			foreach ($info_list as $key=>$value) 
		    {
				$warehouse = $this->warehouse->read($value['warehouse']);
				$info_list[$key]['warehouse'] = $warehouse['title'];
				$purchase = $this->purchase->read($value['purchase']);
				$info_list[$key]['purchase'] = $purchase['title'];
				if($value['outk'] != 0)
				{
					$info_list[$key]['outk'] = date('Y-m-d H:i:s',$value['outk']);
				}
				else
				{
					$info_list[$key]['outk'] = "";
				}
				if($value['orderinfo'] == 0)
				{
					$info_list[$key]['orderinfo'] = "";
				}
				if($value['waybill'] == 0)
				{
					$info_list[$key]['waybill'] = "";
				}
		    }
		    $total = $this->whlabel->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('whlabel_label',$this->data);
	}
	//独立站出库订单
	public function _outorder()
	{
		if(isset($_SESSION['api']))
		{
			$user = $this->user->get_api($_SESSION['api']);
			$usp = $user;
		    $fgshop = "";$sid = "";
		    $user = explode('|',trim($user['shop'],'|'));
			foreach ($user as $value) 
		    {
				$fgshop .= " shop = ".$value." or";
				$sid .= " id = ".$value." or";
			}
		}
		else
		{
			echo "请重新登录";
		}
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$warehouse = $this->input->post('warehouse',true);
			$xztime = $this->input->post('xztime',true);
			$timetk = $this->input->post('timetkk',true);
			$timetj = $this->input->post('timetjj',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);
			$sfxh = $this->input->post('sfxh',true);
			$express = $this->input->post('express',true);
			$waybill = $this->input->post('waybill',true);
			$library = $this->input->post('library',true);
			$country = $this->input->post('country',true);
			$so = $this->input->post('so',true);
			$libraryconfirm = $this->input->post('libraryconfirm',true);
			$print = $this->input->post('print',true);
			$state = $this->input->post('state',true);
			$orderurl = $this->input->post('orderurl',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			/**
			$sj = $this->input->post('sj',true);
			if($sj)
			{
				$sj = $this->input->post('sj',true);
			}
			else
			{
				$sj = "fullorder";
			}
			**/
			$sj = "fullorder";
			$where = "1=1";
			if($warehouse)
            {
                $where  .= " and type = '$warehouse'";
            }
			if($timetk && $timetj)
            {
                $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
            }
			if($orderinfo)
            {
                $where  .= " and orderinfo = '$orderinfo'";
            }
			if($number)
            {
                $where  .= " and number = '$number'";
            }
			if($express)
            {
                $where  .= " and express = '$express'";
            }
			if($waybill)
            {
                $where  .= " and waybill = '$waybill'";
            }
			if($library)
            {
                $where  .= " and library = '$library'";
            }
			if($print)
            {
                $where  .= " and print = '$print'";
            }
			if($libraryconfirm)
            {
                $where .= " and libraryconfirm = '$libraryconfirm'";
            }
			if($state)
            {
                $where .= " and state = '$state'";
            }
			if($shop)
            {
                $where .= " and shop = '$shop'";
            }
			if($country)
            {
                $where .= " and country = '$country'";
            }
			if($sfxh != '')
            {
                $where .= " and sfxh = '$sfxh'";
            }
			if($so)
            {
                $where  .= " and shipremarks like '%$so%'";
            }
			if($source)
            {
				if($source == '2d')
				{
					$where  .= " and source >= '2'";
				}
				else
				{
                    $where  .= " and source = '$source'";
				}
            }
			if(isset($_SESSION['api']))
		        {
			        foreach ($user as $value) 
		            {
			        	$fgshop .= " shop = ".$value." or";
			        }
					$where .= " and (".rtrim($fgshop,'or').")";
		        }
			if($orderurl)
            {
				$url = $this->orderurl->read($orderurl);
                $where  .= " and link like '%".$url['url']."%'";
            }
            //数据排序
            $order_str = "librarytime desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            $info_list = $this->$sj->find_all($where,'id,shop,type,orderinfo,number,waybill,express,librarytime',$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']);
				$info_list[$key]['express'] = $express['servicename'];
				$warehouse = $this->warehouse->read($value['type']);
				$info_list[$key]['type'] = $warehouse['title'];
				if($value['librarytime'] == '0')
				{
					$info_list[$key]['librarytime'] = '';
				}
				else
				{
					$info_list[$key]['librarytime'] = ''.date('Y-m-d H:i:s',$value['librarytime']).'';
				}
            }
		    $total = $this->$sj->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->data['express'] = $this->express->find_all();
		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
		$this->data['wlshop'] = $wlshop;
		$user = $this->user->get_api($_SESSION['api']);
		$powerid = $this->power->read($user['power']);
		$powertext = explode('|',trim($powerid['excelid'],'|'));
		$pid = '';
		foreach ($powertext as $v) 
		{
			$pid .= " id = ".$v." or";
		}
		$fullorderexcel = $this->fullorderexcel->find_all("type = '100002' and (".rtrim($pid,'or').")",'*','idorder desc');//导出模板
		$this->data['fullorderexcel'] = $fullorderexcel;
		$orderurl = $this->orderurl->find_all(rtrim($fgshop,'or'));
		$this->data['orderurl'] = $orderurl;
		$this->_Template('whlabel_outorder',$this->data);
	}
	
	//tt出库
	public function _toutorder()
	{
		if(isset($_SESSION['api']))
		{
			$user = $this->user->get_api($_SESSION['api']);
			$usp = $user;
		    $fgshop = "";$sid = "";
		    $user = explode('|',trim($user['shop'],'|'));
			foreach ($user as $value) 
		    {
				$fgshop .= " shop = ".$value." or";
				$sid .= " id = ".$value." or";
			}
		}
		else
		{
			echo "请重新登录";
		}
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$warehouse = $this->input->post('warehouse',true);
			$xztime = $this->input->post('xztime',true);
			$timetk = $this->input->post('timetkk',true);
			$timetj = $this->input->post('timetjj',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);
			$sfxh = $this->input->post('sfxh',true);
			$express = $this->input->post('express',true);
			$waybill = $this->input->post('waybill',true);
			$library = $this->input->post('library',true);
			$country = $this->input->post('country',true);
			$so = $this->input->post('so',true);
			$libraryconfirm = $this->input->post('libraryconfirm',true);
			$print = $this->input->post('print',true);
			$state = $this->input->post('state',true);
			$orderurl = $this->input->post('orderurl',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			/**
			$sj = $this->input->post('sj',true);
			if($sj)
			{
				$sj = $this->input->post('sj',true);
			}
			else
			{
				$sj = "fullorder";
			}
			**/
			$sj = "fullordertt";
			$where = "1=1";
			if($warehouse)
            {
                $where  .= " and type = '$warehouse'";
            }
			if($timetk && $timetj)
            {
                $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
            }
			if($orderinfo)
            {
                $where  .= " and orderinfo = '$orderinfo'";
            }
			if($number)
            {
                $where  .= " and number = '$number'";
            }
			if($express)
            {
                $where  .= " and express = '$express'";
            }
			if($waybill)
            {
                $where  .= " and waybill = '$waybill'";
            }
			if($library)
            {
                $where  .= " and library = '$library'";
            }
			if($print)
            {
                $where  .= " and print = '$print'";
            }
			if($libraryconfirm)
            {
                $where .= " and libraryconfirm = '$libraryconfirm'";
            }
			if($state)
            {
                $where .= " and state = '$state'";
            }
			if($shop)
            {
                $where .= " and shop = '$shop'";
            }
			if($country)
            {
                $where .= " and country = '$country'";
            }
			if($sfxh != '')
            {
                $where .= " and sfxh = '$sfxh'";
            }
			if($so)
            {
                $where  .= " and shipremarks like '%$so%'";
            }
			if($source)
            {
				if($source == '2d')
				{
					$where  .= " and source >= '2'";
				}
				else
				{
                    $where  .= " and source = '$source'";
				}
            }
			if(isset($_SESSION['api']))
		        {
			        foreach ($user as $value) 
		            {
			        	$fgshop .= " shop = ".$value." or";
			        }
					$where .= " and (".rtrim($fgshop,'or').")";
		        }
			if($orderurl)
            {
				$url = $this->orderurl->read($orderurl);
                $where  .= " and link like '%".$url['url']."%'";
            }
            //数据排序
            $order_str = "librarytime desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            $info_list = $this->$sj->find_all($where,'id,shop,type,orderinfo,number,waybill,express,librarytime',$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']);
				$info_list[$key]['express'] = $express['servicename'];
				$warehouse = $this->warehouse->read($value['type']);
				$info_list[$key]['type'] = $warehouse['title'];
				if($value['librarytime'] == '0')
				{
					$info_list[$key]['librarytime'] = '';
				}
				else
				{
					$info_list[$key]['librarytime'] = ''.date('Y-m-d H:i:s',$value['librarytime']).'';
				}
            }
		    $total = $this->$sj->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->data['express'] = $this->express->find_all();
		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
		$this->data['wlshop'] = $wlshop;
		$user = $this->user->get_api($_SESSION['api']);
		$powerid = $this->power->read($user['power']);
		$powertext = explode('|',trim($powerid['excelid'],'|'));
		$pid = '';
		foreach ($powertext as $v) 
		{
			$pid .= " id = ".$v." or";
		}
		$fullorderexcel = $this->fullorderexcel->find_all("type = '100007' and (".rtrim($pid,'or').")",'*','idorder desc');//导出模板
		$this->data['fullorderexcel'] = $fullorderexcel;
		$orderurl = $this->orderurl->find_all(rtrim($fgshop,'or'));
		$this->data['orderurl'] = $orderurl;
		$this->_Template('whlabel_toutorder',$this->data);
	}
	
	//速卖通出库订单
	public function _soutorder()
	{
		if(isset($_SESSION['api']))
		{
			$user = $this->user->get_api($_SESSION['api']);
			$usp = $user;
		    $fgshop = "";$sid = "";
		    $user = explode('|',trim($user['shop'],'|'));
			foreach ($user as $value) 
		    {
				$sid .= " id = ".$value." or";
			}
		}
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$warehouse = $this->input->post('warehouse',true);
			$xztime = $this->input->post('xztime',true);
			$timetk = $this->input->post('timetkk',true);
			$timetj = $this->input->post('timetjj',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);
			$express = $this->input->post('express',true);
			$waybill = $this->input->post('waybill',true);
			$library = $this->input->post('library',true);
			$country = $this->input->post('country',true);
			$sfxh = $this->input->post('sfxh',true);
			$libraryconfirm = $this->input->post('libraryconfirm',true);
			$print = $this->input->post('print',true);
			$state = $this->input->post('state',true);
			$so = $this->input->post('so',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			/**
			$sj = $this->input->post('sj',true);
			if($sj)
			{
				$sj = $this->input->post('sj',true);
			}
			else
			{
				$sj = "fullorder";
			}
			**/
			$sj = "fullordersmt";
			$where = "1=1";
			if($warehouse)
            {
                $where  .= " and type = '$warehouse'";
            }
			if($timetk && $timetj)
            {
                $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
            }
			if($orderinfo)
            {
                $where  .= " and orderinfo = '$orderinfo'";
            }
			if($number)
            {
                $where  .= " and number = '$number'";
            }
			if($express)
            {
                $where  .= " and express = '$express'";
            }
			if($waybill)
            {
                $where  .= " and waybill = '$waybill'";
            }
			if($library)
            {
                $where  .= " and library = '$library'";
            }
			if($print)
            {
                $where  .= " and print = '$print'";
            }
			if($libraryconfirm)
            {
                $where .= " and libraryconfirm = '$libraryconfirm'";
            }
			if($state)
            {
                $where .= " and state = '$state'";
            }
			if($shop)
            {
                $where .= " and shop = '$shop'";
            }
			if($sfxh != '')
            {
                $where .= " and sfxh = '$sfxh'";
            }
			if($so)
            {
                $where  .= " and shipremarks like '%$so%'";
            }
			if($source)
            {
                $where  .= " and source = '$source'";
            }
			if($country)
            {
                $where .= " and country = '$country'";
            }
			else
			{
				if(isset($_SESSION['api']))
		        {
			        foreach ($user as $value) 
		            {
			        	$fgshop .= " shop = ".$value." or";
			        }
					$where .= " and (".rtrim($fgshop,'or').")";
		        }
			}
            //数据排序
            $order_str = "librarytime desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            $info_list = $this->$sj->find_all($where,'id,shop,type,orderinfo,number,waybill,express,librarytime',$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']);
				$info_list[$key]['express'] = $express['servicename'];
				$warehouse = $this->warehouse->read($value['type']);
				$info_list[$key]['type'] = $warehouse['title'];
				if($value['librarytime'] == '0')
				{
					$info_list[$key]['librarytime'] = '';
				}
				else
				{
					$info_list[$key]['librarytime'] = ''.date('Y-m-d H:i:s',$value['librarytime']).'';
				}
            }
		    $total = $this->$sj->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->data['express'] = $this->express->find_all();
		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
		$this->data['wlshop'] = $wlshop;
		$user = $this->user->get_api($_SESSION['api']);
		$powerid = $this->power->read($user['power']);
		$powertext = explode('|',trim($powerid['excelid'],'|'));
		$pid = '';
		foreach ($powertext as $v) 
		{
			$pid .= " id = ".$v." or";
		}
		$fullorderexcel = $this->fullorderexcel->find_all("type = '100005' and (".rtrim($pid,'or').")",'*','idorder desc');//导出模板
		$this->data['fullorderexcel'] = $fullorderexcel;
		$this->_Template('whlabel_soutorder',$this->data);
	}
	
	//订单退库
	public function _retreat()
	{
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$warehouse = $this->input->post('warehouse',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);
			$state = $this->input->post('state',true);
			$review = $this->input->post('review',true);
			$state = $this->input->post('state',true);
			$express = $this->input->post('express',true);
			$orderinfo = $this->input->post('orderinfo',true);
			$user = $this->input->post('user',true);
			$name = $this->input->post('name',true);
			$waybill = $this->input->post('waybill',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			$where = "(state=206 or state=210) and mergeid = 0";
			if($warehouse)
            {
                $where  .= " and state = '$warehouse'";
            }
			if($timetk && $timetj)
            {
                $where  .= " and buytime > '$timetk' and buytime < '$timetj'";
            }
			if($shop)
            {
                $where  .= " and shop = '$shop'";
            }
			if($source)
            {
                $where  .= " and source = '$source'";
            }
			if($state)
            {
				$where  .= " and state = '$state'";
            }
			if($review)
            {
                $where  .= " and review = '$review'";
            }
			if($state)
            {
                $where  .= " and state = '$state'";
            }
			if($express)
            {
                $where  .= " and express = '$express'";
            }
			if($orderinfo)
            {
                $where  .= " and orderinfo = '$orderinfo'";
            }
			if($user)
            {
                $where  .= " and user = '$user'";
            }
			if($name)
            {
                $where  .= " and name = '$name'";
            }
			if($waybill)
            {
                $where  .= " and waybill = '$waybill'";
            }
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            $info_list = $this->fullorder->find_all($where,'id,shop,warehouse,orderinfo,number,express,waybill,state,buytime',$order_str,$start,$perpage);
			 //格式化数据
            foreach ($info_list as $key=>$value) 
		    {
				$shop = $this->shop->read($value['shop']);
				$info_list[$key]['shop'] = $shop['shopname'];
				$warehouse = $this->warehouse->read($value['warehouse']);
				$info_list[$key]['warehouse'] = $warehouse['title'];
				$info_list[$key]['orderinfo'] = "".$value['orderinfo']."";
				$info_list[$key]['buytime'] = ''.date('Y-m-d',$value['buytime']).'
'.date('H:i:s',$value['buytime']).'
';
				if($value['waybill'] == 0)
				{
					$info_list[$key]['waybill'] = "";
				}
				$express = $this->express->read($value['express']);
				$info_list[$key]['express'] = $express['title'];
				$typeclass = $this->typeclass->read($value['state']);
				$info_list[$key]['state'] = $typeclass['title'];
            }
		    $total = $this->fullorder->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->data['express'] = $this->express->find_all();
		$this->_Template('whlabel_retreat',$this->data);
	}
	//退库标签浏览
	public function _retreatlk()
	{
		$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);
			$sku = $this->input->post('sku',true);
			$warehouse = $this->input->post('warehouse',true);
			$purchase = $this->input->post('purchase',true);
			$orderinfo = $this->input->post('orderinfo',true);
			$waybill = $this->input->post('waybill',true);
			$category = $this->input->post('category',true);
			$size = $this->input->post('size',true);
			$grade = $this->input->post('grade',true);
			$color = $this->input->post('color',true);
			$lowe = $this->input->post('lowe',true);
			$state = $this->input->post('state',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			
			$where = "state=2";
			if($timetk && $timetj)
            {
                $where  .= " and retreat > '$timetk' and retreat < '$timetj'";
            }
			if($sku)
            {
                $where  .= " and sku = '$sku'";
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($orderinfo)
            {
                $where  .= " and orderinfo = '$orderinfo'";
            }
			if($waybill)
            {
                $where  .= " and waybill = '$waybill'";
            }
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
            //数据排序
            $order_str = "time desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            $info_list = $this->whlabel->find_all($where,'id,warehouse,retreatwarehouse,sku,title,label,purchase,orderinfo,waybill,retreat,outk',$order_str,$start,$perpage);
			foreach ($info_list as $key=>$value) 
		    {
				$warehouse = $this->warehouse->read($value['warehouse']);
				$info_list[$key]['warehouse'] = $warehouse['title'];
				$retreatwarehouse = $this->warehouse->read($value['retreatwarehouse']);
				$info_list[$key]['retreatwarehouse'] = $retreatwarehouse['title'];
				$purchase = $this->purchase->read($value['purchase']);
				$info_list[$key]['purchase'] = $purchase['title'];
				if($value['outk'] != 0)
				{
					$info_list[$key]['outk'] = date('Y-m-d H:i:s',$value['outk']);
				}
				else
				{
					$info_list[$key]['outk'] = "";
				}
				if($value['retreat'] != 0)
				{
					$info_list[$key]['retreat'] = date('Y-m-d H:i:s',$value['retreat']);
				}
				else
				{
					$info_list[$key]['retreat'] = "";
				}
				if($value['orderinfo'] == 0)
				{
					$info_list[$key]['orderinfo'] = "";
				}
				if($value['waybill'] == 0)
				{
					$info_list[$key]['waybill'] = "";
				}
		    }
		    $total = $this->whlabel->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('whlabel_retreatlk',$this->data);
	}
	//更换标签及浏览
	public function _change()
	{
		$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);
			$label = $this->input->post('label',true);
			$oldlabel = $this->input->post('oldlabel',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			$where = "state=10 ";
			if($timetk && $timetj)
            {
                $where  .= " and labeltime > '$timetk' and labeltime < '$timetj'";
            }
			if($label)
            {
                $where  .= " and label = '$label'";
            }
			if($oldlabel)
            {
                $where  .= " and oldlabel = '$oldlabel'";
            }
            //数据排序
            $order_str = "time asc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            $info_list = $this->whlabel->find_all($where,'id,oldlabel,oldtitle,label,title,	labeltime',$order_str,$start,$perpage);
			foreach ($info_list as $key=>$value) 
		    {
					$info_list[$key]['labeltime'] = date('Y-m-d H:i:s',$value['labeltime']);
		    }
		    $total = $this->whlabel->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('whlabel_change',$this->data);
	}
	
	//产品标签
	public function _cpbqdc()
	{
		if(isset($_GET['excel']))  
		{
			$where = "1=1";
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
			$warehouse = $this->input->get('warehouse',true);
			$state = $this->input->get('state',true);
			$timetk = $this->input->get('timetkk',true);
			$timetj = $this->input->get('timetjj',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($state || $state == 0)
            {
                $where  .= " and state = '$state'";
            }
			if($timetk && $timetj)
            {
                $where .= " and time > '$timetk' and time < '$timetj'";
            }
            //取得信息列表
           $info_list = $this->whlabel->find_all($where,'*');
			$rows = array();$list = array();
			foreach ($info_list as $key=>$value) 
		    {
				$rows[$value['time']] = $value;//所有数据sku
		    }
			foreach ($rows as $value) 
		    {
				$warehouse = $this->warehouse->read($value['warehouse']);
				$s = $this->whlabel->find_count($where.' and time = "'.$value['time'].'"');
				$list[] = array($warehouse['title'],$value['sku'],$value['title'],date('Y-m-d H:i:s',$value['enter']),date('Y-m-d H:i:s',$value['time']),$value['text'],$s);
		    }
            $title = "产品标签统计表"; 
            $titlename = "
            | ".$title." | 
|---|
            
			| 仓库 | SKU | 产品 | 入库时间 | 操作时间 | 备注 | 数量 | 
            
"; 
            $filename = $title.".xls";
			$tail = "";
            $this->excel->get_fz2($list,$titlename,$filename,$tail);
	    }
	}
	//进销存导出
	public function _exceljxc()
	{
		$classid = $this->classid->sku();
		$pm = $classid;
		$typeclass = array();
		$tc = $this->typeclass->find_all();
		foreach ($tc as $v)
		{
			$typeclass[$v['id']] = $v;
		}
		$prc = array();
		$purchase = $this->purchase->find_all();
		foreach($purchase as $k=>$v)
		{
			$prc[$v['id']] = $v['title'];
		}
		if(isset($_GET['excel']))  
		{
			$where = "sku != 'Preset'";
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
			$category = $this->input->get('category',true);
			$warehouse = $this->input->get('warehouse',true);
			$excelid = $this->input->get('sid',true);
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			$xzid = '';
			if($excelid)
            {
				$excelid = explode(',',trim($excelid,','));
				foreach ($excelid as $key=>$value) 
		        {
					$xzid .= " id = ".$value." or";
				}
                $xzid = " and (".rtrim($xzid,'or').")";;
            }
            //取得信息列表
			/**
           $info_list = $this->whlabel->find_all($where.$xzid,'*');
			$rows = array();$list = array();
			foreach ($info_list as $key=>$value) 
		    {
				$rows[strtolower($value['sku']).$value['features'].$value['warehouse']] = $value;//所有数据sku
		    }
			**/
			
			$wt = array();
			$whlabel_type = $this->whlabel_type->find_all();
			foreach ($whlabel_type as $v) 
			{
				$wt[$v['id']] = $v['title'];
			}
			$wh = array();
				$w = $this->warehouse->find_all('1=1','id,title');
				foreach ($w as $v) 
				{
					$wh[$v['id']] = $v['title'];
				}
			$list = array();
			$rows = $this->whlabel->find_pc($where,'sku,purchase,features,warehouse','warehouse,purchase,details,cpid,dbcontent,sku,cs,bs,title,features,cpbz,sm,type,number');
			foreach ($rows as $key=>$value) 
		    {
				if(isset($wt[$value['type']]))
				{
					$rows[$key]['type'] = $wt[$value['type']];
				}
				else
				{
					$rows[$key]['type'] = '未设置';
				}
				$bm = '03';
				$bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
				$rows[$key]['purchase'] = (isset($prc[$value['purchase']]))?$prc[$value['purchase']]:'未知';
				$sd = $this->whlabel->find_all($where.' and purchase = "'.$value['purchase'].'" and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"','details,cpid,cpbz,state');
				$details = array();
				$cpid = array();
				$cpbz = array();
				$c = 0;$g = 0;$x = 0;$t = 0;$s = 0;$q = 0;
				foreach ($sd as $k=>$v) 
		    	{
					if($v['state'] == 0)
					{
						$c++;
						if($v['cpid'] != 0)
						{
					    	$cpid[$v['cpid']] = $v['cpid'];
						}
						if($v['cpbz'] != '')
						{
					    	$cpbz[$v['cpbz']] = $v['cpbz'];
						}
					}
					if($v['state'] != 9)
					{
						$g++;
					}
					if($v['state'] == 1)
					{
						$x++;
					}
					if($v['state'] == 2)
					{
						$t++;
					}
					if($v['state'] == 8)
					{
						$s++;
					}
					if($v['state'] == "3" || $v['state'] == "4" || $v['state'] == "5" || $v['state'] == "6" || $v['state'] == "7")
					{
						$q++;
					}
					$details[$v['details']] = $v['details'];
				}
				$z = $this->whlabel->find_count($where.' and sku = "'.$value['sku'].'" and zd != "" and state = 0 and purchase = "'.$value['purchase'].'" and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
				$rows[$key]['details'] = implode("、",$details);
				$rows[$key]['cpid'] = ($cpid)?implode(" ",$cpid):'';
				$number = $value['number'];
				$ftime = time()-15*24*3600;
				$rows[$key]['warehouse'] = $wh[$value['warehouse']];
				$rows[$key]['number'] = $g;
				$rows[$key]['c'] = $c;
				$rows[$key]['x'] = $x;
				$rows[$key]['t'] = $t;
				$rows[$key]['s'] = $s;
				$rows[$key]['q'] = $q;
				$rows[$key]['z'] = $z;
				
				$features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$value['features']);
			    $features = explode('-',trim($features,'-'));
				$rows[$key]['dbcontent'] = $typeclass[$features[0]]['title'];
				$pm = $classid;
				$jm = $classid;
				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)
					{
						if(!isset($typeclass[$v]))
					    {
							continue;
					    }
					    		if(isset($pm[$typeclass[$v]['classid']]))
					    {
							if(stripos($typeclass[$v]['zh'],'|') !== false)
							{
								$tz = explode('|',$typeclass[$v]['zh']);
								$pm[$typeclass[$v]['classid']] = $tz[0];
							}
							else
							{
						        $pm[$typeclass[$v]['classid']] = $typeclass[$v]['zh'];
							}
					    }
						if(isset($jm[$typeclass[$v]['classid']]))
						{
						       $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
							
						}
				    }
			    }
				$jm = array_filter($jm);
				$rows[$key]['bs'] = implode("-",$jm);
				$rows[$key]['cs'] = $bm.implode("",$bmpx);
				$zh = implode(" ",$pm);
				$zh = str_replace('自然色 ','',trim($zh,' '));
				$zh = str_replace(array('        ','       ','      ','     ','    ','   ','  '),' ',$zh);
				$zh = preg_replace("/\r\n|\r|\n/",'',$zh);
				$rows[$key]['features'] = $zh;
				
		    }
            $title = "总进销存统计表"; 
            $titlename = "
            | ".$title." | 
|---|
            
			| 仓库 | 供应商 | 位置 | 库存编码 | 类目 | SKU | 用友编码 | 用友料号 | 商品名称 | 商品中文 | 产品备注 | 说明 | 类型 | 入库总量 | 库存数量 | 销售数量 | 退货数量 | 删除数量 | 其它操作 | 占单数量 | 
            
";
            $filename = $title.".xls";
			$tail = "";
            $this->excel->get_fz2($rows,$titlename,$filename,$tail);
	    }
	}
	//入库导出
	public function _excelr()
	{
		if(isset($_GET['excel']))  
		{
			$category = $this->input->get('category',true);
			$size = $this->input->get('size',true);
			$grade = $this->input->get('grade',true);
			$color = $this->input->get('color',true);
			$lowe = $this->input->get('lowe',true);
			$sku = $this->input->get('sku',true);
			$warehouse = $this->input->get('warehouse',true);
			$purchase = $this->input->get('purchase',true);
			$ktime = $this->input->get('ktime',true);
			$jtime = $this->input->get('jtime',true);
			$ktime = strtotime($ktime);
			$jtime = strtotime($jtime);
			$where = "1=1";$gj = "";$ck = "";
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($sku)
            {
                $where  .= " and sku = '$sku'";
            }
			if($ktime && $jtime)
            {
                $where  .= " and enter > '$ktime' and enter < '$jtime' and state != 9";
            }
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
			$list = array();
			$rows = $this->whlabel->find_pc($where,'enter,sku,warehouse','*',$order_str);
			foreach ($rows as $value) 
		    {
				$ck = $this->warehouse->read($value['warehouse']);
				$warehouse = $ck['title'];
				$tkck = $this->warehouse->read($value['retreatwarehouse']);//退库仓库
				$retreatwarehouse = $tkck['title'];
				$gy = $this->purchase->read($value['purchase']);
				$purchase = $gy['title'];
				$g = $this->whlabel->find_count($where.' and enter = "'.$value['enter'].'" and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'"');
				$list[] = array('warehouse'=>$warehouse,'sku'=>$value['sku'],'title'=>$value['title'],'time'=>date('Y-m-d H:i:s',$value['enter']),'number'=>$g);
		    }
            $title = date('Y-m-d',$ktime).'至'.date('Y-m-d',$jtime)."入库详情"; 
            $titlename = "
            | ".$title." | 
|---|
            
			| 仓库 | SKU | 产品 | 时间 | 数量 | 
            
"; 
            $filename = $title.".xls";
			$tail = "";
            $this->excel->get_fz2($list,$titlename,$filename,$tail);
	    }
	}
	
	//出库、退库导出
	public function _excelct()
	{
		$classid = $this->classid->sku();
		$pm = $classid;
		$typeclass = array();
		$tc = $this->typeclass->find_all();
		foreach ($tc as $v)
		{
			$typeclass[$v['id']] = $v;
		}
		$prc = array();
		$purchase = $this->purchase->find_all();
		foreach($purchase as $k=>$v)
		{
			$prc[$v['id']] = $v['title'];
		}
		if(isset($_GET['excel']))  
		{
			$wh = array();
			$w = $this->warehouse->find_all('1=1','id,title');
			foreach ($w as $v) 
			{
				$wh[$v['id']] = $v['title'];
			}
			$type = $this->input->get('excel',true);
			$category = $this->input->get('category',true);
			$size = $this->input->get('size',true);
			$grade = $this->input->get('grade',true);
			$color = $this->input->get('color',true);
			$lowe = $this->input->get('lowe',true);
			$sku = $this->input->get('sku',true);
			$warehouse = $this->input->get('warehouse',true);
			$lacetype = $this->input->get('lacetype',true);
			$lacecolor = $this->input->get('lacecolor',true);
			$density = $this->input->get('density',true);
			$haircap = $this->input->get('haircap',true);
			$purchase = $this->input->get('purchase',true);
			$title = $this->input->get('title',true);
			$state = $this->input->get('state',true);
			$sid = $this->input->get('sid',true);
			$ktime = $this->input->get('ktime',true);
			$jtime = $this->input->get('jtime',true);
			$ktime = strtotime($ktime);
			$jtime = strtotime($jtime);
			$where = "1=1";$gj = "";$ck = "";
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($state)
            {
                $where  .= " and state = '$state'";
            }
			if($lacetype)
            {
                $where  .= " and features like '%-$lacetype-%'";
            }
			if($lacecolor)
            {
                $where  .= " and features like '%-$lacecolor-%'";
            }
			if($density)
            {
                $where  .= " and features like '%-$density-%'";
            }
			if($haircap)
            {
                $where  .= " and features like '%-$haircap-%'";
            }
			if($title)
            {
				$title = trim($title,' ');
				$title = trim($title,'	');
                $where  .= " and title like '%$title%'";
            }
			if($sku)
            {
				$sku = trim($sku,' ');
				$sku = trim($sku,'	');
                $where  .= " and sku like '%$sku%'";
            }
			if($ktime && $jtime)
            {
                if($type == 1)
				{
					$tl = '出库';
                    $where  .= " and state= '1' and outk > '$ktime' and outk < '$jtime'";
				}
				else if($type == 2)
				{
					$tl = '退库';
					$where  .= " and state= '2' and retreat > '$ktime' and retreat < '$jtime'";
				}
				else if($type == 3)
				{
					$gj  = " and enter > '$ktime' and enter < '$jtime'";
					$ck  = " and outk > '$ktime' and outk < '$jtime'";
				}
				else if($type == 4)
				{
					$tl = '出库+零售';
					$where  .= " and (state= '1' or state= '10') and outk > '$ktime' and outk < '$jtime'";
				}
				else if($type == 5)
				{
					$tl = '零售';
					$where  .= " and state= '10' and outk > '$ktime' and outk < '$jtime'";
				}
            }
			$sidwhere = '';
			if($sid)
            {
				$sd = "";
				$s = explode(',',trim($sid,','));
				foreach ($s as $value) 
		    	{
					$sd .= " id = ".$value." or";
				}
                $sidwhere  = " and (".rtrim($sd,'or').")";
            }
            //数据排序
            $order_str = "time desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
			if($type != 3 && $type != 5)
			{
			    if($type == 1 || $type == 4)
			    {
                    $info_list = $this->whlabel->find_all($where,'warehouse,purchase,sku,title,features,label,orderinfo,waybill,outk',$order_str);
			        foreach ($info_list as $key=>$value) 
		            {
						$info_list[$key]['purchase'] = (isset($prc[$value['purchase']]))?$prc[$value['purchase']]:'未知';
				        $info_list[$key]['outk'] = date('Y-m-d H:i:s',$value['outk']);//减12调整美国时间
						$warehouse = $this->warehouse->read($value['warehouse']);
					    $info_list[$key]['warehouse'] = $warehouse['title'];
						$features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$value['features']);
			    		$features = explode('-',trim($features,'-'));
						$pm = $classid;
						foreach($features as $k=>$v)
						{
							if($v != 0)
							{
								if(!isset($typeclass[$v]))
					    		{
									continue;
					    		}
					    		if(isset($pm[$typeclass[$v]['classid']]))
					    {
							if(stripos($typeclass[$v]['zh'],'|') !== false)
							{
								$tz = explode('|',$typeclass[$v]['zh']);
								$pm[$typeclass[$v]['classid']] = $tz[0];
							}
							else
							{
						        $pm[$typeclass[$v]['classid']] = $typeclass[$v]['zh'];
							}
					    }
				    		}
			   		    }
					    $zh = implode(" ",$pm);
					    $zh = str_replace('自然色 ','',trim($zh,' '));
					    $zh = str_replace(array('        ','       ','      ','     ','    ','   ','  '),' ',$zh);
					    $zh = preg_replace("/\r\n|\r|\n/",'',$zh);
						$info_list[$key]['features'] = $zh;
		            }
			    }
			    else
			    {
				     $info_list = $this->whlabel->find_all($where,'warehouse,purchase,sku,title,features,label,orderinfo,waybill,retreat',$order_str);
			        foreach ($info_list as $key=>$value) 
		            {
						$info_list[$key]['purchase'] = (isset($prc[$value['purchase']]))?$prc[$value['purchase']]:'未知';
				        $info_list[$key]['retreat'] = date('Y-m-d H:i:s',$value['retreat']);//减12调整美国时间
						$warehouse = $this->warehouse->read($value['warehouse']);
					    $info_list[$key]['warehouse'] = $warehouse['title'];
						$features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$value['features']);
			    		$features = explode('-',trim($features,'-'));
						$pm = $classid;
						foreach($features as $k=>$v)
						{
							if($v != 0)
							{
								if(!isset($typeclass[$v]))
					    		{
									continue;
					    		}
					    		if(isset($pm[$typeclass[$v]['classid']]))
					    {
							if(stripos($typeclass[$v]['zh'],'|') !== false)
							{
								$tz = explode('|',$typeclass[$v]['zh']);
								$pm[$typeclass[$v]['classid']] = $tz[0];
							}
							else
							{
						        $pm[$typeclass[$v]['classid']] = $typeclass[$v]['zh'];
							}
					    }
				    		}
			   		    }
					    $zh = implode(" ",$pm);
					    $zh = str_replace('自然色 ','',trim($zh,' '));
					    $zh = str_replace(array('        ','       ','      ','     ','    ','   ','  '),' ',$zh);
					    $zh = preg_replace("/\r\n|\r|\n/",'',$zh);
						$info_list[$key]['features'] = $zh;
		            }
			    }
                $title = date('Y-m-d',$ktime).'至'.date('Y-m-d',$jtime).$tl.'详情'; 
                $titlename = "
                | ".$title." | 
|---|
                
				| 仓库 | 供应商 | SKU | 商品名称 | 商品中文 | 标签 | 订单号 | 运单号 | ".$tl."时间(中国时间) | 
                
"; 
                $filename = $title.".xls";
			    $tail = "";
                $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
			}
			else if($type == 5)
			{
				$info_list = $this->whlabel->find_all($where,'warehouse,purchase,sku,title,features,label,outk',$order_str);
			    foreach ($info_list as $key=>$value) 
		        {
					$info_list[$key]['purchase'] = (isset($prc[$value['purchase']]))?$prc[$value['purchase']]:'未知';
					$info_list[$key]['outk'] = date('Y-m-d H:i:s',$value['outk']);//减12调整美国时间
					$warehouse = $this->warehouse->read($value['warehouse']);
					$info_list[$key]['warehouse'] = $warehouse['title'];
					$features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$value['features']);
			    		$features = explode('-',trim($features,'-'));
						$pm = $classid;
						foreach($features as $k=>$v)
						{
							if($v != 0)
							{
								if(!isset($typeclass[$v]))
					    		{
									continue;
					    		}
					    		if(isset($pm[$typeclass[$v]['classid']]))
					    {
							if(stripos($typeclass[$v]['zh'],'|') !== false)
							{
								$tz = explode('|',$typeclass[$v]['zh']);
								$pm[$typeclass[$v]['classid']] = $tz[0];
							}
							else
							{
						        $pm[$typeclass[$v]['classid']] = $typeclass[$v]['zh'];
							}
					    }
				    		}
			   		    }
					    $zh = implode(" ",$pm);
					    $zh = str_replace('自然色 ','',trim($zh,' '));
					    $zh = str_replace(array('        ','       ','      ','     ','    ','   ','  '),' ',$zh);
					    $zh = preg_replace("/\r\n|\r|\n/",'',$zh);
						$info_list[$key]['features'] = $zh;
		        }
				$title = date('Y-m-d',$ktime).'至'.date('Y-m-d',$jtime).$tl.'详情'; 
                $titlename = "
                | ".$title." | 
|---|
                
				| 仓库 | 供应商 | SKU | 商品名称 | 商品中文 | 标签 | ".$tl."时间(中国时间) | 
                
"; 
                $filename = $title.".xls";
			    $tail = "";
                $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
			}
			else
			{
				/**
				$info_list = $this->whlabel->find_all($where.$sidwhere,'*');
				$rows = array();$list = array();
				foreach ($info_list as $key=>$value) 
		    	{
					$rows[strtolower($value['sku']).'warehouse'.$value['warehouse']] = $value;//所有数据sku
		    	}
				**/
				$wh = array();
				$w = $this->warehouse->find_all('1=1','id,title');
				foreach ($w as $v) 
				{
					$wh[$v['id']] = $v['title'];
				}
				$wt = array();
			$whlabel_type = $this->whlabel_type->find_all();
			foreach ($whlabel_type as $v) 
			{
				$wt[$v['id']] = $v['title'];
			}
			$classid = $this->classid->sku();
				$list = array();
				$rows = $this->whlabel->find_pc($where.$sidwhere,'sku,purchase,features,warehouse','warehouse,purchase,details,cpid,sku,title,features,cpbz,sm,type');
				foreach ($rows as $key=>$value) 
		    	{
					$rows[$key]['purchase'] = (isset($prc[$value['purchase']]))?$prc[$value['purchase']]:'未知';
					$rows[$key]['purchase'] = (isset($prc[$value['purchase']]))?$prc[$value['purchase']]:'未知';
				$sd = $this->whlabel->find_all($where.' and purchase = "'.$value['purchase'].'" and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"','details,cpid,cpbz,state,outk,retreat');
				$details = array();
				$cpid = array();
				$cpbz = array();
				$c = 0;$g = 0;$x = 0;$t = 0;$s = 0;$q = 0;
				foreach ($sd as $k=>$v) 
		    	{
					if($v['state'] == 0)
					{
						$c++;
					}
					if($v['state'] != 9)
					{
						$g++;
					}
					if($v['outk'] > 1)
					{
						$x++;
					}
					if($v['retreat'] > 0)
					{
						$t++;
					}
					if($v['state'] == 8)
					{
						$s++;
					}
					if($v['state'] == "3" || $v['state'] == "4" || $v['state'] == "5" || $v['state'] == "6" || $v['state'] == "7")
					{
						$q++;
					}
					$details[$v['details']] = $v['details'];
					if($v['cpid'] != 0)
					{
					    $cpid[$v['cpid']] = $v['cpid'];
					}
					if($v['cpbz'] != '')
					{
					    $cpbz[$v['cpbz']] = $v['cpbz'];
					}
				}
				if(isset($wt[$value['type']]))
				{
					$rows[$key]['type'] = $wt[$value['type']];
				}
				else
				{
					$rows[$key]['type'] = '未设置';
				}
				$rows[$key]['details'] = implode("、",$details);
				$rows[$key]['cpid'] = ($cpid)?implode(" ",$cpid):'';
				$ftime = time()-15*24*3600;
				$rows[$key]['warehouse'] = $wh[$value['warehouse']];
				$rows[$key]['cpbz'] = ($cpbz)?implode(" ",$cpbz):'';
				$rows[$key]['g'] = $this->whlabel->find_count($where.' and purchase = "'.$value['purchase'].'" and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'" and state != 9'.$gj);
				$rows[$key]['c'] = $c;
				$rows[$key]['x'] = $this->whlabel->find_count($where.' and purchase = "'.$value['purchase'].'" and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'" and state = 1'.$ck);
				$rows[$key]['t'] = $t;
				
				
				$z = $this->whlabel->find_count($where.' and sku = "'.$value['sku'].'" and zd != "" and state = 0 and purchase = "'.$value['purchase'].'" and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
				$rows[$key]['z'] = $z;
				$jm = $classid;
				
					$features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$value['features']);
			    		$features = explode('-',trim($features,'-'));
						$pm = $classid;
						foreach($features as $k=>$v)
						{
							if($v != 0)
							{
								if(!isset($typeclass[$v]))
					    		{
									continue;
					    		}
					    		if(isset($pm[$typeclass[$v]['classid']]))
					    {
							if(stripos($typeclass[$v]['zh'],'|') !== false)
							{
								$tz = explode('|',$typeclass[$v]['zh']);
								$pm[$typeclass[$v]['classid']] = $tz[0];
							}
							else
							{
						        $pm[$typeclass[$v]['classid']] = $typeclass[$v]['zh'];
							}
							if(isset($jm[$typeclass[$v]['classid']]))
						{
							if($typeclass[$v]['jm'])
							{
						    	$jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
							}
						}
					    }
				    		}
			   		    }
					    $zh = implode(" ",$pm);
					    $zh = str_replace('自然色 ','',trim($zh,' '));
					    $zh = str_replace(array('        ','       ','      ','     ','    ','   ','  '),' ',$zh);
					    $zh = preg_replace("/\r\n|\r|\n/",'',$zh);
						$rows[$key]['features'] = $zh;
						$jm = array_filter($jm);//去除空值
				$jm = implode("-",$jm);
				$rows[$key]['jm'] = $jm;
				$rows[$key]['asd'] = $typeclass[$features[0]]['title'];
		    	}
            	$title = date('Y-m-d',$ktime).'至'.date('Y-m-d',$jtime).'进销存详情'; 
            	$titlename = "
            	| ".$title." | 
|---|
            	
				| 仓库 | 供应商 | 位置 | 库存编码 | SKU | 商品名称 | 商品中文 | 产品备注 | 说明 | 类型 | 入库总量 | 库存数量 | 销售数量 | 退货数量 | 占单数量 | 料号 | 类目 | 
            	
"; 
            	$filename = $title.".xls";
				$tail = "";
            	$this->excel->get_fz2($rows,$titlename,$filename,$tail);
			}
	    }
	}
	
	//出库+入库数据整合
	public function _excelcr()
	{
		if(isset($_GET['excel']))  
		{
			$type = $this->input->get('excel',true);
			$category = $this->input->get('category',true);
			$size = $this->input->get('size',true);
			$grade = $this->input->get('grade',true);
			$color = $this->input->get('color',true);
			$lowe = $this->input->get('lowe',true);
			$sku = $this->input->get('sku',true);
			$warehouse = $this->input->get('warehouse',true);
			$purchase = $this->input->get('purchase',true);
			$state = $this->input->get('state',true);
			$sid = $this->input->get('sid',true);
			$ktime = $this->input->get('ktime',true);
			$jtime = $this->input->get('jtime',true);
			$ktime = strtotime($ktime);
			$jtime = strtotime($jtime);
			$where = "1=1";$gj = "";$ck = "";
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($state)
            {
                $where  .= " and state = '$state'";
            }
			if($sku)
            {
                $where  .= " and sku like '%$sku%'";
            }
			if($ktime && $jtime)
            {
               $where .= " and ((enter > '$ktime' and enter < '$jtime') or (outk > '$ktime' and outk < '$jtime'))";
            }
			$sidwhere = '';
			if($sid)
            {
				$sd = "";
				$s = explode(',',trim($sid,','));
				foreach ($s as $value) 
		    	{
					$sd .= " id = ".$value." or";
				}
                $sidwhere  .= " and (".rtrim($sd,'or').")";
            }
			
            //取得信息列表
			$timeread  = $ktime;
			$timenum = ceil(($jtime - $ktime) / (24*3600));
			$timelist = array();
			for($i=0;$i<$timenum;$i++)
			{
				$timeread = ($i>0)?$ktime+$i*24*3600:$ktime;
				$timelist[date('Y-m-d',$timeread)] = array('c'=>0,'r'=>0);
			}
			
				$info_list = $this->whlabel->find_all($where.$sidwhere,'outk,enter,sku,state');
				//echo "";
				//print_r($info_list);
				//exit();
				$rows = array();$list = array();
				foreach ($info_list as $key=>$value) 
		    	{
					$thistime = $timelist;
					if(isset($rows[strtolower($value['sku'])]))
					{
						if($value['outk'] > $ktime && $value['state'] < $jtime)
						{
							$rows[strtolower($value['sku'])][date('Y-m-d',$value['outk'])]['c'] += 1;
						}
						if($value['enter'] > $ktime && $value['enter'] < $jtime)
						{
							$rows[strtolower($value['sku'])][date('Y-m-d',$value['enter'])]['r'] += 1;
						}
					}
					else
					{
						if($value['outk'] > $ktime && $value['outk'] < $jtime)
						{
							$thistime[date('Y-m-d',$value['outk'])]['c'] += 1;
						}
						if($value['enter'] > $ktime && $value['enter'] < $jtime)
						{
							$thistime[date('Y-m-d',$value['enter'])]['r'] += 1;
						}
						$rows[strtolower($value['sku'])] = $thistime;
					}
		    	}
            	$str = "
       	 	
        	
        	";
			
			$str .= "| SKU";
			foreach ($timelist as $k=>$v)
            {
            	$str .=" | ".$k."出库";
				$str .=" | ".$k."入库";
			}
           	$str .=  " | 
"; 
			$str .= ""; 
			foreach ($rows as $key=>$val)
			{
				$str .= "| ".strtoupper($key).""; 
		   		foreach ($val as $k=>$v)
			    {
					$str .= " | ".$val[$k]['c'].""; 
					if($val[$k]['r'] > 0)
					{
					    $str .= " | -".$val[$k]['r'].""; 
					}
					else
					{
						$str .= " | ".$val[$k]['r'].""; 
					}
				}
				$str .=  " | 
"; 
       		 }
			 $str .= "
";
			 $str .= ""; 
			 header( "Content-Type: application/vnd.ms-excel; name='excel'" ); 
			 header( "Content-type: application/octet-stream" ); 
			 header( "Content-Disposition: attachment; filename=".time().'.xls' ); 
			 header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ); 
			 header( "Pragma: no-cache" ); 
			 header( "Expires: 0" ); 
			 exit($str);
		
	    }
	}
	
	
	//数量调整模板导出
	public function _presetout()
	{
		if(isset($_GET['excel']))  
		{
			$where = "sku != 'Preset' and purchase != 0";
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            $info_list = $this->whlabel->find_pc($where,'warehouse,purchase,sku','*','id desc',0,1);
			$rows = array();$list = array();
			foreach ($info_list as $value) 
		    {
				$warehouse = $this->warehouse->read($value['warehouse']);
				$number = $value['number'];$ftime = time()-15*24*3600;
				$purchase = $this->purchase->read($value['purchase']);
				$list[] = array($warehouse['title'],$purchase['bm'],$value['sku'],'0','','0','','');
		    }
            $title = "库存模板"; 
            $titlename = "
            
			| 仓库 | 供应商编码 | SKU | 增减数量(正数或负数) | 增减备注 | 扣减方式:0减少库存1删除库存 | 增加类型(增加为必填,填数字):1.采购入库2.盘盈调整3.其他调整入库4.退库入库5.退货可用入库6.形态转换入库 | 扣减类型(扣减为必填,填数字):1.销售出库2.销售美国出库3.盘亏调整4.其他调整出库5.形态转换出库 | 
            
"; 
            $filename = $title.".xls";
			$tail = "";
            $this->excel->get_fz2($list,$titlename,$filename,$tail);
	    }
	}
	//数量调整模板导入
	public function _presetedit()
	{
		$dir = '/data/excel/'.date('Ymd',time()).'/';
		$config['upload_path'] = '.'.$dir ;
		$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
        $config['allowed_types'] = 'xls|xlsx|csv';
        $config['max_size'] = 10240;
		$this->load->library('upload', $config);
		$this->upload->initialize($config);
        if ($this->upload->do_upload('userfile'))
        {
			$full_path = $dir.$this->upload->data('file_name');
			$fileName = '.' . $full_path;
            if (!file_exists($fileName)) 
			{
				echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
            }
			else
			{
				require_once "./data/excel/PHPExcel/IOFactory.php";
				$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
				$phpExcel->setActiveSheetIndex(0);// 设置为默认表
				$sheetCount = $phpExcel->getSheetCount();// 获取表格数量
				$row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
				$column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
				++$column;//如果列数大于26行
				$list = array();
				for ($i = 2; $i <= $row; $i++) // 行数循环
				{
					$data = array();
                    for ($c = 'A'; $c != $column; $c++)  // 列数循环
	                {
						$data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
                    }
					$list[] = $data;
                }
			}
			$i = 0;$j = 0;$ed = array();
		    foreach ($list as $key=>$value)
		    {
				$time = time();
				if($value['0'] == "")
				{
					continue;
				}
				$warehouse = $this->warehouse->get_title($value['0']);
				$purchase = $this->purchase->get_bm($value['1']);
				$sku =  $value['2'];
				$num =  $value['3'];//调整数量
				$text =  $value['4'];//扣减说明
				$type =  $value['5'];//调整方式0扣减1删除
				$rktype =  $value['6']!=''?$value['6']:0;//增加库存
				$cktype =  $value['7']!=''?$value['7']:0;//减少库存
				$d = $this->whlabel->get_warehousesku($warehouse['id'],$sku);
				if(!$purchase)//如果没有这个SKU
				{
					$ed[] = array($purchase.'-不存在此供应商编码');
					$j++;
					continue;
				}
				if(!$d)//如果没有这个SKU
				{
					$ed[] = array($sku.'-库存中不存在此SKU');
					$j++;
					continue;
				}
				if(!isset($warehouse['id']))
				{
					$ed[] = array($sku.'-仓库名错误!');
					$j++;
					continue;
				}
				if($type != '0' && $type != '1')
				{
					$ed[] = array($sku.'-扣减方式填写错误!');
					$j++;
					continue;
				}
				if($num < 0)//扣减库存
				{
					if($warehouse['id'] == 5 && ($cktype == '' || ($cktype > 1 && $text == '')))
					{
						$ed[] = array($sku.'-扣减必须填写扣减类型,非类型1必须填写备注');
						$j++;
						continue;
					}
					$data = $this->whlabel->find_all('warehouse = "'.$warehouse['id'].'" and sku = "'.$sku.'" and zd = "" and state = 0');
					if(count($data) < abs($num))
					{
						$ed[] = array($sku.'-扣减数量大于库存剩余数量!');
						$j++;
						continue;
					}
					if($type == 0)//如果扣减方式为 扣减库存
					{
						for($i=0;$iwhlabel->save(array('state'=>8,'textout'=>$text,'deltime'=>$time,'cktype'=>$cktype,'time'=>$time,'outk'=>$time),$data[$i]['id']);
						}
					}
					else if($type == 1)
					{
						$zt = $this->whlabeltransport->find_all('sku = "'.$sku.'" and warehouse = "'.$warehouse['id'].'" and features = "'.$d['features'].'" and cz = "0"');
						if(count($zt) > 0)
						{
							$ed[] = array($sku.'-有在途库存无法删除!');
							$j++;
							continue;
						}
						for($i=0;$iwhlabel->remove($data[$i]['id']);
						}
					}
				}
				else if($num > 0)//增加库存
				{
					if($warehouse['id'] == 5 && ($rktype == '' || ($rktype > 1 && $text == '')))
					{
						$ed[] = array($sku.'-增加必须填写增加类型,非类型1必须填写备注');
						$j++;
						continue;
					}
					$post['sku'] = $d['sku'];
					$post['shop'] = $d['shop'];
					$post['warehouse'] = $warehouse['id'];
					$post['purchase'] = $purchase['id'];
					$post['retreatwarehouse'] = $d['retreatwarehouse'];
					$post['state'] = 0;
					$post['title'] = $d['title'];
					$post['number'] = $d['number'];
					$post['features'] = $d['features'];
					$post['enter'] = $time;
					$post['time'] = $time;//操作时间
					$post['rktype'] = $rktype;
					for($i=0;$i<$num;$i++)
					{
						$post['label'] = time().rand(100,999).$i;
						$this->whlabel->insert($post);
					}
				}
				sleep(1);//防止入库时间一样,需要延迟1秒
			}
			if($j > 0)
			{
				$tt = date('Ymd',time());
				$title = '库存导入错误信息-'.$tt;
        		$titlename = "";
				$tail = "\n";
        		$filename = $title.".xls";
        		$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
				$dir = '/data/excel/'.$time.'/';
				$file_name = 'error_'.$time.rand(1000,9999);
				if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
				$myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
				fwrite($myfile,$ecl);
				fclose($myfile);
				$error = $dir.$file_name.'.xls';
				echo json_encode(array('msg'=>'导入成功,'.$j.'条异常,','error'=>$error,'success'=>true));exit;
			}
			else
			{
				echo json_encode(array('msg'=>'导入成功!','error'=>1,'success'=>true));exit;
			}
		}
	}
	//笛卡儿积
	function cp($ps,$sets,$list)
	{
        $result = array();$j=0;
        for($i=0,$count=count($sets); $i<$count-1; $i++)
	    {
            if($i==0)
			{
                $result = $sets[$i];
            }
        $tmp = array();
        foreach($result as $res)
		{
            foreach($sets[$i+1] as $set)
			{
                $tmp[] = $res.','.$set;
            }
        }
        $result = $tmp;
        }
        $this->db->trans_begin();
        foreach ($result as $v) 
	    {
		    $post = array();$title = "";$num="";
		    $data = explode(',',$v);
		    for($i=0;$itypeclass->read($data[$i]);
			    $title = $title.$typeclass['title']." ";
				if($data[$i] != 0)
				{
				    $num .=$data[$i];//所有数据ID拼接
				}
		    }
			foreach ($ps as $kp=>$vp) 
	        {
				$post[$kp] = $vp;
			}
			$post['number'] = $num;
			$info_list = $this->whlabel->get_number($num);//查询whlabel是否存在此拼接的数据ID
			if($info_list)
			{
				$j++;
			}
			else
			{
				$skunum = $this->whlabel->find_count();
				$post['sku'] = 'LY'.substr(strval($skunum+1+10000000),1,7);
		        $post['title'] = rtrim($title,' ');
		        $this->whlabel->insert($post);
			}
					
	    }
	    if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_commit();
			return NULL;
        }
        else
        {
            $this->db->trans_commit();
			return $j;
        }
    }
	public function _kj($arg_array)
	{
		if(isset($_POST['sku']))  
		{
			$time = time();
			$sku = $this->input->post('sku',true);
			$warehouse = $this->input->post('warehouse',true);
			$num = $this->input->post('num',true);
			$text = $this->input->post('text',true);
			$purchase = $this->input->post('purchase',true);
			$cktype = $this->input->post('cktype',true);
			$order = $this->whlabel->find_all("purchase = '$purchase' and sku = '$sku' and warehouse = '$warehouse' and zd = '' and state = 0");
			if($cktype != 1 && $text == '')
			{
				echo json_encode(array('msg'=>"非销售出库必须填写备注!",'success'=>false));exit;
			}
			if($num > count($order))
			{
				echo json_encode(array('msg'=>"扣减数量大于剩余库存数量!",'success'=>false));exit;
			}
			else
			{
				for($i=0;$i<$num;$i++)
				{
					$this->whlabel->save(array('state'=>8,'cktype'=>$cktype,'textout'=>$text,'deltime'=>$time,'time'=>$time,'outk'=>$time),$order[$i]['id']);
				}
			}
			echo json_encode(array('msg'=>"扣减成功!",'success'=>false));exit;
		}
		$uid = $this->whlabel->read($arg_array[0]);
		$uid['num'] = $this->whlabel->find_count('purchase = "'.$uid['purchase']. '" and sku = "'.$uid['sku']. '" and warehouse = "'.$uid['warehouse']. '" and zd = "" and state = 0');
		$this->data['data'] = $uid ;
		$this->_Template('whlabel_kj',$this->data);
	}
	public function _summary($arg_array)
	{
		$prc = array();
		$purchase = $this->purchase->find_all();
		foreach($purchase as $k=>$v)
		{
			$prc[$v['id']] = $v['title'];
		}
		if(isset($_GET['excel']))  
		{
			$ktime = $this->input->get('ktime',true);
			$jtime = $this->input->get('jtime',true);
			$ktime = strtotime($ktime);
			$jtime = strtotime($jtime);
			$where = "1=1";
			if($ktime && $jtime)
            {
				$where  .= " and outk > '$ktime' and outk < '$jtime'";
            }
            //数据排序
            $order_str = "time desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
			$info_list = $this->whlabel->find_pc($where,'sku','warehouse,purchase,details,cpid,sku,title');
			foreach ($info_list as $key=>$value) 
		    {
				$info_list[$key]['purchase'] = (isset($prc[$value['purchase']]))?$prc[$value['purchase']]:'未知';
				$warehouse = $this->warehouse->read($value['warehouse']);
				$info_list[$key]['warehouse'] = $warehouse['title'];
				$x = $this->whlabel->find_all($where.' and sku = "'.$value['sku'].'"','details,cpid');
				$details = array();
					$cpid = array();
					foreach ($x as $k=>$v) 
		    		{
						if($v['details'] != '')
						{
						    $details[$v['details']] = $v['details'];
						}
						if($v['cpid'] != 0)
						{
					    	$cpid[$v['cpid']] = $v['cpid'];
						}
					}
				$info_list[$key]['details'] = ($details)?implode(" ",$details):'';
				$info_list[$key]['cpid'] = ($cpid)?implode(" ",$cpid):'';
				$s = $this->whlabel->find_count('state = 0 and sku = "'.$value['sku'].'"');
				$info_list[$key]['s'] = $s;
				$info_list[$key]['x'] = count($x);
			}
            $title = date('Y-m-d',$ktime).'至'.date('Y-m-d',$jtime).'出库汇总详情'; 
            $titlename = "
            
			| 仓库 | 供应商 | 出库位置 | 出库编码 | SKU | 产品名 | 总剩余库存 | ".date('Y-m-d',$ktime).'至'.date('Y-m-d',$jtime)."销售数量 | 
            
"; 
            $filename = $title.".xls";
			$tail = "";
            $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
	    }
	}
	//usps发货清单
	public function _manifest()
	{
		if(isset($_POST['manifest']))  
		{
			$wltext = $this->input->post('wltext',true);
			$time = time()-16*3600;
			$ptime = strtotime(date('Y-m-d',$time));
			$waybill = array();
			$fullorder = $this->fullorder->find_all("printtime > '$ptime' and librarytime > '$ptime' and library = 2 and waybill != '' and (type = 5 or type = 8)",'number,waybill');
			foreach ($fullorder as $v) 
		    {
				$waybill[$v['waybill']] = $v['waybill'];
		    }
			$fullordersmt = $this->fullordersmt->find_all("printtime > '$ptime' and librarytime > '$ptime' and library = 2 and waybill != '' and (type = 5 or type = 8)",'number,waybill');
			foreach ($fullordersmt as $v) 
		    {
				$waybill[$v['waybill']] = $v['waybill'];
		    }
			$wltext = explode(';',$wltext);
			foreach ($wltext as $v) 
		    {
				if(isset($waybill[$v]))
				{
					unset($waybill[$v]);
				}
			}
			$data = $this->usps->get_manifest($waybill);
			if(isset($data['Description']))
			{
				echo json_encode(array('msg'=>$data['Description'],'success'=>false));exit;
			}
			else if(isset($data['SCANFormImage']) && isset($data['SCANFormNumber']))
			{
				$bctime = date('Ymd',time());
				$pdf = $this->_pdf($data['SCANFormImage'],$data['SCANFormNumber'],$bctime);
				echo json_encode(array('msg'=>$pdf,'success'=>true));exit;
			}
			else
			{
				echo json_encode(array('msg'=>$data,'success'=>false));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 'http://'.$_SERVER['HTTP_HOST'].'/data/pdf/'.$bctime.'/'.$title.'.pdf';
    }
	
	
	
	
	/**
	*
	*
	*
	进销存占单异常索引
	*
	*
	*
	**/
	
	public function _abnormal()
	{
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$sku = $this->input->post('sku',true);
			$where = "1=1";
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            $info_list = $this->whlabel->find_all($where,'*');
			$rows = array();$list = array();
			foreach ($info_list as $key=>$value) 
		    {
				$rows[strtolower($value['sku'])] = $value;//所有数据sku
		    }
			foreach ($rows as $value) 
		    {
				$warehouse = $this->warehouse->read($value['warehouse']);
				$c = $this->whlabel->find_count('sku = "'.$value['sku'].'" and state = "0" and warehouse = "5"');
				$number = $value['number'];$ftime = time()-15*24*3600;
				if($value['shop'] != '')
				{
					$shop = $value['shop'];
					$orderdlz = $this->fullorder->find_all("time > '$ftime' and shop = '$shop' and type = '5' and library = '1' and state = '207' and whlabel like '%|$number-%'",'whlabel,shop,orderinfo,number');
					$ordersmt = $this->fullordersmt->find_all("time > '$ftime' and shop = '$shop' and type = '5' and library = '1' and state = '207' and whlabel like '%|$number-%'",'whlabel,shop,orderinfo,number');
					$order = array_merge($orderdlz,$ordersmt);
					$od = 0;$a = '';$orid = '';
					foreach ($order as $v) 
		        	{
						$or = explode('|',ltrim($v['whlabel'],'|'));
						for($i=0;$ifullorder->find_all("time > '$ftime' and type = '5' and library = '1' and state = '207' and whlabel like '%|$number-%'",'whlabel,shop,orderinfo,number');
					$ordersmt = $this->fullordersmt->find_all("time > '$ftime' and type = '5' and library = '1' and state = '207' and whlabel like '%|$number-%'",'whlabel,shop,orderinfo,number');
					$order = array_merge($orderdlz,$ordersmt);
					$od = 0;$a = '';$orid = '';$qt = array();
					foreach ($order as $v) 
		        	{
						$or = explode('|',ltrim($v['whlabel'],'|'));
						for($i=0;$iwhlabel->find_count("number = '$number' and warehouse = '5' and shop = '".$v['shop']."' and state = 0");
								if($czzs > 0)
								{
									if(isset($qt[$v['shop']]))
									{
										if($qt[$v['shop']] < $orod[1])
										{
											$od += $orod[1];//专属小于单量不计算剩余直接归入通用
											$orid .= $v['number'].'+数量'.$orod[1].'-';
										}
										else
										{
											$qt[$v['shop']] -= $orod[1];
										}
									}
									else
									{
										$qt[$v['shop']] = $czzs;
									}
								}
								else
								{
								    $od += $orod[1];
									$orid .= $v['number'].'+数量'.$orod[1].'-';
								}
							}
						}
					}
				}
				$z = $od.'('.$orid.')';//查看订单号
				//$z = $od;
				if($od > $c)
				{
				    $list[] = array('id'=>$value['id'],'warehouse'=>$warehouse['title'],'sku'=>$value['sku'],'title'=>$value['title'],'c'=>$c,'z'=>$z);
				}
		    }
			$listdata = array_slice($list,$start,$perpage);
		    $total = count($list);
		    $pagenum = ceil($total/$perpage);
		    $over = $total-($start+$perpage);
		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($listdata));
		    echo json_encode($rows);exit;
		}
		$this->_Template('whlabel_abnormal',$this->data);
	}
	/**
	*
	*
	*
	进销存占单异常索引
	*
	*
	*
	**/
	
	public function _error()
	{
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$sku = $this->input->post('sku',true);
			$warehouse = $this->input->post('warehouse',true);
			$ktime = $this->input->post('ktime',true);
			$jtime = $this->input->post('jtime',true);
			$ktime = strtotime($ktime);
			$jtime = strtotime($jtime);
			$where = "sku != 'Preset'";
			$gj = '';
			if($sku)
            {
                $where  .= " and sku like '%$sku%'";
            }
			else
			{
				if($ktime && $jtime)
            	{
                	$gj  = " and time > '$ktime' and time < '$jtime'";
            	}
			}
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            //$info_list = $this->whlabel->find_all($where.$gj,'*');
			$rows = array();$list = array();
			$info_list = $this->whlabel->find_pc($where,'warehouse,features,sku','*');
// 			foreach ($info_list as $value) 
// 		    {
// 				$warehouse = $this->warehouse->read($value['warehouse']);
// 				$c = $this->whlabel->find_count('sku = "'.$value['sku'].'" and state = "0" and warehouse = "'.$value['warehouse'].'"');
// 				$number = $value['number'];$ftime = time()-15*24*3600;
// 				if($c < 1)
// 				{
// 				    $list[] = array('id'=>$value['id'],'warehouse'=>$warehouse['title'],'sku'=>$value['sku'],'title'=>$value['title'],'c'=>$c);
// 				}
// 		    }
		    
		    
		    $warehouse_list =  $this->warehouse->find_all();
		    $warehouse_list = array_column($warehouse_list,null,'id');
		    
			foreach ($info_list as $value) 
		    {
				$warehouse = isset($warehouse_list[$value['warehouse']])?$warehouse_list[$value['warehouse']]:[
				        'title'=>"",
				    ];
				$c = $this->whlabel->find_count('sku = "'.$value['sku'].'" and state = "0" and warehouse = "'.$value['warehouse'].'"');
				$number = $value['number'];$ftime = time()-15*24*3600;
				if($c < 1)
				{
				    $list[] = array('id'=>$value['id'],'warehouse'=>$warehouse['title'],'sku'=>$value['sku'],'title'=>$value['title'],'c'=>$c);
				}
		    }
//             $sql = "select id,warehouse,features,sku,number,title from crowd_whlabel where ".$where;
// 			$query = $this->db->query($sql);
			
// 			$info_list = $query->result_array();
// 			$sql_two = "select title,id from crowd_warehouse";
// 			$query_two = $this->db->query($sql_two);
// 			$warehouse_list = $query_two->result_array();
// 			$warehouse_arr = array_column($warehouse_list,null,'id');
// 			foreach ($info_list as $value) 
// 		    {
// 				if(isset($warehouse_arr[$value['warehouse']])){
// 					$warehouse = $warehouse_arr[$value['warehouse']];
// 				}else{
// 					$warehouse = [
// 						'id'=>0,
// 						'title'=>"异常",
// 					];
// 				}
// 				$c = $this->whlabel->find_count('sku = "'.$value['sku'].'" and state = "0" and warehouse = "'.$value['warehouse'].'"');
// 				$number = $value['number'];$ftime = time()-15*24*3600;
// 				if($c < 1)
// 				{
// 				    $list[] = array('id'=>$value['id'],'warehouse'=>$warehouse['title'],'sku'=>$value['sku'],'title'=>$value['title'],'c'=>$c);
// 				}
// 		    }
			$listdata = array_slice($list,$start,$perpage);
		    $total = count($list);
		    $pagenum = ceil($total/$perpage);
		    $over = $total-($start+$perpage);
		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($listdata));
		    echo json_encode($rows);exit;
		}
		if(isset($post['s']))  
		{
            $id_arr = $this->input->post('s');
            $id_arr =  explode(',',trim($id_arr,','));
            if(!$id_arr)
            {
                echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
            }
            //循环删除记录
            foreach ($id_arr as $v) 
		    {
				$dd = $this->whlabel->read($v);
				if(!isset($dd['id']))
				{
					echo json_encode(array('msg'=>$dd['sku'].'已被删除,请刷新页面','success'=>false));exit;
				}
				$zt = $this->whlabeltransport->find_all('sku = "'.$dd['sku'].'" and warehouse = "'.$dd['warehouse'].'" and features = "'.$dd['features'].'" and cz = "0"');
				if(isset($zt[0]))
				{
					echo json_encode(array('msg'=>'有在途库存无法删除!','success'=>false));exit;
				}
				$deldd = $this->whlabel->find_all("sku = '".$dd['sku']."' and warehouse = '".$dd['warehouse']."'");
				 foreach ($deldd as $vv) 
		         {
					 $this->whlabel->remove($vv['id']);
				 }
            }
            echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));exit;
		}
		$this->_Template('whlabel_error',$this->data);
	}
	
	public function _errorexcel()
	{
		$post = $this->input->post(NULL, TRUE);
		if(isset($_GET['page']))  
		{
		    $page = $this->input->get('page',true);
		    $perpage = $this->input->get('perpage',true);
			$sku = $this->input->get('sku',true);
			$warehouse = $this->input->get('warehouse',true);
			$ktime = $this->input->get('ktime',true);
			$jtime = $this->input->get('jtime',true);
			$ktime = strtotime($ktime);
			$jtime = strtotime($jtime);
			$where = "sku != 'Preset'";
			$gj = '';
			if($sku)
            {
                $where  .= " and sku like '%$sku%'";
            }
			else
			{
				if($ktime && $jtime)
            	{
                	$gj  = " and time > '$ktime' and time < '$jtime'";
            	}
			}
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
			$rows = array();$list = array();
			$info_list = $this->whlabel->find_pc($where,'warehouse,features,sku','*');
			foreach ($info_list as $value) 
		    {
				$warehouse = $this->warehouse->read($value['warehouse']);
				$c = $this->whlabel->find_count('sku = "'.$value['sku'].'" and state = "0" and warehouse = "'.$value['warehouse'].'"');
				$number = $value['number'];$ftime = time()-15*24*3600;
				if($c < 1)
				{
				    $list[] = array('warehouse'=>$warehouse['title'],'sku'=>$value['sku'],'title'=>$value['title'],'c'=>$c);
				}
		    }
			$title = "0库存汇总"; 
            $titlename = ""; 
            $filename = $title.".xls";
			$tail = "";
            $this->excel->get_fz2($list,$titlename,$filename,$tail);
		}
	}
/**
*
*
* 占单
*
*
**/
    public function _kcyz()
	{
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['warehouse']))  
		{
			return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'请更新浏览器缓存!','success'=>false)));exit;//不再使用
			$warehouse = $this->input->post('warehouse',true);
		    $whlabel = $this->input->post('whlabel',true);
			$id = $this->input->post('id',true);
			$shop = $this->input->post('shop',true);
			$number = $this->input->post('number',true);
			if(!$whlabel || $whlabel == '|')
			{
				return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'请先添加产品信息!','success'=>false)));exit;
			}
			$pp = explode('|',trim($whlabel,'|'));
			$x = 0;$save = array();
			foreach ($pp as $va)
			{
				$num = explode('-',$va);
				if($number)
				{
				    $whlabel = $this->whlabel->find_all("state = 0 and number = '$num[0]' and warehouse = '$warehouse' and (zd = '$number' or zd = '') and (shop IS NULL or shop = '')");//通用
				    $shopwhlabel = $this->whlabel->find_all("state = 0 and number = '$num[0]' and warehouse = '$warehouse' and (zd = '$number' or zd = '') and shop like '%,".$shop.",%'");//专属
				}
				else
				{
					$whlabel = $this->whlabel->find_all("state = 0 and number = '$num[0]' and warehouse = '$warehouse' and zd = '' and (shop IS NULL or shop = '')");//通用
				    $shopwhlabel = $this->whlabel->find_all("state = 0 and number = '$num[0]' and warehouse = '$warehouse' and zd = '' and shop like '%,".$shop.",%'");//专属
				}
				$x++;
				if(count($whlabel)+count($shopwhlabel) < $num[1])
				{
					$save[] = $x-1;continue;//提前先加X不然出错,所以要减1
				}
			}
			if(isset($save[0]))
            {
				echo json_encode(array('t'=>2,'msg'=>"红色商品名库存匹配错误或库存不够扣减",'error'=>$save,'success'=>false));exit;
            }
			else
			{
				echo json_encode(array('success'=>true));exit;
			}
		}
	}
	
	public function _db()
	{
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$sku = $this->input->post('sku',true);
			$number = $this->input->post('number',true);
			$warehouse = $this->input->post('warehouse',true);
			$purchase = $this->input->post('purchase',true);
			$orderinfo = $this->input->post('orderinfo',true);
			$waybill = $this->input->post('waybill',true);
			$category = $this->input->post('category',true);
			$size = $this->input->post('size',true);
			$grade = $this->input->post('grade',true);
			$color = $this->input->post('color',true);
			$lowe = $this->input->post('lowe',true);
			$state = $this->input->post('state',true);
			$label = $this->input->post('label',true);
			$timetk = $this->input->post('timetkk',true);
			$timetj = $this->input->post('timetjj',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			$where = "dbtime > 0";
			if($timetk && $timetj)
            {
                $where .= " and dbtime > '$timetk' and dbtime < '$timetj'";
            }
			if($sku)
            {
                $where  .= " and sku = '$sku'";
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
				if($warehouse == 12)
				{
					$w = 'specialstock';
				}
				else
				{
					$w = 'whlabel';
				}
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($state != '')
            {
                $where  .= " and state = '$state'";
            }
            //数据排序
            $order_str = "dbtime desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            $info_list = $this->$w->find_all($where,'id,state,purchase,sku,title,warehouse,dbtime,enter',$order_str,$start,$perpage);
			foreach ($info_list as $key=>$value) 
		    {
				$warehouse = $this->$w->read($value['warehouse']);
				$info_list[$key]['warehouse'] = $warehouse['title'];
				$purchase = $this->purchase->read($value['purchase']);
				$info_list[$key]['purchase'] = $purchase['title'];
				if($value['enter'] != 0)
				{
					$info_list[$key]['enter'] = ''.date('Y-m-d H:i:s',$value['enter']).'
';
				}
				else
				{
					$info_list[$key]['enter'] = "";
				}
				if($value['dbtime'] != 0)
				{
					$info_list[$key]['dbtime'] = ''.date('Y-m-d H:i:s',$value['dbtime']).'
';
				}
				else
				{
					$info_list[$key]['dbtime'] = "";
				}
				
				if($value['state'] == 0)
				{
					$info_list[$key]['state'] = "在库";
				}
				else if($value['state'] == 1)
				{
					$info_list[$key]['state'] = "出库";
				}
				else if($value['state'] == 2)
				{
					$info_list[$key]['state'] = "退库";
				}
				else if($value['state'] == 3)
				{
					$info_list[$key]['state'] = "调拨中";
				}
				else if($value['state'] == 4)
				{
					$info_list[$key]['state'] = "再加工";
				}
				else if($value['state'] == 5)
				{
					$info_list[$key]['state'] = "维修中";
				}
				else if($value['state'] == 6)
				{
					$info_list[$key]['state'] = "盘亏";
				}
				else if($value['state'] == 7)
				{
					$info_list[$key]['state'] = "更换标签";
				}
				else if($value['state'] == 8)
				{
					$info_list[$key]['state'] = "其它";
				}
				else if($value['state'] == 9)
				{
					$info_list[$key]['state'] = "预设";
				}
				
		    }
		    $total = $this->whlabel->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($post['outsku']))  
		{
			$time = time();
			$cz = $this->input->post('cz',true);
			$label = $this->input->post('outsku',true);
			$sl = $this->input->post('sl',true);
			$num = $this->input->post('num',true);
			//$warehouse = $this->input->post('warehouse',true);
			if(!$sl)
			{
				$sl = 1;
			}
			if(!$warehouse)
			{
				echo json_encode(array('msg'=>'请选择调拨到的仓库','success'=>false));exit;
			}
			$dblabel = $this->whlabellabel->get_label($label);
			if($dblabel)
			{
			   $data = $this->whlabel->find_all("features = '".$dblabel['features']."' and warehouse = '".$dblabel['warehouse']."' and shop = '".$dblabel['shop']."' and state = '0' and zd = ''");
			   if(count($data) < 1)
			   {
				   echo json_encode(array('msg'=>'没有此产品数据!','success'=>false));exit;
			   }
			   if(count($data) < $num)
			   {
				   echo json_encode(array('msg'=>'库存数量少于调拨数量!','success'=>false));exit;
			   }
			   for($i=0;$i<$sl;$i++)
			   {
				   $this->whlabel->save(array('state'=>3,'dbtime'=>$dbtime,'dbcontent'=>$data[$i]['warehouse'].'-'.$time.'|','time'=>$time),$data[$i]['id']);
			   }
			   echo json_encode(array('success'=>true));exit;
			}
			else
			{
				echo json_encode(array('msg'=>'未找到此条码产品!','success'=>false));exit;
			}
		}
		$this->data['url'] = str_replace('/','',$this->uri->slash_segment(2));
		$this->_Template('whlabel_db',$this->data);
	}
	
	public function _dbrk()
	{
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$sku = $this->input->post('sku',true);
			$number = $this->input->post('number',true);
			$warehouse = $this->input->post('warehouse',true);
			$purchase = $this->input->post('purchase',true);
			$orderinfo = $this->input->post('orderinfo',true);
			$waybill = $this->input->post('waybill',true);
			$category = $this->input->post('category',true);
			$size = $this->input->post('size',true);
			$grade = $this->input->post('grade',true);
			$color = $this->input->post('color',true);
			$lowe = $this->input->post('lowe',true);
			$state = $this->input->post('state',true);
			$label = $this->input->post('label',true);
			$ctime = $this->input->post('ctime',true);
			$timetk = $this->input->post('timetkk',true);
			$timetj = $this->input->post('timetjj',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			$where = "dbtime > 0";
			if($timetk && $timetj)
            {
                $where .= " and ".$ctime." > '$timetk' and ".$ctime." < '$timetj'";
            }
			if($sku)
            {
                $where  .= " and sku = '$sku'";
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($state != '')
            {
                $where  .= " and state = '$state'";
            }
            //数据排序
            $order_str = "dbtime desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            $info_list = $this->whlabel->find_all($where,'id,state,purchase,sku,title,warehouse,dbtime,enter',$order_str,$start,$perpage);
			foreach ($info_list as $key=>$value) 
		    {
				$warehouse = $this->warehouse->read($value['warehouse']);
				$info_list[$key]['warehouse'] = $warehouse['title'];
				$purchase = $this->purchase->read($value['purchase']);
				$info_list[$key]['purchase'] = $purchase['title'];
				if($value['enter'] != 0)
				{
					$info_list[$key]['enter'] = ''.date('Y-m-d H:i:s',$value['enter']).'
';
				}
				else
				{
					$info_list[$key]['enter'] = "";
				}
				if($value['dbtime'] != 0)
				{
					$info_list[$key]['dbtime'] = ''.date('Y-m-d H:i:s',$value['dbtime']).'
';
				}
				else
				{
					$info_list[$key]['dbtime'] = "";
				}
				
				if($value['state'] == 0)
				{
					$info_list[$key]['state'] = "在库";
				}
				else if($value['state'] == 1)
				{
					$info_list[$key]['state'] = "出库";
				}
				else if($value['state'] == 2)
				{
					$info_list[$key]['state'] = "退库";
				}
				else if($value['state'] == 3)
				{
					$info_list[$key]['state'] = "调拨中";
				}
				else if($value['state'] == 4)
				{
					$info_list[$key]['state'] = "再加工";
				}
				else if($value['state'] == 5)
				{
					$info_list[$key]['state'] = "维修中";
				}
				else if($value['state'] == 6)
				{
					$info_list[$key]['state'] = "盘亏";
				}
				else if($value['state'] == 7)
				{
					$info_list[$key]['state'] = "更换标签";
				}
				else if($value['state'] == 8)
				{
					$info_list[$key]['state'] = "其它";
				}
				else if($value['state'] == 9)
				{
					$info_list[$key]['state'] = "预设";
				}
				
		    }
		    $total = $this->whlabel->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($post['rsku']))  
		{
			$cz = $this->input->post('cz',true);
			$label = $this->input->post('rsku',true);
			$sl = $this->input->post('sl',true);
			$warehouse = $this->input->post('warehouse',true);
			if(!$sl)
			{
				$sl = 1;
			}
			if(!$warehouse)
			{
				echo json_encode(array('msg'=>'请选择入库仓库','success'=>false));exit;
			}
			$dblabel = $this->whlabellabel->get_label($label);
			if($dblabel)
			{
			   $data = $this->whlabel->find_all("features = '".$dblabel['features']."' and warehouse = '".$dblabel['warehouse']."' and shop = '".$dblabel['shop']."' and state = '3' and zd = ''");
			   if(count($data) < 1)
			   {
				   echo json_encode(array('msg'=>'没有此SKU调拨数据!','success'=>false));exit;
			   }
			   if($sl > count($data))
			   {
				   echo json_encode(array('msg'=>'入库数量大于调拨数量!','success'=>false));exit;
			   }
			   $time = time();
			   for($i=0;$i<$sl;$i++)
			   {
				   $this->whlabel->save(array('state'=>0,'dbwarehouse'=>$data[$i]['warehouse'],'warehouse'=>$warehouse,'enter'=>$time,'time'=>$time,'dbcontent'=>$data[$i]['dbcontent'].$warehouse.'-'.$time.'|',),$data[$i]['id']);
			   }
			   echo json_encode(array('success'=>true));exit;
			}
			else
			{
				echo json_encode(array('msg'=>'没有此条码的库存信息!','success'=>false));exit;
			}
		}
		$this->data['url'] = str_replace('/','',$this->uri->slash_segment(2));
		$this->_Template('whlabel_dbrk',$this->data);
	}
	
	
	public function _whlabelczdc()
	{
		if(isset($_GET['excel']))  
		{
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
			$state = $this->input->get('state',true);
			$sku = $this->input->get('sku',true);
			$ctime = $this->input->get('ctime',true);
			$category = $this->input->get('category',true);
			$size = $this->input->get('size',true);
			$grade = $this->input->get('grade',true);
			$color = $this->input->get('color',true);
			$lowe = $this->input->get('lowe',true);
			$timetk = $this->input->get('timetkk',true);
			$timetj = $this->input->get('timetjj',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			$where = "dbtime > 0";
			if($timetk && $timetj)
            {
                $where .= " and dbtime > '$timetk' and dbtime < '$timetj'";
            }
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
            //取得信息列表
           $info_list = $this->whlabel->find_all($where,'*');
			$rows = array();$list = array();
			foreach ($info_list as $key=>$value) 
		    {
				$rows[$value['sku']] = $value;//所有数据sku
		    }
			foreach ($rows as $value) 
		    {
				$warehouse = $this->warehouse->read($value['warehouse']);
				$db = $this->whlabel->find_count($where.' and sku = "'.$value['sku'].'"');
				$rk = $this->whlabel->find_count($where.' and sku = "'.$value['sku'].'" and enter > 0');
				if($value['orderinfo'] == 0)
				{
					$info_list[$key]['orderinfo'] = "";
				}
				if($value['waybill'] == 0)
				{
					$info_list[$key]['waybill'] = "";
				}
				
				if($value['state'] == 0)
				{
					$value['state'] = "在库";
				}
				else if($value['state'] == 3)
				{
					$value['state'] = "调拨中";
				}
				$list[] = array($value['sku'],$value['title'],$db,$rk);
		    }
            $title = date('Y-m-d',$timetk).'至'.date('Y-m-d',$timetj)."统计表"; 
            $titlename = "
            | ".$title." | 
|---|
            
			| SKU | 产品 | 调拨数量 | 入库数量 | 
            
"; 
            $filename = $title.".xls";
			$tail = "";
            $this->excel->get_fz2($list,$titlename,$filename,$tail);
	    }
	}
	
	public function _print($arg_array)
	{
		if(isset($_SESSION['api']))
		{
			$user = $this->user->get_api($_SESSION['api']);
			$usp = $user;
		    $fgshop = "";$sid = "";$wid="";$wtype="";
		    $usersp = explode('|',trim($user['shop'],'|'));
			$userwh = explode('|',trim($user['warehouse'],'|'));
			foreach ($usersp as $value) 
		    {
				$fgshop .= " shop = ".$value." or";
				$sid .= " id = ".$value." or";
			}
			foreach ($userwh as $value) 
		    {
				$wid .= " id = ".$value." or";
				$wtype .= " type = ".$value." or";
			}
		}
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['tmsku']))
		{
			$tmsku = $this->input->post('tmsku',true);
			if(is_numeric($tmsku))
			{
				$yyh = $this->whlabellabel->get_label($tmsku);
			}
			else
			{
				$yyh = $this->whlabellabel->get_sku($tmsku);
			}
			if($yyh)
			{
				echo json_encode(array('features'=>$yyh['features'],'success'=>true));exit;
			}
			else
			{
				echo json_encode(array('success'=>false));exit;
			}
		}
		$classid = $this->classid->sku();
		$pm = $classid;
		$scsku = $classid;
		//等级-真人发类型-颜色-花型-蕾丝头套种类-多尺寸-单尺寸-Clip类型-礼物类型-马尾类型-重量-长度-头路设计-蕾丝尺寸25-蕾丝尺寸26-类型-密度-发帽大小-蕾丝颜色-头套其它属性-头套属性 100为头套额外
		if(isset($post['warehouse']))
		{
			if($post['warehouse'])
			{
				$list = array();$num = "";$title = "";$features = "";
				$order = 0;
				$post['shop'] = '';
				$brand = $this->input->post('brand',true);
				if($brand != '0,')
				{
					$b = $this->brand->read(rtrim($brand,','));
					if($b)
					{
						$post['shop'] = str_replace('|',',',$b['shop']);
					}
				}
				$post['details'] = $this->input->post('details',true);//打印数量
				$xbqnum = $this->input->post('xbqnum',true);
				$post['purchase'] = $this->input->post('purchase',true);
				$post['warehouse'] = $this->input->post('warehouse',true);
				$post['purchase'] = $this->input->post('purchase',true);
				$post['retreatwarehouse'] = $post['warehouse'];
				$post['cpbz'] = $this->input->post('cpbz',true);
				$post['state'] = 9;
				$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);
				$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);
				$list['weight'] = $this->input->post('weight',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']]))
						{
							if(stripos($typeclass['zh'],'|') !== false)
							{
								$exzh = explode('|',$typeclass['zh']);
								$pm[$typeclass['classid']] = $exzh[0];
							}
							else
							{
						        $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['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['enter'] = $time;
				$post['time'] = $time;//操作时间
				$scsku = implode("-",$scsku);
				$zh = implode(" ",$pm);
				$scsku = str_replace('- ','-',trim($scsku,'-'));
				$scsku = str_replace(array('--------','-------','------','-----','----','---','--'),'-',$scsku);
			$bqsku = (isset($b['title']))?$b['title'].'-'.$scsku:$scsku;;
					$post['sku'] = $bqsku;
					$label = time().rand(0,9);
					$post['label'] = $label;
					$cpid = $this->whlabellabel->find_count();
					$post['cpid'] = $cpid+1;
					$cpid = $post['cpid'];
					//$whlabelbarcode = $this->whlabelbarcode->get_number($post['number'],$post['warehouse']);
					
					//if($whlabelbarcode)
					//{
						//$post['label'] = $whlabelbarcode['label'];
						//if(!$this->whlabellabel->insert($post))
						//{
						//	echo json_encode(array('msg'=>'错误,请重试!','success'=>false));exit;
						//}
					//}
					//else
					//{
						$this->db->trans_begin();
				        $this->whlabellabel->insert($post);
						//$this->whlabelbarcode->insert($post);
						if ($this->db->trans_status() === TRUE)
       				    {
							$this->db->trans_commit();
						}
						else
						{
							$this->db->trans_rollback();
							echo json_encode(array('msg'=>'错误,请重试!','success'=>false));exit;
						}
					//}
					$details = ($post['details'] != '')?'位置:('.$post['details'].') '.$cpid.'':'';
					$purchase = $this->purchase->read($post['purchase']);
				echo json_encode(array('title'=>$title,'num'=>$post['label'],'bqsku'=>$bqsku,'xbqnum'=>$xbqnum,'zh'=>str_replace('自然色 ','',rtrim($zh,' ')),'details'=>$details,'purchase'=>$purchase['title'],'cpbz'=>$post['cpbz'],'usa'=>0,'success'=>true));exit;//特殊仓目前不需要仓库选项
			}
		}
		if(isset($_SESSION['api']))
		{
			$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
			$warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");
		    $this->data['wlshop'] = $wlshop;
		    $this->data['warehouse'] = $warehouse;
		}
		$whlabelwz = $this->whlabelwz->find_all();
		$this->data['whlabelwz'] = $whlabelwz;
		$this->_Template('whlabel_print',$this->data);
	}
	
	
	public function _usaprint($arg_array)
	{
		if(isset($_SESSION['api']))
		{
			$user = $this->user->get_api($_SESSION['api']);
			$usp = $user;
		    $fgshop = "";$sid = "";$wid="";$wtype="";
		    $usersp = explode('|',trim($user['shop'],'|'));
			$userwh = explode('|',trim($user['warehouse'],'|'));
			foreach ($usersp as $value) 
		    {
				$fgshop .= " shop = ".$value." or";
				$sid .= " id = ".$value." or";
			}
			foreach ($userwh as $value) 
		    {
				$wid .= " id = ".$value." or";
				$wtype .= " type = ".$value." or";
			}
		}
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['tmsku']))
		{
			$tmsku = $this->input->post('tmsku',true);
			if(is_numeric($tmsku))
			{
				$yyh = $this->whlabellabel->get_label($tmsku);
			}
			else
			{
				$yyh = $this->whlabellabel->get_sku($tmsku);
			}
			if($yyh)
			{
				echo json_encode(array('features'=>$yyh['features'],'success'=>true));exit;
			}
			else
			{
				echo json_encode(array('success'=>false));exit;
			}
		}
		$classid = $this->classid->sku();
		$pm = $classid;
		$scsku = $classid;
		//等级-真人发类型-颜色-花型-蕾丝头套种类-多尺寸-单尺寸-Clip类型-礼物类型-马尾类型-重量-长度-头路设计-蕾丝尺寸25-蕾丝尺寸26-类型-密度-发帽大小-蕾丝颜色-头套其它属性-头套属性 100为头套额外
		if(isset($post['warehouse']))
		{
			if($post['warehouse'])
			{
				$list = array();$num = "";$title = "";$features = "";
				$order = 0;
				$post['shop'] = '';
				$brand = $this->input->post('brand',true);
				if($brand != '0,')
				{
					$b = $this->brand->read(rtrim($brand,','));
					if($b)
					{
						$post['shop'] = str_replace('|',',',$b['shop']);
					}
				}
				$post['details'] = $this->input->post('details',true);//打印数量
				$xbqnum = $this->input->post('xbqnum',true);
				$post['purchase'] = $this->input->post('purchase',true);
				$post['warehouse'] = $this->input->post('warehouse',true);
				$post['purchase'] = $this->input->post('purchase',true);
				$post['retreatwarehouse'] = $post['warehouse'];
				$post['cpbz'] = $this->input->post('cpbz',true);
				$post['state'] = 9;
				$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);
				$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);
				$list['weight'] = $this->input->post('weight',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']]))
						{
							if(stripos($typeclass['zh'],'|') !== false)
							{
								$exzh = explode('|',$typeclass['zh']);
								$pm[$typeclass['classid']] = $exzh[0];
							}
							else
							{
						        $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['title'] = rtrim($title,' ');
				$post['number'] = $num;
				$post['features'] = '-'.$features;
				$fp = $this->whlabel->get_features($post['features']);
				if(!$fp)
				{
					echo json_encode(array('msg'=>'美仓无此产品,需要添加后才可打印','success'=>false));exit;
				}
				$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['enter'] = $time;
				$post['time'] = $time;//操作时间
				$scsku = implode("-",$scsku);
				$zh = implode(" ",$pm);
				$scsku = str_replace('- ','-',trim($scsku,'-'));
				$scsku = str_replace(array('--------','-------','------','-----','----','---','--'),'-',$scsku);
			$bqsku = (isset($b['title']))?$b['title'].'-'.$scsku:$scsku;;
					$post['sku'] = $fp['sku'];
					$post['label'] = $fp['sku'];
					$cpid = $this->whlabellabel->find_count();
					$post['cpid'] = $cpid+1;
					$cpid = $post['cpid'];
					//$whlabelbarcode = $this->whlabelbarcode->get_number($post['number'],$post['warehouse']);
					
					//if($whlabelbarcode)
					//{
						//$post['label'] = $whlabelbarcode['label'];
						//if(!$this->whlabellabel->insert($post))
						//{
						//	echo json_encode(array('msg'=>'错误,请重试!','success'=>false));exit;
						//}
					//}
					//else
					//{
						$this->db->trans_begin();
				        $this->whlabellabel->insert($post);
						//$this->whlabelbarcode->insert($post);
						if ($this->db->trans_status() === TRUE)
       				    {
							$this->db->trans_commit();
						}
						else
						{
							$this->db->trans_rollback();
							echo json_encode(array('msg'=>'错误,请重试!','success'=>false));exit;
						}
					//}
					$details = ($post['details'] != '')?'位置:('.$post['details'].') '.$cpid.'':'';
					$purchase = $this->purchase->read($post['purchase']);
				echo json_encode(array('title'=>$title,'num'=>$post['label'],'bqsku'=>$bqsku,'xbqnum'=>$xbqnum,'zh'=>str_replace('自然色 ','',rtrim($zh,' ')),'details'=>$details,'purchase'=>$purchase['title'],'cpbz'=>$post['cpbz'],'usa'=>1,'success'=>true));exit;//特殊仓目前不需要仓库选项
			}
		}
		if(isset($_SESSION['api']))
		{
			$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
			$warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");
		    $this->data['wlshop'] = $wlshop;
		    $this->data['warehouse'] = $warehouse;
		}
		$whlabelwz = $this->whlabelwz->find_all();
		$this->data['whlabelwz'] = $whlabelwz;
		$this->_Template('whlabel_usaprint',$this->data);
	}
	
	
	public function _printrk($arg_array)
	{
		$prc = array();
		$purchase = $this->purchase->find_all();
		foreach($purchase as $k=>$v)
		{
			$prc[$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);
			$sku = $this->input->post('sku',true);
			$bs = $this->input->post('bs',true);
			$number = $this->input->post('number',true);
			$warehouse = $this->input->post('warehouse',true);
			$purchase = $this->input->post('purchase',true);
			$orderinfo = $this->input->post('orderinfo',true);
			$waybill = $this->input->post('waybill',true);
			$category = $this->input->post('category',true);
			$size = $this->input->post('size',true);
			$grade = $this->input->post('grade',true);
			$color = $this->input->post('color',true);
			$lowe = $this->input->post('lowe',true);
			$state = $this->input->post('state',true);
			$label = $this->input->post('label',true);
			$timetk = $this->input->post('ktime',true);
			$timetj = $this->input->post('jtime',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			$where = "1=1 ";
			if($timetk && $timetj)
            {
                $where .= " and enter > '$timetk' and enter < '$timetj'";
            }
			if($sku)
            {
                $where  .= " and sku = '$sku'";
            }
			if($bs != '')
            {
                $where  .= " and bs = '$bs'";
            }
			if($number)
            {
                $where  .= " and number = '$number'";
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($orderinfo)
            {
                $where  .= " and orderinfo = '$orderinfo'";
            }
			if($waybill)
            {
                $where  .= " and waybill = '$waybill'";
            }
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($label)
            {
                $where  .= " and label = '$label'";
            }
			if($state || $state == 0)
            {
                $where  .= " and state = '$state'";
            }
			$ck = ($warehouse == '12')?'specialstock':'whlabel';
            //数据排序
            $order_str = "enter desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            $info_list = $this->$ck->find_all($where,'id,warehouse,purchase,sku,title,state,enter,details',$order_str,$start,$perpage);
			foreach ($info_list as $key=>$value) 
		    {
				$warehouse = $this->warehouse->read($value['warehouse']);
				$info_list[$key]['warehouse'] = ($ck=='specialstock')?'特殊仓':$warehouse['title'];
				$info_list[$key]['purchase'] = (isset($prc[$value['purchase']]))?$prc[$value['purchase']]:'未知';
				if($value['state'] == 0)
				{
					$info_list[$key]['state'] = "在库";
				}
				else if($value['state'] == 1)
				{
					$info_list[$key]['state'] = "出库";
				}
				else if($value['state'] == 2)
				{
					$info_list[$key]['state'] = "退库";
				}
				else if($value['state'] == 3)
				{
					$info_list[$key]['state'] = "调拨中";
				}
				else if($value['state'] == 4)
				{
					$info_list[$key]['state'] = "再加工";
				}
				else if($value['state'] == 5)
				{
					$info_list[$key]['state'] = "维修中";
				}
				else if($value['state'] == 6)
				{
					$info_list[$key]['state'] = "盘亏";
				}
				else if($value['state'] == 7)
				{
					$info_list[$key]['state'] = "更换标签";
				}
				else if($value['state'] == 8)
				{
					$info_list[$key]['state'] = "其它";
				}
				else if($value['state'] == 9)
				{
					$info_list[$key]['state'] = "预设";
				}
				else if($value['state'] == 10)
				{
					$info_list[$key]['state'] = "美店零售";
				}
				$info_list[$key]['enter'] = date('Y-m-d H:i:s',$value['enter']);
		    }
		    $total = $this->$ck->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($post['tmsku']))
		{
			$time = time();
			$tmsku = $this->input->post('tmsku',true);
			//$post['shop'] = $this->input->post('shop',true);
			$num = $this->input->post('num',true);
			$rktype = $this->input->post('rktype',true);
			if($num > 200)
			{
				echo json_encode(array('msg'=>'入库数量不允许超过200!','c'=>0,'success'=>false));exit;
			}
			if(!$rktype)
			{
				//echo json_encode(array('msg'=>'请选择入库类型!','c'=>0,'success'=>false));exit;
			}
			$rk = $this->whlabellabel->find_all("label = '$tmsku'","*","id desc");
			/**
			$wz = array();
			foreach ($rk as $key=>$value) 
		    {
				$wz[$value['details']] = array('details'=>$value['details'],'id'=>$value['id']);
			}
			if(count($wz) > 1)
			{
				$wz = array_values($wz);
				echo json_encode(array('msg'=>'此条码有多个位置,请选择','wz'=>$wz,'c'=>1,'success'=>false));exit;
			}
			**/
			if(isset($rk[0]['purchase']))
			{
				$rk = $rk[0];
				$j = 0;
				$post['purchase'] = $rk['purchase'];
				$post['warehouse'] = $rk['warehouse'];
				$post['retreatwarehouse'] = $rk['warehouse'];
				$post['sku'] = $rk['sku'];
				$post['number'] = $rk['number'];
				$post['features'] = $rk['features'];
				$post['title'] = $rk['title'];
				$post['enter'] = $time;
				$post['time'] = $time;
				$post['bs'] = 1;
				$post['shop'] = $rk['shop'];
				$post['details'] = $rk['details'];
				$post['cpid'] = $rk['cpid'];
				$post['cpbz'] = $rk['cpbz'];
				//$post['rktype'] = $rktype;
				$warehouse = $this->warehouse->read($rk['warehouse']);
				if($warehouse['bdck'] == '')
				{
					echo json_encode(array('msg'=>'此仓库没有设置现货,无法入库!','c'=>0,'success'=>false));exit;
				}
				else
				{
					$bdck = $warehouse['bdck'];
				}
				$pdwz = $this->whlabel->get_warehousesku($post['warehouse'],$post['sku']);
				if(isset($pdwz['details']))
				{
					if($pdwz['details'] != $post['details'])
					{
						echo json_encode(array('msg'=>'此产品位置应为:'.$pdwz['details'],'c'=>0,'cs'=>$pdwz['details'].' - '.$post['details'],'success'=>false));exit;
					}
				}
					$post['featurespp'] = $rk['featurespp'];
					
			if($post['warehouse'] == '5')
			{
				$yza = $this->whlabel->find_all("sku =  '".$post['sku']."' and warehouse = '".$post['warehouse']."' and shop = '".$post['shop']."'");
				if($yza)
				{
					if($post['features'] != $yza[0]['features'])
					{
						echo json_encode(array('msg'=>'此SKU的产品信息和现有不一致!','new'=>$post['features'].'-'.$post['sku'],'old'=>$yza[0]['features'],'c'=>0,'success'=>false));exit;
					}
				}
				$yzb = $this->whlabel->find_all("features =  '".$post['features']."' and warehouse = '".$post['warehouse']."' and shop = '".$post['shop']."'");
				if($yzb)
				{
					if($post['sku'] != $yzb[0]['sku'])
					{
						echo json_encode(array('msg'=>'此产品信息的SKU和现有'.$yzb[0]['sku'].'不一致!','c'=>0,'success'=>false));exit;
					}
				}
			}
				for($i=0;$i<$num;$i++)
			    {
					$post['label'] = time().rand(100,999).$i;
				    if($this->$bdck->insert($post))
					{
						$j++;
					}
			    }
				/**
				if($post['warehouse'] != 12)
				{
					echo json_encode(array('msg'=>'目前非特殊仓不能入库!','success'=>true));exit;
				}
				**/
				if($j == $num)
				{
					echo json_encode(array('msg'=>'入库成功!','success'=>true));exit;
				}
				else
				{
					echo json_encode(array('msg'=>'未成功入库数量:'.$num-$j.',请补入','c'=>0,'success'=>false));exit;
				}
			}
			else
			{
				echo json_encode(array('msg'=>'未找到此条码数据!','c'=>0,'success'=>false));exit;
			}
		}
		$this->_Template('whlabel_printrk',$this->data);
	}
	public function _printxzrk($arg_array)
	{
		$post = $this->input->post(NULL, TRUE);
	         if(isset($post['wzid']))
		{
			$time = time();
			$id = $this->input->post('wzid',true);
			//$post['shop'] = $this->input->post('shop',true);
			$num = 1;
			$rk = $this->whlabellabel->read($id);
			if(isset($rk['purchase']))
			{
				$x = 0;
				$post['purchase'] = $rk['purchase'];
				$post['warehouse'] = $rk['warehouse'];
				$post['retreatwarehouse'] = $rk['warehouse'];
				$post['sku'] = $rk['sku'];
				$post['number'] = $rk['number'];
				$post['features'] = $rk['features'];
				$post['title'] = $rk['title'];
				$post['enter'] = $time;
				$post['time'] = $time;
				$post['bs'] = 1;
				$post['shop'] = $rk['shop'];
				$post['details'] = $rk['details'];
				$post['cpid'] = $rk['cpid'];
				$post['cpbz'] = $rk['cpbz'];
				$warehouse = $this->warehouse->read($rk['warehouse']);
				if($warehouse['bdck'] == '')
				{
					echo json_encode(array('msg'=>'此仓库没有设置现货,无法入库!','success'=>false));exit;
				}
				else
				{
					$bdck = $warehouse['bdck'];
				}
					$post['featurespp'] = $rk['featurespp'];
					$this->db->trans_begin();
				for($i=0;$i<$num;$i++)
			    {
					$post['label'] = time().rand(100,999).$i;
				    $this->$bdck->insert($post);
			    }
				/**
				if($post['warehouse'] != 12)
				{
					echo json_encode(array('msg'=>'目前非特殊仓不能入库!','success'=>true));exit;
				}
				**/
				if ($this->db->trans_status() === TRUE)
        		{
					$this->db->trans_commit();
					echo json_encode(array('msg'=>'入库成功!','cs'=>$post,'cs2'=>$warehouse,'success'=>true));exit;
				}
				else
				{
					$this->db->trans_rollback();
					echo json_encode(array('msg'=>'入库失败,请重试','c'=>0,'success'=>false));exit;
				}
			}
			else
			{
				echo json_encode(array('msg'=>'未找到此条码数据!','c'=>0,'success'=>false));exit;
			}
		}
	}
	public function _printck($arg_array)
	{
		$prc = array();
		$purchase = $this->purchase->find_all();
		foreach($purchase as $k=>$v)
		{
			$prc[$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);
			$sku = $this->input->post('sku',true);
			$bs = $this->input->post('bs',true);
			$number = $this->input->post('number',true);
			$warehouse = $this->input->post('warehouse',true);
			$purchase = $this->input->post('purchase',true);
			$orderinfo = $this->input->post('orderinfo',true);
			$waybill = $this->input->post('waybill',true);
			$category = $this->input->post('category',true);
			$size = $this->input->post('size',true);
			$grade = $this->input->post('grade',true);
			$color = $this->input->post('color',true);
			$lowe = $this->input->post('lowe',true);
			$state = $this->input->post('state',true);
			$label = $this->input->post('label',true);
			$timetk = $this->input->post('ktime',true);
			$timetj = $this->input->post('jtime',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			$where = "state=1 ";
			if($timetk && $timetj)
            {
                $where .= " and outk > '$timetk' and outk < '$timetj'";
            }
			if($sku)
            {
                $where  .= " and sku = '$sku'";
            }
			if($bs != '')
            {
                $where  .= " and bs = '$bs'";
            }
			if($number)
            {
                $where  .= " and number = '$number'";
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($orderinfo)
            {
                $where  .= " and orderinfo = '$orderinfo'";
            }
			if($waybill)
            {
                $where  .= " and waybill = '$waybill'";
            }
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($label)
            {
                $where  .= " and label = '$label'";
            }
			$ck = ($warehouse == '12')?'specialstock':'whlabel';
            //数据排序
            $order_str = "outk desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
            $info_list = $this->$ck->find_all($where,'id,warehouse,purchase,sku,title,state,outk,details',$order_str,$start,$perpage);
			foreach ($info_list as $key=>$value) 
		    {
				$warehouse = $this->warehouse->read($value['warehouse']);
				$info_list[$key]['warehouse'] = ($ck=='specialstock')?'特殊仓':$warehouse['title'];
				$info_list[$key]['purchase'] = (isset($prc[$value['purchase']]))?$prc[$value['purchase']]:'未知';
				if($value['state'] == 0)
				{
					$info_list[$key]['state'] = "在库";
				}
				else if($value['state'] == 1)
				{
					$info_list[$key]['state'] = "出库";
				}
				else if($value['state'] == 2)
				{
					$info_list[$key]['state'] = "退库";
				}
				else if($value['state'] == 3)
				{
					$info_list[$key]['state'] = "调拨中";
				}
				else if($value['state'] == 4)
				{
					$info_list[$key]['state'] = "再加工";
				}
				else if($value['state'] == 5)
				{
					$info_list[$key]['state'] = "维修中";
				}
				else if($value['state'] == 6)
				{
					$info_list[$key]['state'] = "盘亏";
				}
				else if($value['state'] == 7)
				{
					$info_list[$key]['state'] = "更换标签";
				}
				else if($value['state'] == 8)
				{
					$info_list[$key]['state'] = "其它";
				}
				else if($value['state'] == 9)
				{
					$info_list[$key]['state'] = "预设";
				}
				else if($value['state'] == 10)
				{
					$info_list[$key]['state'] = "美店零售";
				}
				$info_list[$key]['outk'] = date('Y-m-d H:i:s',$value['outk']);
		    }
		    $total = $this->$ck->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($post['tmsku']))
		{
			$time = time();
			$tmsku = $this->input->post('tmsku',true);
			//$post['shop'] = $this->input->post('shop',true);
			$num = $this->input->post('num',true);
			$cktype = $this->input->post('cktype',true);
			$label = $this->whlabellabel->get_label($tmsku);
			if(!$cktype)
			{
				//echo json_encode(array('msg'=>'请选择出库类型!','success'=>false));exit;
			}
			if(!isset($label['warehouse']))
			{
				echo json_encode(array('msg'=>'没有此条码信息!','success'=>false));exit;
			}
			$xzck = ($label['warehouse'] == '12')?'specialstock':'whlabel';
			if(stripos($label['features'],'-126-') !== false)
			{
			    $ck = $this->$xzck->find_all("state = '0' and shop = '".$label['shop']."' and number = '".$label['number']."' and warehouse = '".$label['warehouse']."' and zd = ''");
			}
			else
			{
				$ck = $this->$xzck->find_all("state = '0' and shop = '".$label['shop']."' and number = '".$label['number']."' and warehouse = '".$label['warehouse']."' and purchase = '".$label['purchase']."' and zd = ''");
			}
			$j = 0;
			if(count($ck) >= $num)
			{
				for($i=0;$i<$num;$i++)
			    {
					if($this->$xzck->save(array('state'=>1,'outk'=>$time,'time'=>$time),$ck[$i]['id']))//,'cktype'=>$cktype
					{
						$j++;
					}
			    }
				if($j == $num)
				{
					echo json_encode(array('msg'=>'出库成功!','success'=>true));exit;
				}
				else
				{
					echo json_encode(array('msg'=>'未成功出库数量:'.$num-$j.',请补入','c'=>0,'success'=>false));exit;
				}
			}
			else
			{
				echo json_encode(array('msg'=>'没有足够的库存!','cs'=>$label['sku'].' - '.$label['purchase'],'success'=>false));exit;
			}
		}
		$this->_Template('whlabel_printck',$this->data);
	}
	
	
	public function _printexcel()
	{
		$dir = '/data/excel/'.date('Ymd',time()).'/';
		$config['upload_path'] = '.'.$dir ;
		$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
        $config['allowed_types'] = 'xls|xlsx|csv';
        $config['max_size'] = 10240;
		$this->load->library('upload', $config);
		$this->upload->initialize($config);
        if ($this->upload->do_upload('userfile'))
        {
			$full_path = $dir.$this->upload->data('file_name');
			$fileName = '.' . $full_path;
            if (!file_exists($fileName)) 
			{
				echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
            }
			else
			{
				require_once "../Documents/data/excel/PHPExcel/IOFactory.php";
				$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
				$phpExcel->setActiveSheetIndex(0);// 设置为默认表
				$sheetCount = $phpExcel->getSheetCount();// 获取表格数量
				$row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
				$column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
				++$column;//如果列数大于26行
				$list = array();
				for ($i = 2; $i <= $row; $i++) // 行数循环
				{
					$data = array();
                    for ($c = 'A'; $c != $column; $c++)  // 列数循环
	                {
						$data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
                    }
					$list[] = $data;
                }
			}
			$ed = array();$i = 0;$j = 0;$dcdata = array();$yc = '';
			$cmf_arr = array_column($list, '1');
            array_multisort($cmf_arr, SORT_ASC, $list);
		    foreach ($list as $key=>$value)
		    {
				$typeclass = $this->typeclass->get_bqsku($value['1'],$value['2']);
				if($typeclass)
				{
					$this->typeclass->save(array('bqsku'=>$value['3']),$typeclass['id']);
				}
				else
				{
					$ed[] = array($value['1'].'-系统未找到此订单信息');
					$i++;
					continue;
				}
			}
			if($i > 0)
			{
				$yc = $i.'条异常';
			}
				echo json_encode(array('msg'=>'操作成功 '.$yc,'yc'=>$ed,'success'=>true));exit;
			
        }
		}
		
		public function _uck()
	    {
		if(isset($_GET['excel']))
		{
			$tc = array();
			$typeclass = $this->typeclass->find_all();
			foreach ($typeclass as $v) 
		    {
				$tc[$v['id']] = $v['zh'];
			}
			$data = array();$t = array();$rq = '';
			$ts = strtotime(date("Y-m-d",time()))-strtotime(date("Y-m",time()));
			$ts = $ts/(24*3600);
			for($i=0;$i<$ts;$i++)
			{
				$t[] = date("Y-m-d",strtotime('-'.($ts-$i).' day'));
				$rq .=  "".date("Y-m-d",strtotime('-'.($ts-$i).' day'))."";
			}
			$info_list = $this->whlabel->find_pc("warehouse = '5'",'sku','warehouse,sku,features');
			foreach ($info_list as $k=>$v) 
		    {
				$features = explode('-',trim($v['features'],'-'));
				if(!isset($features[3]) || !isset($features[4]))
				{
					continue;
				}
				$data[$k][0] = $tc[$features[0]];//类型
				$data[$k][1] = ($features[3] != 57)?$tc[$features[3]]:'';//颜色,自然色不显示
				$data[$k][2] = $tc[$features[4]];//曲度
				$data[$k][3] = '';
				if(isset($data[$k][1]))
				{
					$data[$k][3] .= $data[$k][1];
				}
				if(isset($data[$k][2]))
				{
					$data[$k][3] .= $data[$k][2];
				}
				if(isset($features[5]))
				{
					$data[$k][3] .= $tc[$features[5]];
				}
				if(isset($features[2]))
				{
					$data[$k][3] .= $tc[$features[2]];
				}
				//$data[$k][3] 颜色,曲度,头套种类,尺寸
				$data[$k][4] = $v['sku'];
				$data[$k][5] = $this->whlabel->find_count('sku = "'.$v['sku'].'" and warehouse = "'.$v['warehouse'].'" and features = "'.$v['features'].'" and (state = 0 or (state = 1 and outk > '.strtotime(date("Y-m",time())).'))');//月初库存
				$data[$k][] = $this->whlabel->find_count('sku = "'.$v['sku'].'" and state = 0 and warehouse = "'.$v['warehouse'].'" and features = "'.$v['features'].'"');//剩余库存
				$zt = $this->whlabeltransport->find_all('sku = "'.$v['sku'].'" and warehouse = "'.$v['warehouse'].'" and features = "'.$v['features'].'" and cz = "0"');
				$ztrq = '';$ztsl = '';
				if(count($zt) > 0)
				{
					foreach ($zt as $vv) 
		            {
						$ztrq .= date('Y-m-d',$vv['stime']).' | 
';	
						$ztsl .= $vv['num'].'
';	
					}
				}
				$data[$k][] = trim($ztsl,'
');
				$data[$k][] = trim($ztrq,'
');
				$byck = 0;
				foreach ($t as $vv) 
		        {
					$sl = $this->whlabel->find_count('sku = "'.$v['sku'].'" and warehouse = "'.$v['warehouse'].'" and features = "'.$v['features'].'" and state = 1 and outk > '.strtotime($vv).' and outk < '.(strtotime($vv)+24*3600));
					$data[$k][] = ($sl > 0)?''.$sl.'':'';
					$byck += $sl;
				}
				$data[$k][] = ($byck > 0)?$byck:'';
			}
			
            $title = "详情 ".date("Y-m-d",time());
            $titlename = "
            
			| 类别 | 颜色 | 曲度 | 名称 | SKU | 月初库存 | 剩余库存 | 在途数量 | 预达日期".
			$rq
			." | 本月出库 | 
            
"; 
            $filename = $title.".xls";
			$tail = "";
            $this->excel->get_fz2($data,$titlename,$filename,$tail);
	    }
	}
	
	public function _whlabelexcelzh()
	{
		if(isset($_GET['excel']))  
		{
			$where = "sku != 'Preset'";
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
			$category = $this->input->get('category',true);
			$warehouse = $this->input->get('warehouse',true);
			$excelid = $this->input->get('sid',true);
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			$xzid = '';
			if($excelid)
            {
				$excelid = explode(',',trim($excelid,','));
				foreach ($excelid as $key=>$value) 
		        {
					$xzid .= " id = ".$value." or";
				}
                $xzid = " and (".rtrim($xzid,'or').")";;
            }
            //取得信息列表
			/**
           $info_list = $this->whlabel->find_all($where.$xzid,'*');
			$rows = array();$list = array();
			foreach ($info_list as $key=>$value) 
		    {
				$rows[strtolower($value['sku']).$value['features'].$value['warehouse']] = $value;//所有数据sku
		    }
			**/
			$list = array();
			$rows = $this->whlabel->find_pc($where,'sku,features,warehouse','warehouse,sku,title,number,features');
			foreach ($rows as $key=>$value) 
		    {
				$c = $this->whlabel->find_count($where.' and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and state = "0" and features = "'.$value['features'].'"');
				$zh = '';
				$zt = $this->whlabeltransport->find_all('sku = "'.$value['sku'].'" and time = "0" and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"','num,stime');
				foreach ($zt as $v) 
		        {
					$zh .= $v['num']." / ".date('Y-m-d',$v['stime'])."
";
				}
				$zt = array_sum(array_column($zt,'num'));
				$number = $value['number'];
				$ftime = time()-15*24*3600;
				$warehouse = $this->warehouse->read($value['warehouse']);
				$rows[$key]['warehouse'] = $warehouse['title'];
				$rows[$key]['number'] = $c;
				$rows[$key]['features'] = $zh;
				$rows[$key]['hb'] = $c+$zt;
		    }
            $title = "导出库存数据及在途中数据".date('Y-m-d',time()); 
            $titlename = "
            | 导出库存数据及在途中数据 | 
|---|
            
			| 仓库 | SKU | 产品 | 库存数量 | 在途数量及预达日期 | 在途+库存数量 | 
            
";
            $filename = $title.".xls";
			$tail = "";
            $this->excel->get_fz2($rows,$titlename,$filename,$tail);
	    }
		if(isset($_GET['excel']))  
		{
			$warehouse = $this->input->get('warehouse',true);
			$sku = $this->input->get('sku',true);
			$cz = $this->input->get('cz',true);
			$text = $this->input->post('text',true);
			$xztime = $this->input->get('xztime',true);
			$timetk = $this->input->get('timetk',true);
			$timetj = $this->input->get('timetj',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			$where = "time = '0' ";
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($sku)
            {
                $where  .= " and sku = '$sku'";
            }
			if($text)
            {
                $where  .= " and text like '%$text%'";
            }
			if($cz != '')
            {
                $where  .= " and cz = '$cz'";
            }
			if($timetk && $timetj)
            {
                $where  .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
            }
            //数据排序
            $order_str = $xztime." desc";
            //取得信息列表
			$zh = array();
            $info_list = $this->whlabeltransport->find_all($where,'warehouse,sku,title,num,features,enter,stime,text');
			foreach ($info_list as $v) 
		    {
				$c = $this->whlabel->find_count('state = 0 and warehouse = "'.$v['warehouse'].'" and features = "'.$v['features'].'"');
				$warehouse = $this->warehouse->read($v['warehouse']);
				$v['warehouse'] = $warehouse['title'];
				$v['enter'] = date('Y-m-d H:i:s',$v['enter']);
				$v['stime'] = date('Y-m-d',$v['stime']);
				if(isset($zh[$v['features']]))
				{
					$zh[$v['features']]['num'] += $v['num'];
				}
				else
				{
					$zh[$v['features']] = $v;
				}
				$zh[$v['features']]['features'] = $c;
		    }
            $title = "在途数据".date('Y-m-d',time()); 
            $titlename = "
            
			| 仓库 | SKU | 名称 | 在途数量 | 库存数量 | 添加在途日期 | 预达日期 | 备注 | 
            
"; 
            $filename = $title.".xls";
			$tail = "";
            $this->excel->get_fz2($zh,$titlename,$filename,$tail);
	    }
	}
	
    public function _fc()
	{
		$vip = 0;
		if(isset($_SESSION['api']))
		{
			$user = $this->user->get_api($_SESSION['api']);
			if($user['vip'] == 1)
			{
				$vip = 1;
			}
		}
		else
		{
			header('Location: /');exit;
		}
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$category = $this->input->post('category',true);
			$size = $this->input->post('size',true);
			$grade = $this->input->post('grade',true);
			$color = $this->input->post('color',true);
			$lowe = $this->input->post('lowe',true);
			$sku = $this->input->post('sku');
			$title = $this->input->post('title');
			$warehouse = $this->input->post('warehouse',true);
			$usa = $this->input->post('usa',true);
			$purchase = $this->input->post('purchase',true);
			$lacetype = $this->input->post('lacetype',true);
			$haircap = $this->input->post('haircap',true);
			$density = $this->input->post('density',true);
			$details = $this->input->post('details',true);
			$state = $this->input->post('state',true);
			$ktime = $this->input->post('ktime',true);
			$jtime = $this->input->post('jtime',true);
			$ktime = strtotime($ktime);
			$jtime = strtotime($jtime);
			$where = "state = '11'";$gj = "";$ck = "";
			if($lacetype)
            {
                $where  .= " and features like '%-$lacetype-%'";
            }
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($haircap)
            {
                $where  .= " and features like '%-$haircap-%'";
            }
			if($density)
            {
                $where  .= " and features like '%-$density-%'";
            }
			if($usa)
            {
				if(!$warehouse)
				{
                    $where  .= " and (warehouse = '5' or warehouse = '8')";
				}
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($details)
            {
                $where  .= " and details = '$details'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($state)
            {
                $where  .= " and state = '$state'";
            }
			if($ktime && $jtime)
            {
                $gj  = " and enter > '$ktime' and enter < '$jtime'";
				$ck  = " and outk > '$ktime' and outk < '$jtime'";
            }
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
			if($sku)
            {
				$sku = trim($sku,' ');
				$sku = trim($sku,'	');
                $where  .= " and sku like '%$sku%'";
				$info_list = $this->whlabel->find_pc($where,'sku,features,warehouse','id,warehouse,sku,title,number,features',$order_str,$start,$perpage);
            }
			else if($title)
            {
				$title = trim($title,' ');
				$title = trim($title,'	');
                $where  .= " and title like '%$title%'";
				$info_list = $this->whlabel->find_pc($where,'sku,features,warehouse','id,warehouse,sku,title,number,features',$order_str,$start,$perpage);
            }
			else
			{
				//$where  .= " and time > '$ktime' and time < '$jtime'";
				$info_list = $this->whlabel->find_pc($where,'sku,features,warehouse','id,warehouse,sku,title,number,features',$order_str,$start,$perpage);
			}
            //取得信息列表
           
			$rows = array();$list = array();
			foreach ($info_list as $key=>$value) 
		    {
				$g = $this->whlabel->find_count($where.' and (oldstate = "11" or state = "11") and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and state != "9" and features = "'.$value['features'].'"');
				$x = $this->whlabel->find_count($where.' and oldstate = "11" and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and state = "1" and features = "'.$value['features'].'"');
				$s = $this->whlabel->find_count($where.' and state = "11"  and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and state = "8" and features = "'.$value['features'].'"');
				$warehouse = $this->warehouse->read($value['warehouse']);
				$info_list[$key]['warehouse'] = $warehouse['title'];
				$info_list[$key]['number'] = $g;
				$info_list[$key]['features'] = $x;
				$info_list[$key]['x'] = $s;
		    }
		    $total = count($this->whlabel->find_pc($where,'sku,features,warehouse','id,warehouse,sku,title,features,number'));
		    $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->data['vip'] = $vip;
		$this->_Template('whlabel_fc',$this->data);
	}
	
	public function _fcmb()
	{
			$where = "sku != 'Preset'";
			$rows = $this->whlabel->find_pc($where,'sku,features,warehouse','warehouse,sku,title');
			foreach ($rows as $k=>$v) 
		    {
				$warehouse = $this->warehouse->read($v['warehouse']);
				$rows[$k]['warehouse'] = $warehouse['title'];
				$rows[$k]['num'] = $this->whlabel->find_count('warehouse = "'.$v['warehouse'].'" and sku = "'.$v['sku'].'" and state = 11');
				$rows[$k]['t'] = '';
				$rows[$k]['n'] = '';
		    }
            $title = "封货产品数据导入模板"; 
            $titlename = "
            | ".$title." | 
|---|
            
			| 仓库 | SKU | 产品 | 封存产品总数量 | 类型(0.增加封存数量 1.转入产品库存 2.删除封存数量 留空导入时自动跳过此行) | 数量(填写正整数,留空导入时自动跳过此行) | 
            
";
            $filename = $title.".xls";
			$tail = "";
            $this->excel->get_fz2($rows,$titlename,$filename,$tail);
	    
	}
	public function _fcexcel()
	{
		$dir = '/data/excel/'.date('Ymd',time()).'/';
		$config['upload_path'] = '.'.$dir ;
		$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
        $config['allowed_types'] = 'xls|xlsx|csv';
        $config['max_size'] = 10240;
		$this->load->library('upload', $config);
		$this->upload->initialize($config);
        if ($this->upload->do_upload('userfile'))
        {
			$full_path = $dir.$this->upload->data('file_name');
			$fileName = '.' . $full_path;
            if (!file_exists($fileName)) 
			{
				echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
            }
			else
			{
				libxml_use_internal_errors(true);
				require_once "../Documents/data/excel/PHPExcel/IOFactory.php";
				$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
				$phpExcel->setActiveSheetIndex(0);// 设置为默认表
				$sheetCount = $phpExcel->getSheetCount();// 获取表格数量
				$row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
				$column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
				++$column;//如果列数大于26行
				$list = array();
				for ($i = 2; $i <= $row; $i++) // 行数循环
				{
					$data = array();
                    for ($c = 'A'; $c != $column; $c++)  // 列数循环
	                {
						$data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
                    }
					$list[] = $data;
                }
			}
			$i = 0;$j = 0;$ed = array();
		    foreach ($list as $key=>$value)
		    {
				$time = time();
				if($value['0'] == "" || !is_numeric($value['3']) || !is_numeric($value['4']))
				{
					continue;
				}
				$warehouse = $this->warehouse->get_title($value['0']);
				$sku =  $value['1'];
				$type =  $value['4'];//调整方式0扣减1删除
				$num =  $value['5'];//调整数量
				//$text =  $value['4'];//扣减说明
				$d = $this->whlabel->get_warehousesku($warehouse['id'],$sku);
				if(!$d)//如果没有这个SKU
				{
					$ed[] = array($sku.'-库存中不存在此SKU');
					$j++;
					continue;
				}
				if(!isset($warehouse['id']))
				{
					$ed[] = array($sku.'-仓库名错误!');
					$j++;
					continue;
				}
				if($type == 1 || $type == 2)//扣减库存
				{
					$data = $this->whlabel->find_all('warehouse = "'.$warehouse['id'].'" and sku = "'.$sku.'" and state = 11');
					if(count($data) < abs($num))
					{
						$ed[] = array($sku.'-数量大于封存产品剩余数量!');
						$j++;
						continue;
					}
					if($type == 1)//转入库存
					{
						for($i=0;$iwhlabel->save(array('state'=>0,'oldstate'=>11,'time'=>$time),$data[$i]['id']);
						}
					}
					else if($type == 2)//删除
					{
						for($i=0;$iwhlabel->remove($data[$i]['id']);
						}
					}
				}
				else if($type == 0)//增加库存
				{
					$post['sku'] = $d['sku'];
					$post['shop'] = '';
					$post['warehouse'] = $warehouse['id'];
					$post['purchase'] = $d['purchase'];
					$post['retreatwarehouse'] = $d['retreatwarehouse'];
					$post['state'] = 11;
					$post['title'] = $d['title'];
					$post['number'] = $d['number'];
					$post['features'] = $d['features'];
					$post['enter'] = $time;
					$post['time'] = $time;//操作时间
					for($i=0;$i<$num;$i++)
					{
						$post['label'] = time().rand(100,999).$i;
						$this->whlabel->insert($post);
					}
				}
				sleep(1);//防止入库时间一样,需要延迟1秒
			}
			if($j > 0)
			{
				$tt = date('Ymd',time());
				$title = '库存导入错误信息-'.$tt;
        		$titlename = "";
				$tail = "\n";
        		$filename = $title.".xls";
        		$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
				$dir = '/data/excel/'.$time.'/';
				$file_name = 'error_'.$time.rand(1000,9999);
				if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
				$myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
				fwrite($myfile,$ecl);
				fclose($myfile);
				$error = $dir.$file_name.'.xls';
				echo json_encode(array('msg'=>'导入成功,'.$j.'条异常,','error'=>$error,'success'=>true));exit;
			}
			else
			{
				echo json_encode(array('msg'=>'导入成功!','error'=>1,'success'=>true));exit;
			}
		}
	}
	
	public function _fcjxc($arg_array)
	{
		if(isset($_GET['excel']))  
		{
			$category = $this->input->get('category',true);
			$size = $this->input->get('size',true);
			$grade = $this->input->get('grade',true);
			$color = $this->input->get('color',true);
			$lowe = $this->input->get('lowe',true);
			$sku = $this->input->get('sku');
			$title = $this->input->get('title');
			$warehouse = $arg_array[0];
			$usa = $this->input->get('usa',true);
			$purchase = $this->input->get('purchase',true);
			$lacetype = $this->input->get('lacetype',true);
			$haircap = $this->input->get('haircap',true);
			$density = $this->input->get('density',true);
			$title = $this->input->get('title',true);
			$state = $this->input->get('state',true);
			$ktime = $this->input->get('ktime',true);
			$jtime = $this->input->get('jtime',true);
			$where = "state=11";$gj = "";$ck = "";
			if($lacetype)
            {
                $where  .= " and features like '%-$lacetype-%'";
            }
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($haircap)
            {
                $where  .= " and features like '%-$haircap-%'";
            }
			if($density)
            {
                $where  .= " and features like '%-$density-%'";
            }
			if($usa)
            {
				if(!$warehouse)
				{
                    $where  .= " and (warehouse = '5' or warehouse = '8')";
				}
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($state)
            {
                $where  .= " and state = '$state'";
            }
			$order_str = "id desc";
			if($sku)
            {
				$sku = trim($sku,' ');
				$sku = trim($sku,'	');
                $where  .= " and sku like '%$sku%'";
				$info_list = $this->whlabel->find_pc($where,'sku,features,warehouse','warehouse,sku,title,features',$order_str,$start,$perpage);
            }
			else if($title)
            {
				$title = trim($title,' ');
				$title = trim($title,'	');
                $where  .= " and title like '%$title%'";
				$info_list = $this->whlabel->find_pc($where,'sku,features,warehouse','warehouse,sku,title,features',$order_str,$start,$perpage);
            }
			else
			{
				//$where  .= " and time > '$ktime' and time < '$jtime'";
				$info_list = $this->whlabel->find_pc($where,'sku,features,warehouse','warehouse,sku,title,features',$order_str,$start,$perpage);
			}
            //取得信息列表
           
			$rows = array();$list = array();
			foreach ($info_list as $key=>$value) 
		    {
				
				$g = $this->whlabel->find_count($where.' and (oldstate = "11" or state = "11") and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and state != "9" and features = "'.$value['features'].'"');
				$x = $this->whlabel->find_count($where.' and oldstate = "11" and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and state = "1" and features = "'.$value['features'].'"');
				$s = $this->whlabel->find_count($where.' and state = "11"  and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and state = "8" and features = "'.$value['features'].'"');
				$rows[$key] = $value;
				$warehouse = $this->warehouse->read($value['warehouse']);
				$rows[$key]['warehouse'] = $warehouse['title'];
				$rows[$key]['features'] = $g;
				$rows[$key]['a'] = $x;
				$rows[$key]['b'] = $s;
		    }
            $title = "总统计表"; 
            $titlename = "
            | ".$title." | 
|---|
            
			| 仓库 | SKU | 产品名称 | 录入总量 | 取出总量 | 剩余总量 | 
            
";
            $filename = $title.".xls";
			$tail = "";
            $this->excel->get_fz2($rows,$titlename,$filename,$tail);
	    }
		$vip = 0;
		if(isset($_SESSION['api']))
		{
			$user = $this->user->get_api($_SESSION['api']);
			if($user['vip'] == 1)
			{
				$vip = 1;
			}
		}
		else
		{
			header('Location: /');exit;
		}
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$category = $this->input->post('category',true);
			$size = $this->input->post('size',true);
			$grade = $this->input->post('grade',true);
			$color = $this->input->post('color',true);
			$lowe = $this->input->post('lowe',true);
			$sku = $this->input->post('sku');
			$title = $this->input->post('title');
			$warehouse = $arg_array[0];
			$usa = $this->input->post('usa',true);
			$purchase = $this->input->post('purchase',true);
			$lacetype = $this->input->post('lacetype',true);
			$haircap = $this->input->post('haircap',true);
			$density = $this->input->post('density',true);
			$title = $this->input->post('title',true);
			$state = $this->input->post('state',true);
			$ktime = $this->input->post('ktime',true);
			$jtime = $this->input->post('jtime',true);
			$ktime = strtotime($ktime);
			$jtime = strtotime($jtime);
			$where = "state=11";$gj = "";$ck = "";
			if($lacetype)
            {
                $where  .= " and features like '%-$lacetype-%'";
            }
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($haircap)
            {
                $where  .= " and features like '%-$haircap-%'";
            }
			if($density)
            {
                $where  .= " and features like '%-$density-%'";
            }
			if($usa)
            {
				if(!$warehouse)
				{
                    $where  .= " and (warehouse = '5' or warehouse = '8')";
				}
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($state)
            {
                $where  .= " and state = '$state'";
            }
			if($ktime && $jtime)
            {
                $gj  = " and enter > '$ktime' and enter < '$jtime'";
				$ck  = " and outk > '$ktime' and outk < '$jtime'";
            }
            //数据排序
            $order_str = "id desc";$xs=0;
			$rows = array();$list = array();
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
			if($sku || $title)
            {
				if($title)
                {
				    $title = trim($title,' ');
				    $title = trim($title,'	');
                    $where  .= " and title like '%$title%'";
				}
				else
				{
				    $sku = trim($sku,' ');
				    $sku = trim($sku,'	');
                    $where  .= " and sku like '%$sku%'";
				}
				$info_list = $this->whlabel->find_pc($where,'sku,features,warehouse','id,warehouse,sku,title,features',$order_str,$start,$perpage);
				foreach ($info_list as $key=>$value) 
		        {
				
				    $g = $this->whlabel->find_count($where.' and (oldstate = "11" or state = "11") and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and state != "9" and features = "'.$value['features'].'"');
				    $x = $this->whlabel->find_count($where.' and oldstate = "11" and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and state = "1" and features = "'.$value['features'].'"');
				    $s = $this->whlabel->find_count($where.' and state = "11"  and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and state = "8" and features = "'.$value['features'].'"');
				    $rows[$key] = $value;
				    $warehouse = $this->warehouse->read($value['warehouse']);
				    $rows[$key]['warehouse'] = $warehouse['title'];
				    $rows[$key]['features'] = $g;
				    $rows[$key]['a'] = $x;
				    $rows[$key]['b'] = $s;
				    $kc = $this->whlabel->find_all($where.' and sku = "'.$value['sku'].'" and state = 0 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"','details,cpid');//现有库存
				    $xl = $this->whlabel->find_count($where." and outk > '".(time()-30*24*3600)."' and outk < '".time()."'".' and sku = "'.$value['sku'].'" and state = 1 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');//30天销量
				    $yj = $c/($xl/30);
				
				    if($yj < 7)
				    {
					    $rows[$key]['y'] = round($yj).'天销量';	
				    }
				    else
				    {
					    $rows[$key]['y'] = '正常';	
				    }
		        }
            }
			else
			{
				//$where  .= " and time > '$ktime' and time < '$jtime'";
				$info_list = $this->whlabel->find_pc($where,'sku,features,warehouse','id,warehouse,sku,title,features',$order_str,$start,$perpage);
				foreach ($info_list as $key=>$value) 
		    {
				
				$g = $this->whlabel->find_count($where.' and (oldstate = "11" or state = "11") and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and state != "9" and features = "'.$value['features'].'"');
				$x = $this->whlabel->find_count($where.' and oldstate = "11" and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and state = "1" and features = "'.$value['features'].'"');
				$s = $this->whlabel->find_count($where.' and state = "11"  and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and state = "8" and features = "'.$value['features'].'"');
				$zs[$key] = $value;
				$warehouse = $this->warehouse->read($value['warehouse']);
				$zs[$key]['warehouse'] = $warehouse['title'];
				$zs[$key]['features'] = $g;
				$zs[$key]['a'] = $x;
				$zs[$key]['b'] = $s;
				$kc = $this->whlabel->find_all($where.' and sku = "'.$value['sku'].'" and state = 0 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"','details,cpid');//现有库存
				$xl = $this->whlabel->find_count($where." and outk > '".(time()-30*24*3600)."' and outk < '".time()."'".' and sku = "'.$value['sku'].'" and state = 1 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');//30天销量
				$yj = $c/($xl/30);
				
				if($yj < 7)
				{
					$zs[$key]['y'] = round($yj).'天销量';	
					$rows[$key] = $zs[$key];
				}
		    }
			}
		
			
		    $total = count($this->whlabel->find_pc($where,'sku,features,warehouse','id'));
		    $pagenum = ceil($total/$perpage);
		    $over = $total-($start+$perpage);
		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($rows));
		    echo json_encode($rows);exit;
		}
		$this->data['arg_array'] = $arg_array[0];
		$this->_Template('whlabel_fcjxc',$this->data);
	}
	
	public function _0kcdel()
	{
		$dir = '/data/excel/'.date('Ymd',time()).'/';
		$config['upload_path'] = '.'.$dir ;
		$config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
        $config['allowed_types'] = 'xls|xlsx|csv';
        $config['max_size'] = 10240;
		$this->load->library('upload', $config);
		$this->upload->initialize($config);
        if ($this->upload->do_upload('userfile'))
        {
			$full_path = $dir.$this->upload->data('file_name');
			$fileName = '.' . $full_path;
            if (!file_exists($fileName)) 
			{
				echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
            }
			else
			{
				require_once "./data/excel/PHPExcel/IOFactory.php";
				@$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
				@$phpExcel->setActiveSheetIndex(0);// 设置为默认表
				$sheetCount = $phpExcel->getSheetCount();// 获取表格数量
				$row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
				$column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
				++$column;//如果列数大于26行
				$list = array();
				for ($i = 2; $i <= $row; $i++) // 行数循环
				{
					$data = array();
                    for ($c = 'A'; $c != $column; $c++)  // 列数循环
	                {
						$data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
                    }
					$list[] = $data;
                }
			}
			$i = 0;$j = 0;$ed = array();
		    foreach ($list as $key=>$value)
		    {
				$time = time();
				if($value['0'] == "" || $value['1'] == "")
				{
					continue;
				}
				$warehouse = $this->warehouse->get_title($value['0']);
				$sku =  $value['1'];
				$d = $this->whlabel->get_warehousesku($warehouse['id'],$sku);
				if(!$d)//如果没有这个SKU
				{
					$ed[] = array($sku.'-库存中不存在此SKU');
					$j++;
					continue;
				}
				if(!isset($warehouse['id']))
				{
					$ed[] = array($sku.'-仓库名错误!');
					$j++;
					continue;
				}
				$z = $this->whlabel->find_count('sku = "'.$sku.'" and zd = "" and state = 0 and warehouse = "'.$warehouse['id'].'"');
				if($z < 1)
				{
					$z = $this->whlabel->find_all('sku = "'.$sku.'" and warehouse = "'.$warehouse['id'].'"');
				    foreach ($z as $v) 
		            {
						$zt = $this->whlabeltransport->find_all('sku = "'.$sku.'" and warehouse = "'.$warehouse['id'].'" and features = "'.$d['features'].'" and cz = "0"');
						if(count($zt) > 0)
						{
							$ed[] = array($sku.'-有在途库存无法删除!');
							$j++;
							continue;
						}
                        $this->whlabel->remove($v['id']);
				    }
				}
				else
				{
					$ed[] = array($sku.'-非0库存!');
					$j++;
					continue;
				}
			}
			if($j > 0)
			{
				$tt = date('Ymd',time());
				$title = '删除0库存错误信息-'.$tt;
        		$titlename = "";
				$tail = "\n";
        		$filename = $title.".xls";
        		$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
				$dir = '/data/excel/'.$time.'/';
				$file_name = 'error_'.$time.rand(1000,9999);
				if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
				$myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
				fwrite($myfile,$ecl);
				fclose($myfile);
				$error = $dir.$file_name.'.xls';
				echo json_encode(array('msg'=>'导入成功,'.$j.'条异常,','error'=>$error,'success'=>true));exit;
			}
			else
			{
				echo json_encode(array('msg'=>'导入成功!','error'=>1,'success'=>true));exit;
			}
		}
	}
	
	public function _gbhtype()
	{
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['s']))  
		{
			$n = $this->input->post('n');
            $d = $this->input->post('s');
            if(!$d)
            {
                echo json_encode(array('msg'=>'未选择需要更改的商品','success'=>false));exit;
            }
			$d =  explode(',',trim($d,','));
			$t = $this->whlabel_type->read($n);
            //循环删除记录
            foreach ($d as $v) 
		    {
			   $u = $this->whlabel->read($v);
               $data = $this->whlabel->find_all("sku = '".$u['sku']."' and purchase = '".$u['purchase']."' and features = '".$u['features']."' and warehouse = '".$u['warehouse']."'");
			   foreach ($data as $val) 
		       {
				   $this->whlabel->save(array('type'=>$n),$val['id']);
			   }
            }
            echo json_encode(array('d'=>$d,'t'=>$t['title'],'msg'=>'修改成功!','success'=>true));
		}
    }
	
	
	//出库、退库导出
	public function _dccrtype()
	{
		$classid = $this->classid->sku();
		$pm = $classid;
		$typeclass = array();
		$tc = $this->typeclass->find_all();
		foreach ($tc as $v)
		{
			$typeclass[$v['id']] = $v;
		}
		$prc = array();
		$purchase = $this->purchase->find_all();
		foreach($purchase as $k=>$v)
		{
			$prc[$v['id']] = $v['title'];
		}
		if(isset($_GET['sid']))  
		{
			$wh = array();
			$w = $this->warehouse->find_all('1=1','id,title');
			foreach ($w as $v) 
			{
				$wh[$v['id']] = $v['title'];
			}
			$type = $this->input->get('excel',true);
			$category = $this->input->get('category',true);
			$size = $this->input->get('size',true);
			$grade = $this->input->get('grade',true);
			$color = $this->input->get('color',true);
			$lowe = $this->input->get('lowe',true);
			$sku = $this->input->get('sku',true);
			$warehouse = $this->input->get('warehouse',true);
			$lacetype = $this->input->get('lacetype',true);
			$lacecolor = $this->input->get('lacecolor',true);
			$density = $this->input->get('density',true);
			$haircap = $this->input->get('haircap',true);
			$purchase = $this->input->get('purchase',true);
			$title = $this->input->get('title',true);
			$state = $this->input->get('state',true);
			$sid = $this->input->get('sid',true);
			$ktime = $this->input->get('ktime',true);
			$jtime = $this->input->get('jtime',true);
			$ktime = strtotime($ktime);
			$jtime = strtotime($jtime);
			$where = "1=1";$gj = "";$ck = "";
			if($category)
            {
                $where  .= " and features like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and features like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and features like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and features like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and features like '%-$lowe-%'";
            }
			if($warehouse)
            {
                $where  .= " and warehouse = '$warehouse'";
            }
			if($purchase)
            {
                $where  .= " and purchase = '$purchase'";
            }
			if($state)
            {
                $where  .= " and state = '$state'";
            }
			if($lacetype)
            {
                $where  .= " and features like '%-$lacetype-%'";
            }
			if($lacecolor)
            {
                $where  .= " and features like '%-$lacecolor-%'";
            }
			if($density)
            {
                $where  .= " and features like '%-$density-%'";
            }
			if($haircap)
            {
                $where  .= " and features like '%-$haircap-%'";
            }
			if($title)
            {
				$title = trim($title,' ');
				$title = trim($title,'	');
                $where  .= " and title like '%$title%'";
            }
			if($sku)
            {
				$sku = trim($sku,' ');
				$sku = trim($sku,'	');
                $where  .= " and sku like '%$sku%'";
            }
			if($ktime && $jtime)
            {
                //$where  .= " and ((enter > '$ktime' and enter < '$jtime') or (outk > '$ktime' and outk < '$jtime'))";
            }
			$sidwhere = '';
			if($sid)
            {
				$sd = "";
				$s = explode(',',trim($sid,','));
				foreach ($s as $value) 
		    	{
					$sd .= " id = ".$value." or";
				}
                $sidwhere  = " and (".rtrim($sd,'or').")";
            }
            //数据排序
            $order_str = "time desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
				$wh = array();
				$w = $this->warehouse->find_all('1=1','id,title');
				foreach ($w as $v) 
				{
					$wh[$v['id']] = $v['title'];
				}
				$wt = array();
			$whlabel_type = $this->whlabel_type->find_all();
			foreach ($whlabel_type as $v) 
			{
				$wt[$v['id']] = $v['title'];
			}
			$classid = $this->classid->sku();
				$list = array();
				$rows_r = $this->whlabel->find_pc($where." and enter > '$ktime' and enter < '$jtime' ".$sidwhere,'sku,features,warehouse,enter','warehouse,sku,title,zh,features,time,enter,rktype,number,text');
				foreach ($rows_r as $key=>$value) 
		    	{
					$rows_r[$key]['warehouse'] = $wh[$value['warehouse']];
					$pm = $classid; 
					$jm = $classid; 
					$rows_r[$key]['enter'] = '入库';
					$rows_r[$key]['time'] = $value['enter'];
					if($value['rktype'] == 1)
					{
						$rows_r[$key]['rktype'] = '采购入库';
					}
					else if($value['rktype'] == 2)
					{
						$rows_r[$key]['rktype'] = '盘盈调整';
					}
					else if($value['rktype'] == 3)
					{
						$rows_r[$key]['rktype'] = '其他调整入库';
					}
					else if($value['rktype'] == 4)
					{
						$rows_r[$key]['rktype'] = '其他调整入库';
					}
					else if($value['rktype'] == 5)
					{
						$rows_r[$key]['rktype'] = '退库入库';
					}
					else if($value['rktype'] == 6)
					{
						$rows_r[$key]['rktype'] = '退货可用入库';
					}
					else if($value['rktype'] == 7)
					{
						$rows_r[$key]['rktype'] = '形态转换入库';
					}
					else
					{
						$rows_r[$key]['rktype'] = '';
					}
				    $features = explode('-',trim($value['features'],'-'));
				    foreach($features as $v)
				    {
					   if(isset($typeclass[$v]))
					   {
						   $zh = explode('|',trim($typeclass[$v]['zh'],'|'));
					       $pm[$typeclass[$v]['classid']] = $zh[0];
					   }
					   if(isset($typeclass[$v]))
					   {
						   if(isset($jm[$typeclass[$v]['classid']]))
						   {
							   $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
							
						   }
					    }
				    }
				    $zh = implode(" ",$pm);
				    $zh = str_replace('自然色 ','',rtrim($zh,' '));
				    $zh = str_replace(array('        ','       ','      ','     ','    ','   ','  '),' ',$zh);
				    $rows_r[$key]['zh'] = $zh;
				    $jm = array_filter($jm);
					$rows_r[$key]['features'] = implode("-",$jm);
					$rows_r[$key]['number'] = $this->whlabel->find_count($where." and enter = '".$value['enter']."' ".$sidwhere);
		    	}
				
				$rows_c = $this->whlabel->find_all($where." and outk > '$ktime' and outk < '$jtime' ".$sidwhere,'warehouse,sku,title,zh,features,time,outk,cktype,number,textout');
				foreach ($rows_c as $key=>$value) 
		    	{
					$rows_c[$key]['warehouse'] = $wh[$value['warehouse']];
					$pm = $classid; 
					$jm = $classid; 
					$rows_c[$key]['time'] = $value['outk'];
					$rows_c[$key]['outk'] = '出库';
					if($value['cktype'] == 1)
					{
						$rows_c[$key]['cktype'] = '销售出库';
					}
					else if($value['cktype'] == 2)
					{
						$rows_c[$key]['cktype'] = '销售美国出库';
					}
					else if($value['cktype'] == 3)
					{
						$rows_c[$key]['cktype'] = '盘亏调整';
					}
					else if($value['cktype'] == 4)
					{
						$rows_c[$key]['cktype'] = '其他调整出库';
					}
					else if($value['cktype'] == 5)
					{
						$rows_c[$key]['cktype'] = '形态转换出库';
					}
					else
					{
						$rows_c[$key]['cktype'] = '';
					}
					 $features = explode('-',trim($value['features'],'-'));
				    foreach($features as $v)
				    {
					   if(isset($typeclass[$v]))
					   {
						   $zh = explode('|',trim($typeclass[$v]['zh'],'|'));
					       $pm[$typeclass[$v]['classid']] = $zh[0];
					   }
					   if(isset($typeclass[$v]))
					   {
						   if(isset($jm[$typeclass[$v]['classid']]))
						   {
							   $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
							
						   }
					    }
				    }
				    $zh = implode(" ",$pm);
				    $zh = str_replace('自然色 ','',rtrim($zh,' '));
				    $zh = str_replace(array('        ','       ','      ','     ','    ','   ','  '),' ',$zh);
				    $rows_c[$key]['zh'] = $zh;
				    $jm = array_filter($jm);
					$rows_c[$key]['features'] = implode("-",$jm);
					$rows_c[$key]['number'] = 1;
		    	}
				$merged = $rows_r;
				foreach ($rows_c as $key => $value) 
				{
					if (isset($merged[$key])) 
					{
						$merged[] = $value;
					} 
					else
					{
						$merged[$key] = $value;
					}
				}
				usort($merged, function($a, $b)
				{
					return $a['time'] - $b['time'];
				});
				foreach ($merged as $key=>$value) 
		    	{
					$merged[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
				}
            	$title = date('Y-m-d',$ktime).'至'.date('Y-m-d',$jtime); 
            	$titlename = "
            	
				| 仓库 | SKU | 商品名称 | 仓库品名 | 料号 | 时间 | 操作 | 类型 | 数量 | 备注 | 
            	
"; 
            	$filename = $title.".xlsx";
				$tail = "";
            	$this->excel->get_fz2($merged,$titlename,$filename,$tail);
			
	    }
	}
	
}