load->library('session');
		$this->load->_model('Model_finance','finance');
		$this->load->_model('Model_fullorder','fullorder');
		$this->load->_model('Model_fullordertt','fullordertt');
		$this->load->_model('Model_fullordersmt','fullordersmt');
		$this->load->_model('Model_shop','shop');
		$this->load->_model('Model_typeclass','typeclass');
		$this->load->_model('Model_express','express');
		$this->load->_model('Model_country','country');
		$this->load->_model('Model_productdescribe','productdescribe');
		$this->load->_model('Model_customs','customs');
		$this->load->_model('Model_detailed','detailed');
		$this->load->_model('Model_productdescription','productdescription');
		$this->load->_model('Model_logistics','logistics');
		$this->load->_model('Model_hl','hl');
		$this->load->_model('Model_excel','excel');
		$this->load->_model('Model_warehouse','warehouse');
		$this->load->_model('Model_systemwigsout','systemwigsout');
		$this->load->_model('Model_classid','classid');
	}
	//定义方法的调用规则 获取URI第二段值
    public function _remap($arg,$arg_array)
    {
		if($arg == 'excel')
        {
             $this->_excel();
        }
		else if($arg == 'ckexcel')
        {
             $this->_ckexcel();
        }
		else if($arg == 'caiwu')
        {
             $this->_caiwu($arg_array);
        }
		else if($arg == 'ckcaiwu')
        {
             $this->_ckcaiwu();
        }
		else if($arg == 'product')
        {
             $this->_product($arg_array);
        }
		else if($arg == 'dhlfp')
        {
             $this->_dhlfp();
        }
		else if($arg == 'ouout')
        {
             $this->_ouout();
        }
		else if($arg == 'cksize')
        {
             $this->_cksize();
        }
		else
		{
			 $this->_index($arg);
		}
    }
	
	//店铺统计
	public function _index($arg)
	{
		$fu = (isset($arg))?($arg=="smt"?"fullordersmt":"fullorder"):"fullorder";
		$user = $this->user->get_api($_SESSION['api']);
		if($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['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$timetk = $this->input->post('timetk',true);
			$timetj = $this->input->post('timetj',true);
			$shop = $this->input->post('shop',true);
			$source = $this->input->post('source',true);
			$library = $this->input->post('library',true);
			$warehouse = $this->input->post('warehouse',true);
			$orderinfo = $this->input->post('orderinfo',true);
			$user = $this->input->post('user',true);
			$name = $this->input->post('name',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			$where = "mergeid = 0";
			if($timetk && $timetj)
            {
                 $where  .= " and librarytime > '$timetk' and librarytime < '$timetj'";
            }
			if($shop)
            {
                $where  .= " and shop = '$shop'";
            }
			if($source)
            {
                $where  .= " and source = '$source'";
            }
			if($library)
            {
				$where  .= " and library = '$library'";
            }
			if($warehouse)
            {
                $where  .= " and type = '$warehouse'";
            }
			if($orderinfo)
            {
                $where  .= " and orderinfo = '$orderinfo'";
            }
			if($user)
            {
                $where  .= " and user = '$user'";
            }
			if($name)
            {
                $where  .= " and name = '$name'";
            }
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
			$shouldmoney=0;$expressmoney=0;$budget=0;$refundj=0;
            //取得信息列表
            $info_list = $this->$fu->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,orderremarks,hl',$order_str,$start,$perpage);
			 //格式化数据
            foreach ($info_list as $key=>$value)
		    {
				$order = $this->$fu->read($value['id']);
				$order['hl'] = $order['hl']!=0?$order['hl']:6.71;
				$shop = $this->shop->read($value['shop']);
				$info_list[$key]['shop'] = $shop['shopname'];
				$info_list[$key]['user'] = $shop['shopuser'];
				$warehouse = $this->warehouse->read($value['type']);
				$info_list[$key]['type'] = $warehouse['title'];
				$info_list[$key]['shouldmoney'] = ($order['currencytitle']=='CNY')?sprintf("%.2f",$order['shouldmoney']/$order['hl']):$value['shouldmoney'];
				$shouldmoney += $info_list[$key]['shouldmoney'];
				$expressmoney += $info_list[$key]['expressmoney'];
				$info_list[$key]['budget'] = ($order['currencytitle']=='CNY')?sprintf("%.2f",$order['budget']/$order['hl']):$value['budget'];
				$budget += $info_list[$key]['budget'];
				$refundj += $info_list[$key]['refundj'];
            }
			$money = $this->$fu->find_all($where);
			$shouldmoney = sprintf("%.2f",$shouldmoney);
			$expressmoney = sprintf("%.2f",$expressmoney);
			$budget = sprintf("%.2f",$budget);
			$refundj = sprintf("%.2f",$refundj);
		    $total = $this->$fu->find_count($where);
		    $pagenum = ceil($total/$perpage);
		    $over = $total-($start+$perpage);
		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'money'=>(array($shouldmoney,$budget,$expressmoney,$refundj)));
		    echo json_encode($rows);exit;
		}
		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
		$this->data['wlshop'] = $wlshop;
		$this->data['arg'] = $arg;
		$this->_Template('finance',$this->data);
	}
	public function _caiwu($arg_array)
	{
		$user = $this->user->get_api($_SESSION['api']);
		if($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['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$timetk = $this->input->post('timetk',true);
			$timetj = $this->input->post('timetj',true);
			$shop = $this->input->post('shop',true);
			$source = $this->input->post('source',true);
			$library = $this->input->post('library',true);
			$warehouse = $this->input->post('warehouse',true);
			$orderinfo = $this->input->post('orderinfo',true);
			$number = $this->input->post('number',true);
			$user = $this->input->post('user',true);
			$name = $this->input->post('name',true);
			$xztime = $this->input->post('xztime',true);
			$country = $this->input->post('country',true);
			$paypal = $this->input->post('paypal',true);
			$fullorder = $this->input->post('fullorder',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			$where = "mergeid = 0";
			if($timetk && $timetj)
            {
                 $where  .= " and  ".$xztime." > '$timetk' and  ".$xztime." < '$timetj'";
            }
			if($shop)
            {
                $where  .= " and shop = '$shop'";
            }
			if($source)
            {
                $where  .= " and source = '$source'";
            }
			if($library)
            {
				$where  .= " and library = '$library'";
            }
			if($warehouse)
            {
                $where  .= " and type = '$warehouse'";
            }
			if($orderinfo)
            {
                $where  .= " and orderinfo = '$orderinfo'";
            }
			if($number)
            {
                $where  .= " and number = '$number'";
            }
			if($user)
            {
                $where  .= " and user = '$user'";
            }
			if($name)
            {
                $where  .= " and name = '$name'";
            }
			if($country)
            {
                $where  .= " and country = '$country'";
            }
			if($paypal)
            {
                $where  .= " and paypal = '$paypal'";
            }
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
			$shouldmoney=0;$expressmoney=0;$budget=0;$refundj=0;$cost=0;$lr=0;
            //取得信息列表
			if($fullorder == 'fullordersmt')
			{
                $info_list = $this->fullordersmt->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,cost,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
				$total = $this->fullordersmt->find_count($where);
			}
			else if($fullorder == 'fullorder')
			{
				 $info_list = $this->fullorder->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,cost,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
				 
		          $total = $this->fullorder->find_count($where);
			}
			else if($fullorder == 'fullordertt')
			{
				 $info_list = $this->fullordertt->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,cost,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
				 
		          $total = $this->fullordertt->find_count($where);
			}
			else
			{
				$info_lista = $this->fullordersmt->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,cost,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
				$info_listb = $this->fullorder->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,cost,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
				$info_listc = $this->fullordertt->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,cost,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
				$info_list = array_merge($info_lista,$info_listb);
				$total = $this->fullordersmt->find_count($where);
				$total += $this->fullorder->find_count($where);
				$total += $this->fullordertt->find_count($where);
			}
			 //格式化数据
            foreach ($info_list as $key=>$value)
		    {
				$shop = $this->shop->read($value['shop']);
				$fu = ($shop['type'] == "269")?'fullorder':'fullordersmt';
				$order = $this->$fu->read($value['id']);
				$order['hl'] = $order['hl']!=0?$order['hl']:6.71;
				$info_list[$key]['shop'] = $shop['shopname'];
				$info_list[$key]['user'] = $shop['shopuser'];
				$warehouse = $this->warehouse->read($value['type']);
				$info_list[$key]['type'] = $warehouse['title'];
				$merge = $info_list[$key]['budget']-$info_list[$key]['refundj']-$info_list[$key]['cost']/$order['hl']-$info_list[$key]['expressmoney'];
				$info_list[$key]['merge'] = sprintf("%.2f",$merge);//利润
				$currencytitle = ($merge!=0 && $info_list[$key]['budget']!=0)?$merge/$info_list[$key]['budget']*100:0;
				$info_list[$key]['currencytitle'] = $currencytitle==0?'0'.'%':sprintf("%.2f",$currencytitle)."%";//利润百分比
				$info_list[$key]['shouldmoney'] = ($order['currencytitle']=='CNY')?sprintf("%.2f",$order['shouldmoney']/$order['hl']):$value['shouldmoney'];
				$shouldmoney += $info_list[$key]['shouldmoney'];
				$expressmoney += $info_list[$key]['expressmoney'];
				$info_list[$key]['budget'] = ($order['currencytitle']=='CNY')?sprintf("%.2f",$order['budget']/$order['hl']):$value['budget'];
				$budget += $info_list[$key]['budget'];
				$refundj += $info_list[$key]['refundj'];
				$cost += $info_list[$key]['cost'];
				$lr += $merge;
            }
			$shouldmoney = sprintf("%.2f",$shouldmoney);
			$expressmoney = sprintf("%.2f",$expressmoney);
			$budget = sprintf("%.2f",$budget);
			$refundj = sprintf("%.2f",$refundj);
			$cost = sprintf("%.2f",$cost);
			$lr = sprintf("%.2f",$lr);
		    $pagenum = ceil($total/$perpage);
		    $over = $total-($start+$perpage);
		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'money'=>(array($shouldmoney,$budget,$expressmoney,$refundj,$cost,$lr)));
		    echo json_encode($rows);exit;
		}
		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
		$this->data['wlshop'] = $wlshop;
		if(isset($arg_array[0]))
		{
			$is = ($arg_array[0] == 'dlz')?'1':'2';
			$arg = $arg_array[0];
		}
		else
		{
			$is = '1';
			$arg = 'dlz';
		}
		$this->data['is'] = $is;
		$this->data['arg'] =$arg;
		$this->_Template('finance_cw',$this->data);
	}
	public function _ckcaiwu()//仓库财务
	{
		$user = $this->user->get_api($_SESSION['api']);
		if($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['page']))  
		{
		    $page = $this->input->post('page',true);
		    $perpage = $this->input->post('perpage',true);
			$timetk = $this->input->post('timetk',true);
			$timetj = $this->input->post('timetj',true);
			$shop = $this->input->post('shop',true);
			$source = $this->input->post('source',true);
			$library = $this->input->post('library',true);
			$warehouse = $this->input->post('warehouse',true);
			$orderinfo = $this->input->post('orderinfo',true);
			$user = $this->input->post('user',true);
			$name = $this->input->post('name',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			$fullorder = $this->input->post('fullorder',true);
			$where = "mergeid = 0";
			if($timetk && $timetj)
            {
                 $where  .= " and librarytime > '$timetk' and librarytime < '$timetj'";
            }
			if($shop)
            {
                $where  .= " and shop = '$shop'";
            }
			if($source)
            {
                $where  .= " and source = '$source'";
            }
			if($library)
            {
				$where  .= " and library = '$library'";
            }
			if($warehouse)
            {
                $where  .= " and type = '$warehouse'";
            }
			if($orderinfo)
            {
                $where  .= " and orderinfo = '$orderinfo'";
            }
			if($user)
            {
                $where  .= " and user = '$user'";
            }
			if($name)
            {
                $where  .= " and name = '$name'";
            }
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
			$shouldmoney=0;$expressmoney=0;$budget=0;$refundj=0;$purchase=0;$lr=0;
            //取得信息列表
            $info_list = $this->$fullorder->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,purchase,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
			 //格式化数据
            foreach ($info_list as $key=>$value)
		    {
				$order = $this->$fullorder->read($value['id']);
				$order['hl'] = $order['hl']!=0?$order['hl']:6.71;
				$shop = $this->shop->read($value['shop']);
				$info_list[$key]['shop'] = $shop['shopname'];
				$info_list[$key]['user'] = $shop['shopuser'];
				$warehouse = $this->warehouse->read($value['type']);
				$info_list[$key]['type'] = $warehouse['title'];
				$merge = $info_list[$key]['budget']-$info_list[$key]['refundj']-$info_list[$key]['purchase']/$order['hl']-$info_list[$key]['expressmoney'];
				$info_list[$key]['merge'] = sprintf("%.2f",$merge);//利润
				$currencytitle = ($merge!=0 && $info_list[$key]['budget']!=0)?$merge/$info_list[$key]['budget']*100:0;
				$info_list[$key]['currencytitle'] = $currencytitle==0?'0'.'%':sprintf("%.2f",$currencytitle)."%";//利润百分比
				$info_list[$key]['shouldmoney'] = ($order['currencytitle']=='CNY')?sprintf("%.2f",$order['shouldmoney']/$order['hl']):$value['shouldmoney'];
				$shouldmoney += $info_list[$key]['shouldmoney'];
				$expressmoney += $info_list[$key]['expressmoney'];
				$info_list[$key]['budget'] = ($order['currencytitle']=='CNY')?sprintf("%.2f",$order['budget']/$order['hl']):$value['budget'];
				$budget += $info_list[$key]['budget'];
				$refundj += $info_list[$key]['refundj'];
				$purchase += $info_list[$key]['purchase'];
				$lr += $merge;
            }
			$money = $this->$fullorder->find_all($where);
			$shouldmoney = sprintf("%.2f",$shouldmoney);
			$expressmoney = sprintf("%.2f",$expressmoney);
			$budget = sprintf("%.2f",$budget);
			$refundj = sprintf("%.2f",$refundj);
			$purchase = sprintf("%.2f",$purchase);
			$lr = sprintf("%.2f",$lr);
		    $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),'money'=>(array($shouldmoney,$budget,$expressmoney,$refundj,$purchase,$lr)));
		    echo json_encode($rows);exit;
		}
		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
		$this->data['wlshop'] = $wlshop;
		$this->_Template('finance_ckcw',$this->data);
	}
	//导出资金统计excel
	public function _excel()
	{
		if(isset($_GET['excel']))  
		{
			$timetk = $this->input->get('timetk',true);
			$timetj = $this->input->get('timetj',true);
			$shop = $this->input->get('shop',true);
			$source = $this->input->get('source',true);
			$library = $this->input->get('library',true);
			$warehouse = $this->input->get('warehouse',true);
			$orderinfo = $this->input->get('orderinfo',true);
			$user = $this->input->get('user',true);
			$name = $this->input->get('name',true);
			$xztime = $this->input->get('xztime',true);
			$country = $this->input->get('country',true);
			$fullorder = $this->input->get('fullorder',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			$where = "mergeid = 0";
			if($timetk && $timetj)
            {
                $where  .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
            }
			if($shop)
            {
                $where  .= " and shop = '$shop'";
            }
			if($source)
            {
                $where  .= " and source = '$source'";
            }
			if($library)
            {
				$where  .= " and library = '$library'";
            }
			if($warehouse)
            {
                $where  .= " and type = '$warehouse'";
            }
			if($orderinfo)
            {
                $where  .= " and orderinfo = '$orderinfo'";
            }
			if($user)
            {
                $where  .= " and user = '$user'";
            }
			if($name)
            {
                $where  .= " and name = '$name'";
            }
			if($country)
            {
                $where  .= " and country = '$country'";
            }
			/*  匹配ID加入  */
			$tc = array();$typeclass = array();
			$tclass = $this->typeclass->find_all();
			foreach ($tclass as $v) 
			{
				$tc[$v['id']] = $v['title'];
				$typeclass[$v['id']] = $v;
			}
			$shouldmoney=0;$expressmoney=0;$budget=0;$refundj=0;$refundj=0;$cost=0;$lr=0;
            //取得信息列表
			if($fullorder == 'fullordersmt')
			{
                $info_list = $this->fullordersmt->find_all($where,'id,shop,user,type,client,orderinfo,number,shouldmoney,budget,expressmoney,cost,refundj,refundy,rpaypal,paypal,rtext,merge,mergeid,orderremarks,clientremarks,shipremarks,country,express,librarytime,fpdata,hl,currencytitle');
			}
			else if($fullorder == 'fullorder')
			{
				 $info_list = $this->fullorder->find_all($where,'id,shop,user,type,client,orderinfo,number,shouldmoney,budget,expressmoney,cost,refundj,refundy,rpaypal,paypal,rtext,merge,mergeid,orderremarks,clientremarks,shipremarks,country,express,librarytime,fpdata,hl,currencytitle');
			}
			else if($fullorder == 'fullordertt')
			{
				 $info_list = $this->fullordertt->find_all($where,'id,shop,user,type,client,orderinfo,number,shouldmoney,budget,expressmoney,cost,refundj,refundy,rpaypal,paypal,rtext,merge,mergeid,orderremarks,clientremarks,shipremarks,country,express,librarytime,fpdata,hl,currencytitle');
			}
			else
			{
				$info_lista = $this->fullordersmt->find_all($where,'id,shop,user,type,client,orderinfo,number,shouldmoney,budget,expressmoney,cost,refundj,refundy,rpaypal,paypal,rtext,merge,mergeid,orderremarks,clientremarks,shipremarks,country,express,librarytime,fpdata,hl,currencytitle');
				$info_listb = $this->fullorder->find_all($where,'id,shop,user,type,client,orderinfo,number,shouldmoney,budget,expressmoney,cost,refundj,refundy,rpaypal,paypal,rtext,merge,mergeid,orderremarks,clientremarks,shipremarks,country,express,librarytime,fpdata,hl,currencytitle');
				$info_listc = $this->fullordertt->find_all($where,'id,shop,user,type,client,orderinfo,number,shouldmoney,budget,expressmoney,cost,refundj,refundy,rpaypal,paypal,rtext,merge,mergeid,orderremarks,clientremarks,shipremarks,country,express,librarytime,fpdata,hl,currencytitle');
				$info_list = array_merge($info_lista,$info_listb,$info_listc);
			}
			 //格式化数据
			 $i = 0;
			 $classid = $this->classid->sku();
			foreach ($info_list as $key=>$value)
		    {
				$value['hl'] = $value['hl']!=0?$value['hl']:6.71;
				$shop = $this->shop->read($value['shop']);
				$info_list[$key]['shop'] = $shop['shopname'];
				$info_list[$key]['user'] = $shop['shopuser'];
				$warehouse = $this->warehouse->read($value['type']);
				$info_list[$key]['type'] = $warehouse['title'];
				$country = $this->country->read($value['country']);
				$info_list[$key]['country'] = $country['ename'];
				$express = $this->express->read($value['express']);
				$info_list[$key]['express'] = $express['servicename'];
				$merge = $info_list[$key]['budget']-$info_list[$key]['refundj']-$info_list[$key]['cost']/$value['hl']-$info_list[$key]['expressmoney'];
				$info_list[$key]['merge'] = sprintf("%.2f",$merge);//利润
				$mergeid = ($value['budget']!=0)?$merge/$info_list[$key]['budget']*100:0;
				$info_list[$key]['mergeid'] = sprintf("%.2f",$mergeid)."%";//利润百分比
				$info_list[$key]['shouldmoney'] = ($value['currencytitle']=='CNY')?sprintf("%.2f",$value['shouldmoney']/$value['hl']):$value['shouldmoney'];
				$shouldmoney += $info_list[$key]['shouldmoney'];
				$expressmoney += $info_list[$key]['expressmoney'];
				$info_list[$key]['budget'] = ($value['currencytitle']=='CNY')?sprintf("%.2f",$value['budget']/$value['hl']):$value['budget'];
				$budget += $info_list[$key]['budget'];
				$refundj += $info_list[$key]['refundj'];
				$cost += $info_list[$key]['cost'];
				$lr += $info_list[$key]['merge'];
				$info_list[$key]['librarytime'] = date('Y-m-d H:i:s',$value['librarytime']);
				$fpdata = array();
				if(stripos($value['fpdata'],';') !== false)
				{
		   		    $fpdata = explode(';',rtrim($value['fpdata'],';'));
		            foreach ($fpdata as $ke=>$va)
		            {
						$dj = '';$ys = '';$hx = '';
						$pm = $classid;
		    			$jm = $classid;
						$bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
						$features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$va);
						$ts = explode('|',trim($features,'|'));
						if(stripos($ts[0],',') !== false)
						{
							$ft = explode(',',$ts[0]);
			    			$features = explode('-',trim($ft[1],'-'));
							$features[] = $ft[0];
						}
						else
						{
							$features = explode('-',trim($ts[0],'-'));
						}
						foreach($features as $k=>$v)
						{
							if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']]))
							{
								if($typeclass[$v]['bm'] != '')
								{
									$bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];
								}
							}
							if($v != 0)
							{
								if($typeclass[$v]['classid'] == 13)
								{
									$dj = $typeclass[$v]['title'];
								}
								if($typeclass[$v]['classid'] == 8)
								{
									$ys = $typeclass[$v]['title'];
								}
								if($typeclass[$v]['classid'] == 15)
								{
									$hx = $typeclass[$v]['title'];
								}
								if(isset($pm[$typeclass[$v]['classid']]))
								{
									if($typeclass[$v]['title'] == '9A')
									{
										$pm[$typeclass[$v]['classid']] = '9A';
									}
									else if($typeclass[$v]['title'] == '10A')
									{
										$pm[$typeclass[$v]['classid']] = '10A';
									}
									else
									{
										$clzh = $typeclass[$v]['zh'];
										if(stripos($typeclass[$v]['zh'],'|') !== false)
										{
											$clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
											$clzh = $clzh[0];
										}
										$pm[$typeclass[$v]['classid']] = $clzh;
									}
								}
								if(isset($jm[$typeclass[$v]['classid']]))
								{
									if($typeclass[$v]['jm'])
									{
						    			$jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
									}
								}
							}
						}
						$jm = array_filter($jm);//去除空值
						$jm = implode("-",$jm);
						$pm = array_filter($pm);//去除空值
						$zh = implode(" ",$pm);
						$zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
						$fpdata[$ke] = array($ts[5],$dj,$ys,$hx,$jm,'03'.implode("",$bmpx),$ts[2]);//内容,尺寸,等级,颜色,数量
                    }
				}
				$info_list[$key]['fpdata'] = $fpdata;
				$i++;
            }
			$shouldmoney = sprintf("%.2f",$shouldmoney);
			$expressmoney = sprintf("%.2f",$expressmoney);
			$budget = sprintf("%.2f",$budget);
			$refundj = sprintf("%.2f",$refundj);
			$cost = sprintf("%.2f",$cost);
			$lr = sprintf("%.2f",$lr);
			$data = array($shouldmoney.' USD',$budget.' USD',$expressmoney.' USD',$cost.' CNY',$refundj.' USD',$lr.' USD');
            $title = "财务统计信息";
            $titlename = "
            | ".$title." | 
|---|
            
            | NO. | 店铺名称 | 负责人 | 发货仓库 | 客户名称 | 订单号 | 编号 | 订单金额 USD | 预估金额 USD | 运费 USD | 成本 CNY | 补/退原额 USD | 补/退净额 USD | 补/退款交易号 | 线下交易号 | 原因 | 利润 USD | 利润率 | 订单备注 | 客户备注 | 发货备注 | 国家 | 物流 | 出库时间 | 
            | 订单产品信息 |  
			| 尺寸 | 等级 | 颜色 | 花型 | 料号 | 编码 | 数量 |  | 总条数 | 
            
"; 
            $filename = $title.".xls"; 
			$tail = "|  |  |  |  |  |  | 合计: | ".$data[0]." | ".$data[1]." | ".$data[2]." | ".$data[3]." | ".$data[4]." |  |  |  |  | ".$data[5]." |  |  | 
\n"; 
            $this->excel->get_fz($info_list,$titlename,$filename,$tail);
	    }
	}
	//仓库导出资金统计excel
	public function _ckexcel()
	{
		if(isset($_GET['excel']))  
		{
			$timetk = $this->input->get('timetk',true);
			$timetj = $this->input->get('timetj',true);
			$shop = $this->input->get('shop',true);
			$source = $this->input->get('source',true);
			$library = $this->input->get('library',true);
			$warehouse = $this->input->get('warehouse',true);
			$orderinfo = $this->input->get('orderinfo',true);
			$user = $this->input->get('user',true);
			$name = $this->input->get('name',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			$fullorder = $this->input->get('fullorder',true);
			$where = "mergeid = 0";
			if($timetk && $timetj)
            {
                $where  .= " and librarytime > '$timetk' and librarytime < '$timetj'";
            }
			if($shop)
            {
                $where  .= " and shop = '$shop'";
            }
			if($source)
            {
                $where  .= " and source = '$source'";
            }
			if($library)
            {
				$where  .= " and library = '$library'";
            }
			if($warehouse)
            {
                $where  .= " and type = '$warehouse'";
            }
			if($orderinfo)
            {
                $where  .= " and orderinfo = '$orderinfo'";
            }
			if($user)
            {
                $where  .= " and user = '$user'";
            }
			if($name)
            {
                $where  .= " and name = '$name'";
            }
			/*  匹配ID加入  */
			$tc = array();
			$typeclass = $this->typeclass->find_all();
			foreach ($typeclass as $v) 
			{
				if($_GET['excel'] == 2)
				{
					if($v['zh'] == '')
					{
						$tc[$v['id']] = $v['title'];
					}
					else
					{
					    $tc[$v['id']] = $v['zh'];
					}
				}
				else
				{
				    $tc[$v['id']] = $v['title'];
				}
			}
			$purchase=0;$cost=0;$lr=0;
            //取得信息列表
            $info_list = $this->$fullorder->find_all($where,'id,type,orderinfo,number,purchase,cost,merge,shipremarks,fpdata,hl,currencytitle');
			 //格式化数据
			 $i = 0;
			foreach ($info_list as $key=>$value)
		    {
				$order = $this->$fullorder->read($value['id']);
				$warehouse = $this->warehouse->read($value['type']);
				$info_list[$key]['type'] = $warehouse['title'];
				$merge = $info_list[$key]['cost']-$info_list[$key]['purchase'];
				$info_list[$key]['merge'] = sprintf("%.2f",$merge);//利润
				$purchase += $info_list[$key]['purchase'];
				$cost += $info_list[$key]['cost'];
				$lr += $info_list[$key]['merge'];
				$fpdata = array();
				if(stripos($value['fpdata'],';') !== false)
				{
		   		    $fpdata = explode(';',rtrim($value['fpdata'],';'));
		            foreach ($fpdata as $ke=>$va)
		            {
						$title = '';
			            $fg = explode('|',$va);
						$fg[0] = str_replace(array('163-','164-','165-','166-','-0-'),array('','','','','-'),$fg[0]);
						$cp = explode('-',rtrim($fg[0],'-'));
						$dj = (isset($cp[2]) && isset($tc[$cp[2]]))?$tc[$cp[2]]:'0';
						$ys = isset($cp[3])?(isset($tc[$cp[3]])?$tc[$cp[3]]:'没有此颜色'):'0';
						unset($cp[0],$cp[1],$cp[2],$cp[3]);
						foreach ($cp as $v)
		                {
							if(isset($tc[$v]))
							{
							    $title .= $tc[$v].' ';
							}
						}
						$fpdata[$ke] = array($fg[5],$dj,$ys,$title,$fg[2]);//内容,尺寸,等级,颜色,数量
                    }
				}
				$info_list[$key]['fpdata'] = $fpdata;
				$i++;
            }
			$purchase = sprintf("%.2f",$purchase);
			$cost = sprintf("%.2f",$cost);
			$lr = sprintf("%.2f",$lr);
			$data = array($purchase.' CNY',$cost.' CNY',$lr.' CNY');
            $title = "财务统计信息"; 
            $titlename = "
            | ".$title." | 
|---|
            
            | NO. | 发货仓库 | 订单号 | 编号 | 成本 | 外贸成本 | 利润 | 发货备注 |  | 总条数 | 
            
"; 
            $filename = $title.".xls"; 
			$tail = "|  |  |  | 合计: | ".$data[0]." | ".$data[1]." | ".$data[2]." |  |  |  | 
\n"; 
            $this->excel->get_fz($info_list,$titlename,$filename,$tail);
	    }
	}
	
	//导出DHL发货清单统计excel
	public function _dhlfp()
	{
		if(isset($_GET['excel']))  
		{
			$timetk = $this->input->get('timetk',true);
			$timetj = $this->input->get('timetj',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			$fullorder = $this->input->get('fullorder',true);
			$where = "mergeid = 0 and express = 1 and printtype = 1 and library = 2 and print = 3";
			if($timetk && $timetj)
            {
                $where  .= " and librarytime > '$timetk' and librarytime < '$timetj'";
            }
            //取得信息列表
            $info_list = $this->$fullorder->find_all($where,'id,librarytime,waybill,country,al,zwpm,zsbjz');
			 //格式化数据
			 $i = 1;
			foreach ($info_list as $key=>$value)
		    {
				$country = $this->country->read($value['country']);
				$info_list[$key]['country'] = $country['zname'];
				$info_list[$key]['id'] = $i;
				$info_list[$key]['librarytime'] = date('Y-m-d H:i:s',$value['librarytime']);
				$i++;
            }
            $title = "CN PLT-  发票导出清单"; 
            $titlename = "
            
            | 序号 | 业务日期 | 转单号码 | 目的地 | 二字码 | 中文品名 | 申报价 | 
"; 
            $filename = $title.".xls"; 
			$tail = ""; 
            $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
	    }
	}
	
	public function _product($arg_array)
	{
		$post = $this->input->post(NULL, TRUE);
		if(isset($post['id']))
		{
			$id = $this->input->post('id',true);
			$post['fpdata'] = $this->input->post('fpdata');
			$post['expressmoney'] = $this->input->post('expressmoney',true);
			$post['cost'] = $this->input->post('cost',true);
			$post['purchase'] = $this->input->post('purchase',true);
			$fullorder = $this->input->post('fullorder',true);
			/**
			if($post['state'] == 216 && $ud['state'] != 216)
			{
				echo json_encode(array('msg'=>'不可修改为完成状态','success'=>false));exit;
			}
			**/
			if($this->$fullorder->save($post,$id))
        	{
         		echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
       	 	}
       		else
        	{
           		echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
        	}
		}
		$fullorder = $arg_array[0];
		$is = ($fullorder == 'fullorder')?'1':'2';
		$fpdata = array();
		$fullorder = $this->$fullorder->read($arg_array[1]);
		$fullorder['parameter'] = str_replace(",","---",$fullorder['parameter']);
		$e = $fullorder['express'];//快递信息
		$c = $fullorder['country'];//国家信息
        $data = $this->logistics->find_all('express = "'.$e.'" and country = "'.$c.'"');
		if($data)
		{
			$fullorder['expressmoney'] = sprintf("%.2f",$data[0]['firstmoney']);
		}
		$this->data['fullorder'] = $fullorder;
		$this->data['countrys'] = $this->country->find_all();
		$this->data['express'] = $this->express->find_all();
		if(stripos($fullorder['fpdata'],';') !== false)
		{
		    $fpdata = explode(';',rtrim($fullorder['fpdata'],';'));
		    foreach ($fpdata as $k=>$v) 
		    {
			    $fpdata[$k] = explode('|',$v);
            }
		}
		$this->data['fpdata'] = $fpdata;
		$shop = $this->shop->read($fullorder['shop']);
		$this->data['et'] = $shop['estimaterate'];//此店铺配置预计到帐金额比例
		//单项开始
		$warehouse = $this->warehouse->read($fullorder['warehouse']);//发货仓库
		$state = $this->typeclass->read($fullorder['state']);//订单状态
		$country = $this->country->read($fullorder['country']);//国家
		if($fullorder['capital'] == 1)
		{
			$capital = '暂未支付';
		}
		else if($fullorder['capital'] == 2)
		{
			$capital = '部分支付';
		}
		else if($fullorder['capital'] == 3)
		{
			$capital = '全部支付';
		}
		if($fullorder['printtype'] == 1)
		{
			$printtype = '运单';
		}
		else if($fullorder['printtype'] == 2)
		{
			$printtype = '发货单';
		}
		else if($fullorder['printtype'] == 3)
		{
			$printtype = '不打印单据';
		}
		else
		{
			$printtype = '未选择';
		}
		$this->data['warehouse'] = $warehouse['title'];
		$this->data['state'] = $state['title'];
		$this->data['capital'] = $capital;
		$this->data['country'] = $country['ename'];
		$this->data['printtype'] = $printtype;
		$this->data['is'] = $is;
		$systemwigsout = $this->systemwigsout->get_number($fullorder['number']);
		$wigsout = array();
		if($systemwigsout)
		{
			$cz = explode('|',trim($systemwigsout['cz'],'|'));
			$cztime = explode('|',trim($systemwigsout['cztime'],'|'));
			$zw = array(1=>'配货',2=>'高针',3=>'完成',4=>'曲发',5=>'前处理',6=>'后处理',7=>'发型师',8=>'包装');
			if($systemwigsout['cz'] != '' && count($cz) > 0)
			{
				for($i=0;$idata['systemwigsout'] = $wigsout;
		//单项结束
		$this->_Template('finance_product',$this->data);
	}
	
	public function _ouout() //财务汇总导出
	{
		if(isset($_GET['excel']))  
		{
			$timetk = $this->input->get('timetk',true);
			$timetj = $this->input->get('timetj',true);
			$shop = $this->input->get('shop',true);
			$source = $this->input->get('source',true);
			$library = $this->input->get('library',true);
			$warehouse = $this->input->get('warehouse',true);
			$orderinfo = $this->input->get('orderinfo',true);
			$user = $this->input->get('user',true);
			$name = $this->input->get('name',true);
			$xztime = $this->input->get('xztime',true);
			$country = $this->input->get('country',true);
			$fullorder = $this->input->get('fullorder',true);
			$timetk = strtotime($timetk);
			$timetj = strtotime($timetj);
			$where = "mergeid = 0";
			if($timetk && $timetj)
            {
                $where  .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
            }
			if($fullorder == 'sd')
        	{
         		echo '此功能只能单独导出独立站或速卖通数据';exit;
       	 	}
			if($shop)
            {
                $where  .= " and shop = '$shop'";
            }
			if($source)
            {
                $where  .= " and source = '$source'";
            }
			if($library)
            {
				$where  .= " and library = '$library'";
            }
			if($warehouse)
            {
                $where  .= " and type = '$warehouse'";
            }
			if($orderinfo)
            {
                $where  .= " and orderinfo = '$orderinfo'";
            }
			if($user)
            {
                $where  .= " and user = '$user'";
            }
			if($name)
            {
                $where  .= " and name = '$name'";
            }
			if($country)
            {
                $where  .= " and country = '$country'";
            }
            //数据排序
            $order_str = "id desc";
            if(empty($page))
		    {
                $start = 0;
		    	$perpage = 1;
            }
		    else
		    {
                $start = ($page - 1)*$perpage;
            }
            //取得信息列表
			$info_list = $this->$fullorder->find_all($where,'fpdata,library');
			$rowsc = array();$rowst = array();
			foreach ($info_list as $key=>$value) 
		    {
				$fpdata = explode(';',rtrim($value['fpdata'],';'));
				foreach ($fpdata as $va) 
		        {
					$fpdatason = explode('|',$va);
					$fpdatason[1] = rtrim($fpdatason[1],' ');
					str_replace(array('Peruvian','Indian','Brazilian','Malaysian'),array('','','',''),$fpdatason[1]);
					if($value['library'] == 2)
					{
						$c = 1; $t = 0;
					}
					else
					{
						$c = 0; $t = 1;
					}
					if(isset($rows[$fpdatason[1]]))
					{
						$rows[$fpdatason[1]]['c'] += $c;
						$rows[$fpdatason[1]]['t'] += $t;
					}
					else
					{
						$rows[$fpdatason[1]]['a'] = $fpdatason[1];
						$rows[$fpdatason[1]]['c'] = $c;
						$rows[$fpdatason[1]]['t'] = $t;
					}
				}
		    }
            $title = date('Y-m-d',$timetk).'至'.date('Y-m-d',$timetj).'汇总详情'; 
            $titlename = "
			| ".$title." | 
|---|
            
			| 产品名称 | 销售数量 | 退货数量 | 
            
"; 
            $filename = $title.".xls";
			$tail = "";
            $this->excel->get_fz2($rows,$titlename,$filename,$tail);
	    }
	}
	
	public function _cksize()
	{
		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);
			$shop = $this->input->get('shop',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 and shop != 9 and shop != 26";$gj = "";$ck = "";
			if($category)
            {
                $where  .= " and fpdata like '%-$category-%'";
            }
			if($size)
            {
                $where  .= " and fpdata like '%-$size-%'";
            }
			if($grade)
            {
                $where  .= " and fpdata like '%-$grade-%'";
            }
			if($color)
            {
                $where  .= " and fpdata like '%-$color-%'";
            }
			if($lowe)
            {
                $where  .= " and fpdata like '%-$lowe-%'";
            }
			if($shop)
            {
				$shopdata = '';
                $sd = explode(',',rtrim($shop,','));
				foreach ($sd as $v) 
			    {
				    $shopdata .= "shop = '$v' or ";
				}
				 $where  .= " and (".rtrim($shopdata,'or ').")";
            }
			if($warehouse)
            {
				$warehousedata = '';
                $wd = explode(',',rtrim($warehouse,','));
				foreach ($wd as $v) 
			    {
				    $warehousedata .= "warehouse = '$v' or ";
				}
				 $where  .= " and (".rtrim($warehousedata,'or ').")";
            }
			if($sku)
            {
                $where  .= " and sku like '%$sku%'";
            }
			if($ktime && $jtime)
            {
               $where .= " and librarytime > '$ktime' and librarytime < '$jtime'";
            }
			$sidwhere = '';
			if($sid)
            {
				$sd = "";
				$s = explode(',',trim($sid,','));
				foreach ($s as $value) 
		    	{
					$sd .= " id = ".$value." or";
				}
                $sidwhere  .= " and (".rtrim($sd,'or').")";
            }
			$typeclass = array();
			$tc = $this->typeclass->find_all();
		    foreach ($tc as $v)
		    {
			    $typeclass[$v['id']] = array('ae'=>$v['spare'],'zh'=>$v['zh']);
		    }
            //取得信息列表
			$timeread  = $ktime;
			$timenum = ceil(($jtime - $ktime) / (24*3600));
			$timelist = array();
			for($i=4;$i<41;$i++)
			{
				 if ($i%2==0) 
				 {
				    $timelist[$i] = 0;
				 }
			}
				$info_lista = $this->fullorder->find_all($where.$sidwhere,'fpdata,number');
				$info_listb = $this->fullordersmt->find_all($where.$sidwhere,'fpdata,number');
				$info_listc = $this->fullordertt->find_all($where.$sidwhere,'fpdata,number');
				$info_list = array_merge($info_lista,$info_listb,$info_listc);
				//echo "";
				//print_r($info_list);
				//exit();
				$rows = array();$list = array();$cw = array();
				foreach ($info_list as $key=>$value) 
		    	{
					$thistime = $timelist;
					$zdata = explode(';',trim($value['fpdata'],';'));
					foreach ($zdata as $v) 
		    	    {
						if(stripos($v,'-131-') !== false || ($category != '' && stripos($v,'-'.$category.'-') === false))
						{
							continue;
						}
					    $fpdata = explode('|',trim($v,'|'));
					    $xqdata = explode(',',trim($fpdata[0],','));
						 $cc = $typeclass[$xqdata[0]]['ae'];
						if(!isset($xqdata[1]))
						{
							$cw[] = array($value['fpdata'],$value['number']);
						}
					    $sku = $xqdata[1];
					    if(isset($rows[$sku]))
					    {
						     $rows[$sku][2][$cc] += 1;
					    }
					    else
					    {
							$zh = '';
							$zhdata = explode('-',trim($sku,'-'));
							foreach ($zhdata as $kk => $vv)
							{
								if(isset($typeclass[$vv]['zh']) && $kk != 0)
								{
								    $zh .= $typeclass[$vv]['zh'].' ';
								}
							}
							$rows[$sku][0] = preg_replace('/ (\d+)inch/','',$fpdata[1]);
							$rows[$sku][1] = trim($zh,' ');
						    $rows[$sku][2] = $thistime;
						    $rows[$sku][2][$cc] += 1;
					    }
					}
		    	}
            	$str = "
       	 	
        	
        	";
			
			$str .= "";
			$str .="| 英文";
			$str .=" | 中文";
			foreach ($timelist as $k=>$v)
            {
            	$str .=" | ".$k."";
			}
           	$str .=  " | 
"; 
			$str .= ""; 
			foreach ($rows as $key=>$val)
			{
				$str .= "| ".$val[0].""; 
				$str .= " | ".$val[1].""; 
		   		foreach ($val[2] as $k=>$v)
			    {
					$str .= " | ".$v.""; 
				}
				$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);
	    }
		if(isset($_SESSION['api']))
		{
			$user = $this->user->get_api($_SESSION['api']);
			$usp = $user;
		    $fgshop = "";$sid = "";
		    $usersp = explode('|',trim($user['shop'],'|'));
			foreach ($usersp as $value) 
		    {
				$fgshop .= " shop = ".$value." or";
				$sid .= " id = ".$value." or";
			}
		}
		$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
		$this->data['wlshop'] = $wlshop;
		$this->_Template('finance_cksize',$this->data);
	}
}