<?php

class Logistics_LogisticsController extends Ec_Controller_Action
{

    public function preDispatch ()
    {
        $this->tplDirectory = "logistics/views/logistics/";
        $this->customerAuth = new Zend_Session_Namespace("customerAuth");
    }
    
    public function indexAction ()
    {
    	$this->listOrderAction();
    }
    
    private function getPostData()
    {
    	$postData = array();
    	//订单信息
    	$order = array();
    	$order['reference_no'] = trim($this->_request->getParam('reference_no',''));
    	$order['sm_code'] = trim($this->_request->getParam('sm_code',''));
    	$order['lo_weight'] = trim($this->_request->getParam('lo_weight',''));
		$order['ref_tracking_number'] = trim($this->_request->getParam('ref_tracking_number',''));
		$order['customer_code'] = trim(trim($this->_request->getParam('customer_code','')));    	
		$order['customer_id'] = 0;
		if($order['customer_code']){
			 $customer = Service_Customer::getByField($order['customer_code'],'customer_code');
			 if($customer){
			 	$order['customer_id'] = $customer['customer_id'];
			 }
		}	
		
		$order['warehouse_id'] = 3;	//仓库
    	//收件人信息
    	$receiver = array();
    	$receiver['loa_name'] = trim($this->_request->getParam('loa_name',''));
    	$receiver['loa_company'] = trim($this->_request->getParam('loa_company',''));
    	$receiver['loa_country'] = trim($this->_request->getParam('loa_country',''));
    	$receiver['loa_zipcode'] = trim($this->_request->getParam('loa_zipcode',''));
    	$receiver['loa_phone'] = trim($this->_request->getParam('loa_phone',''));
    	$receiver['loa_address'] = trim($this->_request->getParam('loa_address',''));
    	//海关申报信息
    	$hsList = array();
    	$loh_ids = $this->_request->getParam('loh_id','');
    	if(is_array($loh_ids) && count($loh_ids)>0 ) {
    		$loh_hs_names = $this->_request->getParam('loh_hs_name','');
    		$loh_units = $this->_request->getParam('loh_unit','');
    		$loh_prices = $this->_request->getParam('loh_price','');
    		$loh_quantitys = $this->_request->getParam('loh_quantity','');
    		$loh_hs_codes = $this->_request->getParam('loh_hs_code','');
    		$loh_names = $this->_request->getParam('loh_name','');
    		$loh_notes = $this->_request->getParam('loh_note','');
    		foreach($loh_ids as $key=>$loh_id) {
    			$row = array();
    			$row['loh_id'] = trim($loh_id);
    			$row['loh_hs_name'] = trim($loh_hs_names[$key]);
    			$row['loh_unit'] = trim($loh_units[$key]);
    			$row['loh_price'] = trim($loh_prices[$key]);
    			$row['loh_quantity'] = trim($loh_quantitys[$key]);
    			$row['loh_hs_code'] = trim($loh_hs_codes[$key]);
    			$row['loh_name'] = trim($loh_names[$key]);
    			$row['loh_note'] = trim($loh_notes[$key]);
    			$hsList[] = $row;
    		}
    	}
    	$postData['order'] = $order;
    	$postData['address'] = $receiver;
    	$postData['hs_list'] = $hsList;
    	return $postData;
    }
    /*建立订单*/
    public function createOrderAction() {
        if($this->_request->isPost()){
        	$result = array('ask'=>0, 'message'=>'');
        	$postData = $this->getPostData();
			$postData['action'] = 'add';
        	$v = Service_LogisticsProcess::validator($postData);			
        	if($v === true) {
        		$db = Common_Common::getAdapter();
        		$db->beginTransaction();
        		try{
                                $postData['order']['is_remote_city']=0;
                                if(in_array($postData['order']['sm_code'],Service_LogisticsProcess::$checkRemoteCode)){
                                     $orderProcess=new Service_OrderProcess();
                                    $isRemote=$orderProcess->isRemoteCity($postData['address']['loa_country'],$postData['address']['loa_city'],$postData['address']['loa_zipcode']);
                                    if($isRemote){
                                           $postData['order']['is_remote_city']=1;
                                    }
                                }
        			$logistics_code = Service_LogisticsProcess::addLogisticsOrder($postData);
        			$db->commit();
        			$result['ask'] = 1;
                                $result['message'] = '创建订单['.$logistics_code.']成功';
                                if(isset($isRemote)&&$isRemote){
                                     $result['message'] .= '<br>订单属于偏远地区，如需修改，请在草稿状态下进行编辑修改';
                                }
        			$result['logistics_code'] = $logistics_code;
        		} catch(Exception $e) {
        			$db->rollback();
        			$result['message'] = $e->getMessage();
        		}
        	} else {
        		$result['message'] = implode('<br>', $v);
        	}        	
			echo json_encode($result);
        } else {        	
        	$hsunit = Service_ProductUom::getByCondition();
        	$this->view->hsunit = $hsunit;
        	$this->view->hsunitJson = json_encode($hsunit);
			/* $shipMethods = Service_ShippingMethod::getByCondition(array('method_code_arr'=>array('SWPT','BH-MMP')));
			$this->view->shipMethods = $shipMethods; */
			$this->view->shipMethods = Service_LogisticsProcess::getShipMethods();			
        	echo Ec::renderTpl($this->tplDirectory.'order-create.tpl','layout_from_oms');
			
        }        
    }
     /*修改订单*/
    public function editOrderAction() {
    	$logistics_code = trim($this->_request->getParam('logistics_code',''));
    	if(empty($logistics_code)) exit('error parameter');
    	$aOrder = Service_LogisticsOrder::getByField($logistics_code, 'logistics_code');
    	if($this->_request->isPost()){
    		$result = array('ask'=>0, 'message'=>'');
    		$postData = $this->getPostData();
			$postData['action'] = 'edit';
    		$v = Service_LogisticsProcess::validator($postData,$logistics_code);
    		if($v === true) {
	    		$db = Common_Common::getAdapter();
	    		$db->beginTransaction();
	    		try{    	
                                 $postData['order']['is_remote_city']=0;
                                if(in_array($postData['order']['sm_code'],Service_LogisticsProcess::$checkRemoteCode)){
                                     $orderProcess=new Service_OrderProcess();
                                    $isRemote=$orderProcess->isRemoteCity($postData['address']['loa_country'],$postData['address']['loa_city'],$postData['address']['loa_zipcode']);
                                    if($isRemote){
                                           $postData['order']['is_remote_city']=1;
                                    }
                                }
	    			Service_LogisticsProcess::editLogisticsOrder($logistics_code, $postData);
	    			$db->commit();
	    			$result['ask'] = 1;
                                $result['message'] = '编辑订单['.$logistics_code.']成功';
                                if(isset($isRemote)&&$isRemote){
                                     $result['message'] .= '<br>订单属于偏远地区，如需修改，请在草稿状态下进行编辑修改';
                                }
	    			$result['logistics_code'] = $logistics_code;
	    		} catch(Exception $e) {
	    			$db->rollback();
	    			$result['message'] = $e->getMessage();
	    		}
    		} else {
    			$result['message'] = implode('<br>', $v);
    		}
    		echo json_encode($result);
    	} else {    		
    		if(empty($aOrder) || $aOrder['lo_status']!=0) exit('error parameter');
			$this->view->country = Common_DataCache::getShipTypeCountryMap();
    		$this->view->logistics_code = $logistics_code;
    		$this->view->aOrder = $aOrder;
    		$this->view->aAddress = Service_LogisticsOrderAddress::getByField($logistics_code, 'logistics_code');
    		$this->view->hsList = Service_LogisticsOrderHs::getByCondition(array('logistics_code'=>$logistics_code));
    		$hsunit = Service_ProductUom::getByCondition();
    		$this->view->hsunit = $hsunit;
    		$this->view->hsunitJson = json_encode($hsunit);
			/* $shipMethods = Service_ShippingMethod::getByCondition(array('method_code_arr'=>array('SWPT','BH-MMP')));
			$this->view->shipMethods = $shipMethods; */			
			$this->view->shipMethods = Service_LogisticsProcess::getShipMethods();
			echo Ec::renderTpl($this->tplDirectory.'order-create.tpl','layout_from_oms');
    	}
    }
    
	/*物流订单列表*/
    public function listOrderAction ()
    {
    	
            
            $page = $this->_request->getParam('page', 1);
            $pageSize = $this->_request->getParam('pageSize', 20);
            
            $page = $page ? $page : 1;
            $pageSize = $pageSize ? $pageSize : 20;
			//$pageSize =3;
            $pageSize = min($pageSize,1000);
            $condition = array();
            /* 以下为提交数据整理 */
            $orders_code_CustomerReference = trim($this->_request->getParam("orders_code_CustomerReference",""));
            $condition["orders_code_CustomerReference"] = $orders_code_CustomerReference;       
            if (!empty($orders_code_CustomerReference)) {
                $page=1;
                $pageSize=20;
            }
        
            $warehouse_id = $this->_request->getParam("warehouse_id","");
            $condition["warehouse_id"] = $warehouse_id;
			
            $customer_code = $this->_request->getParam("customer_code","");
			$condition["customer_code"] = $customer_code;

            $country_id = $this->_request->getParam("country_id","");
            $condition["country_id"] = $country_id;
            
            $orders_status = $this->_request->getParam("orders_status","0");
            
        
            $shipping_method = $this->_request->getParam("shipping_method","");
            $condition["sm_code"] = $shipping_method;                    

            //增加开始结束时间
            $add_time_start	= trim($this->_request->getParam('add_time_start',''));
            $condition["add_time_start"] = $add_time_start;
            
            $add_time_end	= trim($this->_request->getParam('add_time_end',''));
            $condition['add_time_end']	= $add_time_end;
            $orders_status_arr = explode(',',$orders_status);
			$condition['order_status_arr'] = $orders_status_arr;
			$condition['loa_type'] = "0";

            $receiving_time_start = $this->_request->getParam("receiving_time_start","");
            $condition['receiving_time_start'] = $receiving_time_start;

            $receiving_time_end = $this->_request->getParam("receiving_time_end","");
            $condition['receiving_time_end'] = $receiving_time_end;
            if($receiving_time_start!=""||$receiving_time_end!=""){
                $a = array();
                if($receiving_time_start!=""){
                    $a['add_time_start'] = $receiving_time_start;
                }
                if($receiving_time_end!=""){
                    $a['add_time_end'] = $receiving_time_end;
                }

                $receivingBatchOrder = Service_ReceivingBatchOrder::getByCondition($a,"*",0,0);
                $logisticsCodeArr = array();
                if(!empty($receivingBatchOrder)){
                    foreach($receivingBatchOrder as $k=>$v){
                        if(!in_array($v['logistics_code'],$logisticsCodeArr)){
                            $logisticsCodeArr[] = $v['logistics_code'];
                        }
                    }
                }else{
                    $logisticsCodeArr = array('notlogisticsCode');
                }
                $condition['logistics_code_arr'] = $logisticsCodeArr;
            }

			 $service_number	= trim($this->_request->getParam('service_number',''));	
			 $condition['service_number'] = $service_number;
            //print_r(array('1'));
			//print_r($orders_status_arr);     	
            $return = array(
                    "ask" => 0,
                    "message" => "No Data"
            );
            /* 以下为业务逻辑方法调用 */
            $count = Service_LogisticsOrder::getJoinOrderByCondition($condition, 'count(*)');
            $return['count'] = $count;
            $cacheProduct = array();
            $rows = '';
            if ($count) {
                $rows = Service_LogisticsOrder::getJoinOrderByCondition($condition, '*', $pageSize,$page,'lo_id desc');
                foreach($rows as $k=>$v){

                    $products = array();                    
                    $products= Service_LogisticsOrderHs::getByCondition(array('logistics_code'=>$v['logistics_code']));
                    
					 foreach($products as $kk=>$vv){
            			if($vv['loh_unit']){
							$productUom = Service_ProductUom::getByField($vv['loh_unit'],"pu_code","*");
            				$products[$kk]['pu_name'] = $productUom['pu_name'];	
						}  	
					 }				
					
					$v['order_product'] = $products;               
                    if($v['loa_country']){
						$countries= Service_Country::getByField($v['loa_country'],'country_id','*');
						 $v['country_name'] = $countries['country_name'];
					}
                              
                   
                    $rows[$k]=$v;
                }

                $return['data'] = $rows;
                $return['ask'] = 1;
                $return['message'] = "";
            }

			

            $allStatus = Service_LogisticsOrderProcess::getOrderStatus();
           //print_r($orderStatusArr);
            //处理数量问题
			
            if(!empty($allStatus)){
            	$numConditon = $condition;
            	foreach($allStatus as $keys=>$values){
            		$numConditon['order_status_arr'] = explode(',',$keys);
            		$countnum = Service_LogisticsOrder::getJoinOrderByCondition($numConditon, 'count(*)');
            		$allStatus[$keys] = $values."({$countnum})";
            	}
            }
			     
            
        $warehouse = Common_DataCache::getWarehouse();
          $warehouseId = array();
        if(!empty($warehouse)){
            foreach($warehouse as $keyw=>$wh){
                if($wh['warehouse_scope']=='0'){
                    unset($warehouse[$keyw]);
                }else{
                    $warehouseId[] = $wh['warehouse_id'];
                }
            }
        }
        $warehouseId[] = '0';
        $warehouseId[] = '3';
        $this->view->warehouse = $warehouse;
        
        $this->view->result = $rows;
		
 		$countryArr = Common_DataCache::getShipTypeCountryMap();
		$this->view->country = $countryArr;		
        
        $shipType = Common_DataCache::getShippingMethod();
        foreach($shipType as $key=>&$value){

            if ($value['warehouse_id']==1) {
                unset($shipType[$key]);
            }
            if(!in_array($value['warehouse_id'],$warehouseId)){
                unset($shipType[$key]);
            }
        }

       /* $smArray = array();
        foreach($shipType as $sm){
            $smArray[] = $sm['sm_code'];
        }
        sort($smArray);*/
        $shipType=Common_Common::multisort($shipType);
        $this->view->shipType = $shipType;
        $this->view->count = $count;
        $this->view->page	  =	$page;
        $this->view->pageSize = $pageSize;

        $this->view->orderStatusArr = $allStatus;
       
        $this->view->params = $condition;
        $this->view->orders_status=$orders_status;
		
        echo Ec::renderTpl($this->tplDirectory . "order-list.tpl",'layout_from_oms');
	
	
    	
    }
	
   /*订单详细*/
    public function detailAction ()
    {
        $ordersCode = $this->_request->getParam('ordersCode','');
 
        $order = Service_LogisticsOrder::getByField($ordersCode,"logistics_code","*");
		if(empty($order)){ exit("没有找到订单.");}		
		if($order['warehouse_id']){      	
        	$warehouse = Service_Warehouse::getByField($order['warehouse_id'],"warehouse_id","*");
        	$order['warehouse_code'] = $warehouse['warehouse_code'];
		}
		$order['orderStatusText'] =  Service_LogisticsOrderProcess::getOrderStatusText($order['lo_status']);		
        $this->view->order = $order;
      
        $orderAddress = Service_LogisticsOrderAddress::getByField($ordersCode,'logistics_code',"*");
        $country = Service_Country::getByField($orderAddress['loa_country'],"country_id","*");
        $orderAddress['country_name'] = $country['country_name'];
        $this->view->orderAddress = $orderAddress;
		
		
        $orderProducts = Service_LogisticsOrderHs::getByCondition(array('logistics_code'=>$ordersCode),"*");
        if($orderProducts){
			foreach($orderProducts as $k=>$v){
            	if($v['loh_unit']){
					$productUom = Service_ProductUom::getByField($v['loh_unit'],"pu_code","*");
            		$orderProducts[$k]['pu_name'] = $productUom['pu_name'];	
				}
				
        	}     
		}  
        $this->view->orderProduct = $orderProducts;
      
        $logs = Service_LogisticsOrderLog::getByCondition(array('logistics_code'=>$ordersCode),"*",0,0,array('lol_id DESC'));
		foreach($logs as $key=>$value){
            if($value['lol_operator']>0){
                $user = Service_User::getByField($value['lol_operator'],'user_id',"*");
                $logs[$key]['user_code'] = $user['user_code'];
            }
        }
        $this->view->logs = $logs;
        $allStatus = Service_LogisticsOrderProcess::getOrderStatusAll();
        $this->view->orderStatusArr = $allStatus;

        echo Ec::renderTpl($this->tplDirectory . "order-detail.tpl",'layout_from_oms');
    }	
	
   	/*运输方式到国家*/
    public function getCountriesByShipMethodAction(){	
		$result = array('ask'=>0,'data'=>array());
		$sm_code = $this->_request->getParam('sm_code','SWPT');
		//$warehouse_id = $this->_request->getParam('warehouse_id',3);
		$countries = Service_SmCountryMap::getJoinCountryByGroupCondition(array('sm_code'=>$sm_code,'warehouse_id'=>$warehouse_id),'smcm_id');
		if($countries){
			$result['ask'] =  1;
			$result['data'] =  $countries;			
		}
		die(Zend_Json::encode($result));
		
	}	
    
    /**
     * @todo 确认订单
     * @author solar
     */
    public function confirmAction(){
    	$return = array('ask' => 0, 'message' =>Ec_Lang::getInstance()->getTranslate('ConfirmOrder').','.Ec_Lang::getInstance()->getTranslate('fail'));
    	$orderArr	= $this->_request->getParam('orderArr','');
    	if (!empty($orderArr)) {
    		$success=0;
    		$failse=0;
    		$customer = $this->_customerAuth;
    		$customerId = $customer['id'];
    		$failsStr = '';
    		foreach($orderArr as $key=>$logistics_code){
    			$result = Service_LogisticsOrderProcess::confirmOrder($logistics_code);
    			if (!empty($result) && $result['ask']=='1') {
    				$success++;
                                $successMsg='订单号'."[{$logistics_code}]成功.";
                                if($result['is_remote_city']){
                                    $successMsg.='订单属偏远地区';
                                }
    				$return['detailmessage'][] =$successMsg; 
    			}else{
    				$return['detailmessage'][] = '订单号'."[{$logistics_code}]失败:".$result['message'];
    				$failse++;
    			}
    		}
    		if($success>0){
    			$return['ask']=1;
    		}
    		$return['message']=Ec_Lang::getInstance()->getTranslate('ConfirmOrder').','.Ec_Lang::getInstance()->getTranslate('success').':'.$success.Ec_Lang::getInstance()->getTranslate('fail').' :'.$failse.'<br/>'.$failsStr;
    	}
    	die(Zend_Json::encode($return));
    }
    
    /**
     * @todo 提交订单
     * @author solar
     */
    public function submitAction() {
    	$logisticsCode = $this->_request->getParam("logisticsCode","");
    	if(empty($logisticsCode)) exit('error parameter');
    	$aOrder = Service_LogisticsOrder::getByField($logisticsCode, 'logistics_code');
    	if(empty($aOrder) || $aOrder['lo_status']!=1) exit('error parameter');
		
    	$customerId = $aOrder['customer_id'];
    	$result = Service_LogisticsOrderProcess::submitOrder($logisticsCode,$customerId);
    	if($result['ask']==0) exit('inner error');
    	$this->printLabelAction();
    }
    
    /**
     * @author solar
     * @todo 打印标签
     */
    public function printLabelAction() {
    	/*$logisticsCode = $this->_request->getParam("logisticsCode","");
    	if(empty($logisticsCode)) exit('error parameter');
    	$aOrder = Service_LogisticsOrder::getByField($logisticsCode, 'logistics_code');
    	if(empty($aOrder)) exit('error parameter');
        $smInfo = Service_ShippingMethod::getByField($aOrder['sm_code'],"sm_code","*");
        if($smInfo['sm_class_code']=="CPS"){
            $aOrder['tracking_number'] = "";
        }else{
            $trackingNumber = Service_ServiceTrackingNumber::getTrackingNumber($aOrder['sm_code'], $aOrder['ref_tracking_number']);
            $aOrder['tracking_number']  = $trackingNumber;
        }
    	//$aOrder['tracking_number'] = Service_ServiceTrackingNumber::getTrackingNumber($aOrder['sm_code'], $aOrder['ref_tracking_number']);
    	$aAddress = Service_LogisticsOrderAddress::getByField($logisticsCode, 'logistics_code');
    	$country = Service_Country::getByField($aAddress['loa_country'],'country_id',"*");
    	$aAddress['country_name'] = $country['country_name_en'];
    	$hsList = Service_LogisticsOrderHs::getByCondition(array('logistics_code'=>$logisticsCode));
    	$this->view->aOrder = $aOrder;
    	$this->view->aAddress = $aAddress;
    	$this->view->hsList = $hsList;
    	$total_price = 0.00;
    	foreach($hsList as $hsRow) $total_price += $hsRow['loh_total_price'];
    	$this->view->totalPrice = $total_price;*/
    	/* $result = Service_LogisticsOrderProcess::submitOrder($logisticsCode);
    	if($result['ask']==0) exit('inner error'); */
    	//echo $this->view->render($this->tplDirectory . "sw.tpl");

        $logisticsCode = $this->_request->getParam("logisticsCode","");
        if(empty($logisticsCode)) exit('error parameter');
        $aOrder = Service_LogisticsOrder::getByField($logisticsCode, 'logistics_code');
        if(empty($aOrder)) exit('error parameter');
        $smInfo = Service_ShippingMethod::getByField($aOrder['sm_code'],"sm_code","*");
        //平邮
        //if($smInfo['sm_class_code']=="CPS") $aOrder['ref_tracking_number'] = "";
        //$aOrder['tracking_number'] = Service_ServiceTrackingNumber::getTrackingNumber($aOrder['sm_code'], $aOrder['ref_tracking_number']);
        $aAddress = Service_LogisticsOrderAddress::getByWhere(array('logistics_code'=>$logisticsCode, 'loa_type'=>0));
        $country = Service_Country::getByField($aAddress['loa_country'],'country_id',"*");
        $aAddress['country_name_en'] = $country['country_name_en'];
        $aAddress['country_name'] = $country['country_name'];
        $hsList = Service_LogisticsOrderHs::getByCondition(array('logistics_code'=>$logisticsCode));
        $total_price = 0.00;
        foreach($hsList as $hsRow) $total_price += $hsRow['loh_total_price'];
        $aOrder['counthsList'] = count($hsList)>5?5:count($hsList);
        $this->view->totalPrice = $total_price;
        $this->view->aOrder = $aOrder;
        $this->view->aAddress = $aAddress;
        if ($aOrder['sm_code']=="SF-RUPR"||$aOrder['sm_code']=="SF-RUPT") {
            $hsList = Service_LogisticsOrderHs::getByCondition(array('logistics_code'=>$logisticsCode),"*",5,1);
        }
        $this->view->hsList = $hsList;
        $this->view->smInfo = $smInfo;
        $this->view->country = $country;
        $this->view->area = '';
        $this->view->packNo = '';

        if ('HKPG' == $aOrder['sm_code']) {
            // 获取国家映射区域代码
            $smCountryMap = Service_SmCountryMap::getByInCondition(array(
                'warehouse_id_arr' => array(0, $aOrder['warehouse_id']),
                'sm_code' => $aOrder['sm_code'],
                'country_code' => $country['country_code']
            ));
            if ($smCountryMap) {
                $this->view->area = $smCountryMap[0]['area'];
            }
        }
        elseif ('HKPP' == $aOrder['sm_code']) {
            // 获取包袋号
            $this->view->packNo = Service_ChangePack::getPackNo($country['country_code'], $aAddress['loa_zipcode']);
            // 获取国家映射区域代码
            $smCountryMap = Service_SmCountryMap::getByInCondition(array(
                'warehouse_id_arr' => array(0, $aOrder['warehouse_id']),
                'sm_code' => $aOrder['sm_code'],
                'country_code' => $country['country_code']
            ));
            if ($smCountryMap) {
                $this->view->area = $smCountryMap[0]['area'];
            }
        }
        if($aOrder['sm_code']=='HKDHL' || 'SZY-EMS' == $aOrder['sm_code'] || 'AUP' == $aOrder['sm_code'])
            echo $this->view->render($this->tplDirectory . "/label/F4.tpl");
        elseif($aOrder['sm_code']=='BH-SGG' || $aOrder['sm_code']=='BH-SGP'){
            echo $this->view->render($this->tplDirectory . "/label/sg.tpl");
        }
        elseif($aOrder['sm_code']=="BZAM"){
            echo $this->view->render($this->tplDirectory."/label/bzam.tpl");
        }
        elseif ('BH-MPPG' == $aOrder['sm_code']) {
            echo $this->view->render($this->tplDirectory . '/label/bh-mppg.tpl');
        }
        elseif ('HKPG' == $aOrder['sm_code']) {
            echo $this->view->render($this->tplDirectory . '/label/hkpg.tpl');
        }
        elseif ('HKPP' == $aOrder['sm_code']) {
            echo $this->view->render($this->tplDirectory . '/label/hkpp.tpl');
        }
        elseif ('CJ-DGMG' == $aOrder['sm_code']) {
            echo $this->view->render($this->tplDirectory . '/label/cj-dgmg.tpl');
        }
        elseif ('CJ-DGMP' == $aOrder['sm_code']) {
            echo $this->view->render($this->tplDirectory . '/label/cj-dgmp.tpl');
        }
        elseif ('SF-RUPR' == $aOrder['sm_code']) {
            echo $this->view->render($this->tplDirectory . '/label/rupr.tpl');
        }
        elseif ('SF-RUPT' == $aOrder['sm_code']) {
            echo $this->view->render($this->tplDirectory . '/label/rupt.tpl');
        }else{
            echo $this->view->render($this->tplDirectory . "/label/sw.tpl");
        }

    }
	
	/*批量提交打印标签*/
    public function submitOrdersAction() {
		
		$return = array('ask' => 0, 'orderCodeList'=>array(),'message' =>Ec_Lang::getInstance()->getTranslate('ConfirmOrder').','.Ec_Lang::getInstance()->getTranslate('fail'));
		$orderArr = $this->_request->getParam("orderArr","");
		
		
		if (!empty($orderArr)){
    		$success=0;
    		$failse=0;    		
    		$failsStr = '';
    		foreach($orderArr as $logisticsCode){							
				
				$result = Service_LogisticsOrderProcess::submitOrder($logisticsCode);
				
				if($result['ask']=='1'){
					$success++;
    				$return['detailmessage'][] = '订单号'."[{$logisticsCode}]成功.";
					$return['orderCodeList'][] = $logisticsCode;
				}else{
    				$return['detailmessage'][] = '订单号'."[{$logisticsCode}]失败:".$result['message'];
    				$failse++;
				}
						
			
			
			}// 
			
    		if($success>0){
    			$return['ask']=1;
    		}			
			$return['message']='提交订单,'.Ec_Lang::getInstance()->getTranslate('success').':'.$success.Ec_Lang::getInstance()->getTranslate('fail').' :'.$failse.'<br/>'.$failsStr;						
			 	
		}
    	die(Zend_Json::encode($return));
    }//submitOrdersAction() {
	
	
   /**
     * @author solar
     * @todo 批量打印标签
     */
    public function batchPrintLabelAction() {
		$orderCodes = $this->_request->getParam("orderCodes","");		
		if(!$orderCodes){ echo "没有参数.";exit;}
		$orderArr = explode(',',$orderCodes);		
		$orders = array();
		
		foreach($orderArr as $logisticsCode){
			if(empty($logisticsCode)){continue;}
			$aOrder = Service_LogisticsOrder::getByField($logisticsCode, 'logistics_code');
			if(empty($aOrder)) {
				 continue;//exit('error parameter');
			}
            $smInfo = Service_ShippingMethod::getByField($aOrder['sm_code'],"sm_code","*");
            if($smInfo['sm_class_code']=="CPS"){
                $aOrder['tracking_number'] = "";
            }else{
                $trackingNumber = Service_ServiceTrackingNumber::getTrackingNumber($aOrder['sm_code'], $aOrder['ref_tracking_number']);
                $aOrder['tracking_number']  = $trackingNumber;
            }
    		$aAddress = Service_LogisticsOrderAddress::getByField($logisticsCode, 'logistics_code');
    		$country = Service_Country::getByField($aAddress['loa_country'],'country_id',"*");
    		$aAddress['country_name'] = $country['country_name_en'];
			$hsList = Service_LogisticsOrderHs::getByCondition(array('logistics_code'=>$logisticsCode));
			
    		$total_price = 0.00;
    		foreach($hsList as $hsRow){ $total_price += $hsRow['loh_total_price'];}  
				
			$orders[] = array(
				'aOrder'=>$aOrder,
				'aAddress'=>$aAddress,
				'hsList'=>$hsList,
				'totalPrice'=>$total_price
			);		
		}    	
    	
    	//$this->view->aOrder = $aOrder;
    	//$this->view->aAddress = $aAddress;
    	//$this->view->hsList = $hsList;
		//$this->view->totalPrice = $total_price;	
    	/* $result = Service_LogisticsOrderProcess::submitOrder($logisticsCode);
    	if($result['ask']==0) exit('inner error'); */
		$this->view->orders = $orders;
    	echo $this->view->render($this->tplDirectory . "batchsw.tpl");    	
    }

    public function deleteAction(){
        $return = array('ask' => 0, 'message' => Ec_Lang::getInstance()->getTranslate('delete').','.Ec_Lang::getInstance()->getTranslate('fail'),'error'=>'');
        $orderArr	= $this->_request->getParam('orderArr','');
        $error = array();
        if (!empty($orderArr)){
            $success=0;
            $failse=0;
            $customer = $this->_customerAuth;
            $customerId = $customer['id'];
            foreach($orderArr as $key=>$orderCode){
                //$result = Service_OrderProcess::confirm($orderCode,$customerId);
                $result = Service_LogisticsOrderProcess::deleteTranslate($orderCode,$customerId);
                if (!empty($result) && $result['ask']=='1') {
                    $return['detailmessage'][] = '订单号'."[{$orderCode}]成功.";
                    $success++;
                }else{
                    $failse++;
                    $return['detailmessage'][] = '订单号'."[{$orderCode}]失败：".$result['message'];
                    //$error[] = $orderCode.Ec_Lang::getInstance()->getTranslate('delete').Ec_Lang::getInstance()->getTranslate('fail').",".Ec_Lang::getInstance()->getTranslate('Reason').':'.$result['message'];
                }
            }
            if($success>0){
                $return['ask']=1;
            }
            if(!empty($error)){
                $return['error'] = $error;
            }
            $return['message']=Ec_Lang::getInstance()->getTranslate('DeletedSuccessfully').':'.$success.' '.Ec_Lang::getInstance()->getTranslate('fail').':'.$failse;
        }
        die(Zend_Json::encode($return));
    }
    
    /**
     * @todo 下载模板
     * @author solar
     */
    public function downloadAction() {
    	header("Content-Type: APPLICATION/OCTET-STREAM");
    	header("Content-Disposition: attachment; filename=upload-order-template.xls;");
    	echo file_get_contents(APPLICATION_PATH."/../data/file".'/upload-order-template.xls');
    	exit;
    }
	
	/**
     * @todo 批量上传订单
     * @author solar
     */
    public function uploadAction() {
    	echo Ec::renderTpl($this->tplDirectory . "upload.tpl",'layout_from_oms');
    }
	
   /**
     * @todo 批量上传订单
     * @author solar
     */
    public function uploadSubmitAction() {
    	/* $uploadSession = new Zend_Session_Namespace('upload');
    	$uploadSession->elementExcel = ''; */
    	$path = APPLICATION_PATH.'/../data/upload/';
    	if(!file_exists($path)){
    		if(!mkdir($path,0777,true)){
    			$this->view->message = '上传失败：内部错误';
    			echo Ec::renderTpl($this->tplDirectory . "upload.tpl",'layout_from_oms');
    			exit;
    		}
    	}
    	$config = array();
    	$config['upload_path']		= $path;
    	$config['allowed_types']	= 'xls|xlsx';
    	$config['max_size']			= '2048000';
    	$config['encrypt_name']		= true;
    	$upload	= new Common_UploadFile($config);
    	$upload->set_upload_path($path);
    	if (!$upload->do_upload($_FILES,'XMLForInput')){
    		$this->view->message = '上传文件失败：'.$upload->display_errors();
    		echo Ec::renderTpl($this->tplDirectory . "upload.tpl",'layout_from_oms');
    		exit;
    	}
    	$uploadData = $upload->data();
    	if(empty($uploadData) || empty($uploadData['full_path'])){
    		$this->view->message = '上传失败：内部错误';
    		echo Ec::renderTpl($this->tplDirectory . "upload.tpl",'layout_from_oms');
    		exit;
    	}
    	$excelData = Common_Upload::readEXCEL($uploadData['full_path']);
    	if(!is_array($excelData) || empty($excelData) || count($excelData)<2) {
    		$this->view->message = '文件数据为空，请编辑好数据后再上传';
    		@unlink($uploadData['full_path']);
    		echo Ec::renderTpl($this->tplDirectory . "upload.tpl",'layout_from_oms');
    		exit;
    	}
    	$result = Service_LogisticsProcess::validateExcel($excelData);
    	if($result['ask']==0) {
    		$this->view->message = implode('<br>', $result['error']);
    	} else {
    		$db = Common_Common::getAdapter();
    		$db->beginTransaction();
    		try{
    			$aCode = array();
    			foreach($result['body'] as $data) {
    				$aCode[] = Service_LogisticsProcess::addLogisticsOrder($data);
    			}
    			$db->commit();
    			$this->view->message = '批量上传订单成功，总共上传'.count($aCode).'个订单，订单号是：'.implode(', ', $aCode);
    		} catch(Exception $e) {
    			$db->rollback();
    			$this->view->message = '批量上传订单出现异常，请稍后重新上传';
    		}
    		/*$this->view->excelHead = $result['header'];
    		$this->view->excelData = $result['body'];
    		$uploadSession->elementExcel = $uploadData['full_path'];
    		echo Ec::renderTpl($this->tplDirectory . "element-preview.tpl",'layout_from_oms');*/
    	}
    	echo Ec::renderTpl($this->tplDirectory . "upload.tpl",'layout_from_oms');
    	@unlink($uploadData['full_path']);
    }	
	

	/*用户列表辅助输入*/
	public function customerAuxiliaryInputAction()
	{		
		$page		= $this->getRequest()->getParam('page', 1);
		$pageSize	= $this->getRequest()->getParam('pageSize', 10);
		$condition	= array(
				'customer_code'		=> trim($this->getRequest()->getParam('s_customer_code')),
				'customer_email'      => trim($this->getRequest()->getParam('s_customer_email')),
				'customer_status'      => 2
				

		);		
		$from = $this->_request->getParam('from','logistics');
        $globals_hs_code = $this->_request->getParam("global_hs_code","");
		//判断参数的有效性
		$from = 'logistics';		
		$this->view->from = $from;
		$this->view->params		= $condition;
		$this->view->pageSize	= $pageSize;
		
		$this->view->page		= $page;
        $this->view->globals_hs_code           = $globals_hs_code;		
		$this->view->count = Service_Customer::getByCondition($condition, 'count(*)');		
		$result=Service_Customer::getByCondition($condition, '*', $pageSize, $page,'customer_id DESC');		
		$this->view->result		= $result;		
		echo $this->view->render($this->tplDirectory . "customerAuxiliaryInput.tpl");
	}	
	/*获取运输方式*/
	public function getMethodsAction(){
		$customer_code	=  strtoupper($this->getRequest()->getParam('customer_code',''));
		$current_sm_code	=  strtoupper($this->getRequest()->getParam('current_sm_code',''));
		$this->view->current_sm_code =  $current_sm_code;
		$this->view->shipMethods = Service_LogisticsProcess::getShipMethods($customer_code);		
		echo $this->view->render($this->tplDirectory . "getmethods.tpl");
	}
	
	/**
	 * 环球易购批量提交订单
	 * @author solar
	 */
	public function hqswghAction() {
		$return = array('ask' => 0, 'message' =>Ec_Lang::getInstance()->getTranslate('SubmitOrder').','.Ec_Lang::getInstance()->getTranslate('fail'));
		$orderArr	= $this->_request->getParam('orderArr','');
		
		if (!empty($orderArr)) {
			$success=0;
			$failse=0;
			//$customer = $this->_customerAuth;
			//$customerId = $customer['id'];
			$failsStr = '';
			foreach($orderArr as $key=>$logistics_code){
				$result = Service_LogisticsOrderProcess::hqswghOrder($logistics_code);
				
				if (!empty($result) && $result['ask']=='1') {
					$success++;
					$return['detailmessage'][] = '订单号'."[{$logistics_code}]成功.";
				}else{
					$return['detailmessage'][] = '订单号'."[{$logistics_code}]失败:".$result['message'];
					$failse++;
				}
			}
			if($success>0){
				$return['ask']=1;
			}
			$return['message']=Ec_Lang::getInstance()->getTranslate('SubmitOrder').','.Ec_Lang::getInstance()->getTranslate('success').':'.$success.Ec_Lang::getInstance()->getTranslate('fail').' :'.$failse.'<br/>'.$failsStr;
		}
		die(Zend_Json::encode($return));
	}

    public function exportAction(){
        set_time_limit(0);
        $orderArr = $this->_request->getParam('orderArr','');
        $exportType = $this->_request->getParam("exportType","");
        if($exportType=="1"){
            $htmlTitle = '<tr>';
            $htmlTitle  = '<td>客户代码</td>';
            $htmlTitle .= '<td>客户参考号</td>';
            $htmlTitle .= '<td>订单号</td>';
            $htmlTitle .= '<td>跟踪号</td>';
            $htmlTitle .= '<td>运输方式</td>';
            $htmlTitle .= '<td>发件人姓名</td>';
            $htmlTitle .= '<td>发件人公司名</td>';
            $htmlTitle .= '<td>发件人省份</td>';
            $htmlTitle .= '<td>发件人城市</td>';
            $htmlTitle .= '<td>发件人电话</td>';
            $htmlTitle .= '<td>发件人地址</td>';
            $htmlTitle .= '<td>收件人姓名</td>';
            $htmlTitle .= '<td>收件人地址</td>';
            $htmlTitle .= '<td>收件人州\区域</td>';
            $htmlTitle .= '<td>收件人城市</td>';
            $htmlTitle .= '<td>收件人邮编</td>';
            $htmlTitle .= '<td>收件人电话</td>';
            $htmlTitle .= '<td>发货重量</td>';
            $htmlTitle .= '<td>收货重量（KG）</td>';
            $htmlTitle .= '<td>收件国家（CN）</td>';
            $htmlTitle .= '<td>国家简称</td>';
            $maxHs = 1;
            $orderContent = "";
            foreach($orderArr as $logisticsCode){
                if($logisticsCode=="") continue;
                $logisticsRow = Service_LogisticsOrder::getByField($logisticsCode,'logistics_code',"*");
                $logisticsOrderHs = Service_LogisticsOrderHs::getByCondition(array('logistics_code'=>$logisticsCode),"*",0,0);
                if(count($logisticsOrderHs)>$maxHs) $maxHs = count($logisticsOrderHs);
                $orderContent.="<tr>";
                $orderContent.="<td>".$logisticsRow['customer_code']."</td>";
                $orderContent.="<td style='vnd.ms-excel.numberformat:@;'>".$logisticsRow['reference_no']."</td>";
                $orderContent.="<td>".$logisticsRow['logistics_code']."</td>";
                $orderContent.="<td style='vnd.ms-excel.numberformat:@;'>".$logisticsRow['ref_tracking_number']."</td>";
                $orderContent.="<td>".$logisticsRow['sm_code']."</td>";
                //$orderContent.="<td>".$logisticsRow['customer_code']."</td>";
                //$orderContent.="<td>".$logisticsRow['customer_code']."</td>";
                $loSenderAddress = Service_LogisticsOrderAddress::getByCondition(array('logistics_code'=>$logisticsCode,'loa_type'=>1),"*",0,0);
                if(!empty($loSenderAddress)){
                    $orderContent.="<td>".$loSenderAddress[0]['loa_name']."</td>";
                    $orderContent.="<td>".$loSenderAddress[0]['loa_company']."</td>";
                    //$senderCountry = Service_Country::getByField($loSenderAddress[0]['loa_country'],'country_id',"*");
                    //$orderContent.="<td>".$senderCountry['country_name']."</td>";
                    $orderContent.="<td>".$loSenderAddress[0]['loa_province']."</td>";
                    $orderContent.="<td>".$loSenderAddress[0]['loa_city']."</td>";
                    $orderContent.="<td style='vnd.ms-excel.numberformat:@;'>".$loSenderAddress[0]['loa_phone']."</td>";
                    $orderContent.="<td>".$loSenderAddress[0]['loa_address']."</td>";
                }else{
                    $orderContent.="<td></td>";
                    $orderContent.="<td></td>";
                    $orderContent.="<td></td>";
                    $orderContent.="<td></td>";
                    $orderContent.="<td></td>";
                    $orderContent.="<td></td>";
                }

                $loReceiptAddress = Service_LogisticsOrderAddress::getByCondition(array('logistics_code'=>$logisticsCode,'loa_type'=>'0'),"*",0,0);
                $orderContent.="<td>".$loReceiptAddress[0]['loa_name']."</td>";
                $orderContent.="<td>".$loReceiptAddress[0]['loa_address']."</td>";
                $orderContent.="<td>".$loReceiptAddress[0]['loa_province']."</td>";
                $orderContent.="<td>".$loReceiptAddress[0]['loa_city']."</td>";
                $orderContent.="<td style='vnd.ms-excel.numberformat:@;'>".$loReceiptAddress[0]['loa_zipcode']."</td>";
                $orderContent.="<td style='vnd.ms-excel.numberformat:@;'>".$loReceiptAddress[0]['loa_phone']."</td>";
                $orderContent.="<td>".$logisticsRow['lo_weight']."</td>";
                $RBO = Service_ReceivingBatchOrder::getByField($logisticsRow['logistics_code'],'logistics_code',"*");
                $weight = isset($RBO['weight'])?$RBO['weight']:"";
                $orderContent.="<td>".$weight."</td>";

                $receiptCountry = Service_Country::getByField($loReceiptAddress[0]['loa_country'],'country_id',"*");
                $orderContent.="<td>".$receiptCountry['country_name']."</td>";
                $orderContent.="<td>".$receiptCountry['country_code']."</td>";
                foreach($logisticsOrderHs as $hs){
                    $orderContent.="<td>".$hs['loh_hs_name']."</td>";
                    $orderContent.="<td>".$hs['loh_total_price']."</td>";
                    $orderContent.="<td>".$hs['loh_quantity']."</td>";
                }
                $orderContent.="</tr>";
            }
            for($i=0;$i<$maxHs;$i++){
                $htmlTitle.="<td>英文品名".($i+1)."</td>";
                $htmlTitle.="<td>申报价值".($i+1)."（USD）</td>";
                $htmlTitle.="<td>数量".($i+1)."（个）</td>";
            }
            $htmlTitle."<tr>";

            header('Pragma:public');
            header('Content-Type:application/x-msexecl;name=logisticsOrderList.xls');
            header("Content-Disposition:inline;filename=logisticsOrderList.xls");
            $htmlTitle = mb_convert_encoding($htmlTitle,'GBK','utf8');
            $orderContent = mb_convert_encoding($orderContent,'GBK','utf8');

            echo "<table border='1'>".$htmlTitle.$orderContent."</table>";
            exit;

        }else{
            $orders_code_CustomerReference = trim($this->_request->getParam("orders_code_CustomerReference",""));
            $condition["orders_code_CustomerReference"] = $orders_code_CustomerReference;

            $warehouse_id = $this->_request->getParam("warehouse_id","");
            $condition["warehouse_id"] = $warehouse_id;

            $customer_code = $this->_request->getParam("customer_code","");
            $condition["customer_code"] = $customer_code;

            $orders_status = $this->_request->getParam("orders_status","0");
            $shipping_method = $this->_request->getParam("shipping_method","");
            $condition["sm_code"] = $shipping_method;            //增加开始结束时间

            $add_time_start	= trim($this->_request->getParam('add_time_start',''));
            $condition["add_time_start"] = $add_time_start;

            $add_time_end	= trim($this->_request->getParam('add_time_end',''));
            $condition['add_time_end']	= $add_time_end;

            $orders_status_arr = explode(',',$orders_status);
            $condition['order_status_arr'] = $orders_status_arr;
            $condition['loa_type'] = "0";

            $receiving_time_start = $this->_request->getParam("receiving_time_start","");
            $condition['receiving_time_start'] = $receiving_time_start;

            $receiving_time_end = $this->_request->getParam("receiving_time_end","");
            $condition['receiving_time_end'] = $receiving_time_end;
            if($receiving_time_start!=""||$receiving_time_end!=""){
                $a = array();
                if($receiving_time_start!=""){
                    $a['add_time_start'] = $receiving_time_start;
                }
                if($receiving_time_end!=""){
                    $a['add_time_end'] = $receiving_time_end;
                }

                $receivingBatchOrder = Service_ReceivingBatchOrder::getByCondition($a,"*",0,0);
                $logisticsCodeArr = array();
                if(!empty($receivingBatchOrder)){
                    foreach($receivingBatchOrder as $k=>$v){
                        if(!in_array($v['logistics_code'],$logisticsCodeArr)){
                            $logisticsCodeArr[] = $v['logistics_code'];
                        }
                    }
                }else{
                    $logisticsCodeArr = array('notlogisticsCode');
                }
                $condition['logistics_code_arr'] = $logisticsCodeArr;
            }
			
			$service_number	= trim($this->_request->getParam('service_number',''));	
			$condition['service_number'] = $service_number;

            //$orders_status_arr = explode(',',$orders_status);
            //$condition['lo_status'] = $orders_status;

            $htmlTitle = '<tr>';
            $htmlTitle  = '<td>客户代码</td>';
            $htmlTitle .= '<td>客户参考号</td>';
            $htmlTitle .= '<td>订单号</td>';
            $htmlTitle .= '<td>跟踪号</td>';
            $htmlTitle .= '<td>运输方式</td>';
            $htmlTitle .= '<td>发件人姓名</td>';
            $htmlTitle .= '<td>发件人公司名</td>';
            $htmlTitle .= '<td>发件人省份</td>';
            $htmlTitle .= '<td>发件人城市</td>';
            $htmlTitle .= '<td>发件人电话</td>';
            $htmlTitle .= '<td>发件人地址</td>';

            $htmlTitle .= '<td>收件人姓名</td>';
            $htmlTitle .= '<td>收件人地址</td>';
            $htmlTitle .= '<td>收件人州\区域</td>';
            $htmlTitle .= '<td>收件人城市</td>';
            $htmlTitle .= '<td>收件人邮编</td>';
            $htmlTitle .= '<td>收件人电话</td>';
            $htmlTitle .= '<td>发货重量</td>';
            $htmlTitle .= '<td>收货重量（KG）</td>';
            $htmlTitle .= '<td>收件国家（CN）</td>';
            $htmlTitle .= '<td>国家简称</td>';
            $maxHs = 1;
            $orderContent = "";

            $count = Service_LogisticsOrder::getJoinOrderByCondition($condition, 'count(*)');
            if($count>0){
                $pageSize = 20;
                $pages = ceil($count/20);
                for($page=1;$page<=$pages;$page++){
                    $rows = Service_LogisticsOrder::getJoinOrderByCondition($condition, '*', $pageSize,$page,'lo_id desc');
                    if(!$rows){continue;}

                    foreach($rows as $logisticsRow){
                        $logisticsOrderHs = Service_LogisticsOrderHs::getByCondition(array('logistics_code'=>$logisticsRow['logistics_code']),"*",0,0);
                        if(count($logisticsOrderHs)>$maxHs) $maxHs = count($logisticsOrderHs);
                        $orderContent.="<tr>";
                        $orderContent.="<td>".$logisticsRow['customer_code']."</td>";
                        $orderContent.="<td style='vnd.ms-excel.numberformat:@;'>".$logisticsRow['reference_no']."</td>";
                        $orderContent.="<td>".$logisticsRow['logistics_code']."</td>";
                        $orderContent.="<td style='vnd.ms-excel.numberformat:@;'>".$logisticsRow['ref_tracking_number']."</td>";
                        $orderContent.="<td>".$logisticsRow['sm_code']."</td>";
                        //$orderContent.="<td>".$logisticsRow['customer_code']."</td>";
                        //$orderContent.="<td>".$logisticsRow['customer_code']."</td>";
                        $loSenderAddress = Service_LogisticsOrderAddress::getByCondition(array('logistics_code'=>$logisticsRow['logistics_code'],'loa_type'=>1),"*",0,0);
                        if(!empty($loSenderAddress)){
                            $orderContent.="<td>".$loSenderAddress[0]['loa_name']."</td>";
                            $orderContent.="<td>".$loSenderAddress[0]['loa_company']."</td>";
                            //$senderCountry = Service_Country::getByField($loSenderAddress[0]['loa_country'],'country_id',"*");
                            //$orderContent.="<td>".$senderCountry['country_name']."</td>";
                            $orderContent.="<td>".$loSenderAddress[0]['loa_province']."</td>";
                            $orderContent.="<td>".$loSenderAddress[0]['loa_city']."</td>";
                            $orderContent.="<td style='vnd.ms-excel.numberformat:@;'>".$loSenderAddress[0]['loa_phone']."</td>";
                            $orderContent.="<td>".$loSenderAddress[0]['loa_address']."</td>";
                        }else{
                            $orderContent.="<td></td>";
                            $orderContent.="<td></td>";
                            $orderContent.="<td></td>";
                            $orderContent.="<td></td>";
                            $orderContent.="<td></td>";
                            $orderContent.="<td></td>";
                        }

                        $loReceiptAddress = Service_LogisticsOrderAddress::getByCondition(array('logistics_code'=>$logisticsRow['logistics_code'],'loa_type'=>'0'),"*",0,0);
                        $orderContent.="<td>".$loReceiptAddress[0]['loa_name']."</td>";
                        $orderContent.="<td>".$loReceiptAddress[0]['loa_address']."</td>";
                        $orderContent.="<td>".$loReceiptAddress[0]['loa_province']."</td>";
                        $orderContent.="<td>".$loReceiptAddress[0]['loa_city']."</td>";
                        $orderContent.="<td>".$loReceiptAddress[0]['loa_zipcode']."</td>";
                        $orderContent.="<td style='vnd.ms-excel.numberformat:@;'>".$loReceiptAddress[0]['loa_phone']."</td>";
                        $orderContent.="<td>".$logisticsRow['lo_weight']."</td>";
                        $RBO = Service_ReceivingBatchOrder::getByField($logisticsRow['logistics_code'],'logistics_code',"*");
                        $weight = isset($RBO['weight'])?$RBO['weight']:"";
                        $orderContent.="<td>".$weight."</td>";

                        $receiptCountry = Service_Country::getByField($loReceiptAddress[0]['loa_country'],'country_id',"*");
                        $orderContent.="<td>".$receiptCountry['country_name']."</td>";
                        $orderContent.="<td>".$receiptCountry['country_code']."</td>";
                        foreach($logisticsOrderHs as $hs){
                            $orderContent.="<td>".$hs['loh_hs_name']."</td>";
                            $orderContent.="<td>".$hs['loh_total_price']."</td>";
                            $orderContent.="<td>".$hs['loh_quantity']."</td>";
                        }
                        $orderContent.="</tr>";
                    }
                }
            }
            for($i=0;$i<$maxHs;$i++){
                $htmlTitle.="<td>英文品名".($i+1)."</td>";
                $htmlTitle.="<td>申报价值".($i+1)."（USD）</td>";
                $htmlTitle.="<td>数量".($i+1)."（个）</td>";
            }
            $htmlTitle."<tr>";

            header('Pragma:public');
            header('Content-Type:application/x-msexecl;name=logisticsOrderList.xls');
            header("Content-Disposition:inline;filename=logisticsOrderList.xls");
            $htmlTitle = mb_convert_encoding($htmlTitle,'GBK','utf8');
            $orderContent = mb_convert_encoding($orderContent,'GBK','utf8');

            //file_put_contents(APPLICATION_PATH . "/../data/{$fileName}",$html);
            echo "<table border='1'>".$htmlTitle.$orderContent."</table>";
            exit;
        }
    }

    public function newExportAction(){
        //set_time_limit(0);
        $orderArr = $this->_request->getParam('orderArr','');
        $exportType = $this->_request->getParam("exportType","");
        require_once APPLICATION_PATH . '/../libs/PHPExcel.php';
        require_once APPLICATION_PATH . '/../libs/PHPExcel/IOFactory.php';
        $table = new PHPExcel();
        $table->getDefaultStyle()->getFont()->setName('宋体');
        $table->setActiveSheetIndex(0);
        $table->setActiveSheetIndex(0)->setTitle("区外仓订单列表");
        $objActSheet=$table->setActiveSheetIndex(0);

        $objActSheet->getColumnDimension('A')->setWidth(10);
        $objActSheet->getColumnDimension('B')->setWidth(20);
        $objActSheet->getColumnDimension('C')->setWidth(20);
        $objActSheet->getColumnDimension('D')->setWidth(20);
        $objActSheet->getColumnDimension('E')->setWidth(15);
        $objActSheet->getColumnDimension('F')->setWidth(15);
        $objActSheet->getColumnDimension('G')->setWidth(15);
        $objActSheet->getColumnDimension('H')->setWidth(15);
        $objActSheet->getColumnDimension('I')->setWidth(15);
        $objActSheet->getColumnDimension('J')->setWidth(15);
        $objActSheet->getColumnDimension('K')->setWidth(15);
        $objActSheet->getColumnDimension('L')->setWidth(15);
        $objActSheet->getColumnDimension('M')->setWidth(15);
        $objActSheet->getColumnDimension('N')->setWidth(15);
        $objActSheet->getColumnDimension('O')->setWidth(15);
        $objActSheet->getColumnDimension('P')->setWidth(15);
        $objActSheet->getColumnDimension('Q')->setWidth(15);
        $objActSheet->getColumnDimension('R')->setWidth(15);
        $objActSheet->getColumnDimension('S')->setWidth(15);
        $objActSheet->getColumnDimension('T')->setWidth(15);
        $objActSheet->getColumnDimension('U')->setWidth(15);
        $objActSheet->getColumnDimension('V')->setWidth(15);
        $objActSheet->getColumnDimension('W')->setWidth(15);
        $objActSheet->getColumnDimension('X')->setWidth(15);

        $objActSheet->setCellValue('A1','客户代码');
        $objActSheet->setCellValue('B1','客户参考号');
        $objActSheet->setCellValue('C1','订单号');
        $objActSheet->setCellValue('D1','跟踪号');
        $objActSheet->setCellValue('E1','运输方式');
        $objActSheet->setCellValue('F1','发件人姓名');
        $objActSheet->setCellValue('G1','发件人公司名');
        $objActSheet->setCellValue('H1','发件人省份');
        $objActSheet->setCellValue('I1','发件人城市');
        $objActSheet->setCellValue('J1','发件人电话');
        $objActSheet->setCellValue('K1','发件人地址');
        $objActSheet->setCellValue('L1','收件人姓名');
        $objActSheet->setCellValue('M1','收件人地址');
        $objActSheet->setCellValue('N1','收件人州\区域');
        $objActSheet->setCellValue('O1','收件人城市');
        $objActSheet->setCellValue('P1','收件人邮编');
        $objActSheet->setCellValue('Q1','收件人电话');
        $objActSheet->setCellValue('R1','发货重量');
        $objActSheet->setCellValue('S1','收货重量（KG）');
        $objActSheet->setCellValue('T1','收件国家（CN）');
        $objActSheet->setCellValue('U1','国家简称');
        $objActSheet->setCellValue("V1","收货时间");
        $objActSheet->setCellValue("W1","收货操作人");
        if($exportType=="1"){
            $maxHs = 1;
            $index = 2;
            foreach($orderArr as $logisticsCode){
                if($logisticsCode=="") continue;
                $logisticsRow = Service_LogisticsOrder::getByField($logisticsCode,'logistics_code',"*");
                $logisticsOrderHs = Service_LogisticsOrderHs::getByCondition(array('logistics_code'=>$logisticsCode),"*",0,0);
                if(count($logisticsOrderHs)>$maxHs) $maxHs = count($logisticsOrderHs);
                $objActSheet->setCellValue('A'.$index,$logisticsRow['customer_code']);
                $objActSheet->setCellValueExplicit('B'.$index,$logisticsRow['reference_no'],PHPExcel_Cell_DataType::TYPE_STRING);
                $objActSheet->getStyle('B'.$index)->getNumberFormat()->setFormatCode("@");
                $objActSheet->setCellValueExplicit('C'.$index,$logisticsRow['logistics_code'],PHPExcel_Cell_DataType::TYPE_STRING);
                $objActSheet->getStyle('C'.$index)->getNumberFormat()->setFormatCode("@");
                $objActSheet->setCellValueExplicit('D'.$index,$logisticsRow['ref_tracking_number'],PHPExcel_Cell_DataType::TYPE_STRING);
                $objActSheet->getStyle('D'.$index)->getNumberFormat()->setFormatCode("@");
                $objActSheet->setCellValue('E'.$index,$logisticsRow['sm_code']);
                $loSenderAddress = Service_LogisticsOrderAddress::getByCondition(array('logistics_code'=>$logisticsRow['logistics_code'],'loa_type'=>1),"*",0,0);
                if(!empty($loSenderAddress)){
                    $objActSheet->setCellValue('F'.$index,$loSenderAddress[0]['loa_name']);
                    $objActSheet->setCellValue('G'.$index,$loSenderAddress[0]['loa_company']);
                    $objActSheet->setCellValue('H'.$index,$loSenderAddress[0]['loa_province']);
                    $objActSheet->setCellValue('I'.$index,$loSenderAddress[0]['loa_city']);
                    $objActSheet->setCellValueExplicit('J'.$index,$loSenderAddress[0]['loa_phone'],PHPExcel_Cell_DataType::TYPE_STRING);
                    $objActSheet->getStyle('J'.$index)->getNumberFormat()->setFormatCode("@");
                    $objActSheet->setCellValue('K'.$index,$loSenderAddress[0]['loa_address']);
                }else{
                    $objActSheet->setCellValue('F'.$index,"");
                    $objActSheet->setCellValue('G'.$index,"");
                    $objActSheet->setCellValue('H'.$index,"");
                    $objActSheet->setCellValue('I'.$index,"");
                    $objActSheet->setCellValue('J'.$index,"");
                    $objActSheet->setCellValue('K'.$index,"");
                }
                $loReceiptAddress = Service_LogisticsOrderAddress::getByCondition(array('logistics_code'=>$logisticsRow['logistics_code'],'loa_type'=>'0'),"*",0,0);
                $objActSheet->setCellValue('L'.$index,$loReceiptAddress[0]['loa_name']);
                $objActSheet->setCellValue('M'.$index,$loReceiptAddress[0]['loa_address']);
                $objActSheet->setCellValue('N'.$index,$loReceiptAddress[0]['loa_province']);
                $objActSheet->setCellValue('O'.$index,$loReceiptAddress[0]['loa_city']);
                $objActSheet->setCellValueExplicit('P'.$index,$loReceiptAddress[0]['loa_zipcode'],PHPExcel_Cell_DataType::TYPE_STRING);
                $objActSheet->getStyle('P'.$index)->getNumberFormat()->setFormatCode("@");
                $objActSheet->setCellValueExplicit('Q'.$index,$loReceiptAddress[0]['loa_phone'],PHPExcel_Cell_DataType::TYPE_STRING);
                $objActSheet->getStyle('Q'.$index)->getNumberFormat()->setFormatCode("@");

                $objActSheet->setCellValue('R'.$index,$logisticsRow['lo_weight']);

                $RBO = Service_ReceivingBatchOrder::getByField($logisticsRow['logistics_code'],'logistics_code',"*");
                $weight = isset($RBO['weight'])?$RBO['weight']:"";
                $objActSheet->setCellValue('S'.$index,$weight);

                $receiptCountry = Service_Country::getByField($loReceiptAddress[0]['loa_country'],'country_id',"*");
                $objActSheet->setCellValue('T'.$index,$receiptCountry['country_name']);
                $objActSheet->setCellValue('U'.$index,$receiptCountry['country_code']);

                $objActSheet->setCellValue("V".$index,isset($RBO['add_time'])?$RBO['add_time']:"");
                if(isset($RBO['user_id'])){
                    $user = Service_User::getByField($RBO['user_id'],"user_id","*");
                    $objActSheet->setCellValue("W".$index,$user['user_code']);
                }else{
                    $objActSheet->setCellValue("W".$index,"");
                }

                $chrFirst = 65;
                $chrSecond = 65;
                foreach($logisticsOrderHs as $key=>$hs){
                    if($key=='0'){
                        $objActSheet->setCellValue('X'.$index,$hs['loh_hs_name']);
                        $objActSheet->setCellValue('Y'.$index,$hs['loh_total_price']);
                        $objActSheet->setCellValue('Z'.$index,$hs['loh_quantity']);
                    }else{
                        if($chrSecond>90){
                            $chrFirst++;
                            $chrSecond = 65;
                        }
                        $objActSheet->setCellValue(chr($chrFirst).chr($chrSecond).$index,$hs['loh_hs_name']);
                        $chrSecond++;
                        if($chrSecond>90){
                            $chrFirst++;
                            $chrSecond = 65;
                        }
                        $objActSheet->setCellValue(chr($chrFirst).chr($chrSecond).$index,$hs['loh_total_price']);
                        $chrSecond++;
                        if($chrSecond>90){
                            $chrFirst++;
                            $chrSecond = 65;
                        }
                        $objActSheet->setCellValue(chr($chrFirst).chr($chrSecond).$index,$hs['loh_quantity']);
                        $chrSecond++;
                    }
                }
                $index++;
            }

            $chrFirstIndex = 65;
            $chrSecondIndex = 65;
            for($i=0;$i<$maxHs;$i++){
                if($i=="0"){
                    $objActSheet->setCellValue('X1','英文品名1');
                    $objActSheet->setCellValue('Y1','申报价值1');
                    $objActSheet->setCellValue('Z1','数量1');
                }else{
                    if($chrSecondIndex>90){
                        $chrFirstIndex++;
                        $chrSecondIndex = 65;
                    }
                    $objActSheet->setCellValue(chr($chrFirstIndex).chr($chrSecondIndex).'1','英文品名'.($i+1));
                    $chrSecondIndex++;
                    if($chrSecondIndex>90){
                        $chrFirstIndex++;
                        $chrSecondIndex = 65;
                    }
                    $objActSheet->setCellValue(chr($chrFirstIndex).chr($chrSecondIndex).'1','申报价值'.($i+1));
                    $chrSecondIndex++;
                    if($chrSecondIndex>90){
                        $chrFirstIndex++;
                        $chrSecondIndex = 65;
                    }
                    $objActSheet->setCellValue(chr($chrFirstIndex).chr($chrSecondIndex).'1','数量'.($i+1));
                    $chrSecondIndex++;
                }
            }

            $objWriter = PHPExcel_IOFactory::createWriter($table, 'Excel5');
            header( "Pragma: public" );
            header( "Expires: 0" );
            header("Accept-Ranges: bytes");
            header('cache-control:must-revalidate');
            header("Content-Disposition: attachment; filename=orderlist".date("YmdHis").".xls");
            header("Content-Type:APPLICATION/OCTET-STREAM;charset=utf-8");
            $objWriter->save('php://output');

        }else{
            $orders_code_CustomerReference = trim($this->_request->getParam("orders_code_CustomerReference",""));
            $condition["orders_code_CustomerReference"] = $orders_code_CustomerReference;

            $warehouse_id = $this->_request->getParam("warehouse_id","");
            $condition["warehouse_id"] = $warehouse_id;

            $customer_code = $this->_request->getParam("customer_code","");
            $condition["customer_code"] = $customer_code;

            $orders_status = $this->_request->getParam("orders_status","0");
            $shipping_method = $this->_request->getParam("shipping_method","");
            $condition["sm_code"] = $shipping_method;            //增加开始结束时间

            $add_time_start	= trim($this->_request->getParam('add_time_start',''));
            $condition["add_time_start"] = $add_time_start;

            $add_time_end	= trim($this->_request->getParam('add_time_end',''));
            $condition['add_time_end']	= $add_time_end;

            $orders_status_arr = explode(',',$orders_status);
            $condition['order_status_arr'] = $orders_status_arr;
            $condition['loa_type'] = "0";

            $receiving_time_start = $this->_request->getParam("receiving_time_start","");
            $condition['receiving_time_start'] = $receiving_time_start;

            $receiving_time_end = $this->_request->getParam("receiving_time_end","");
            $condition['receiving_time_end'] = $receiving_time_end;
            if($receiving_time_start!=""||$receiving_time_end!=""){
                $a = array();
                if($receiving_time_start!=""){
                    $a['add_time_start'] = $receiving_time_start;
                }
                if($receiving_time_end!=""){
                    $a['add_time_end'] = $receiving_time_end;
                }

                $receivingBatchOrder = Service_ReceivingBatchOrder::getByCondition($a,"*",0,0);
                $logisticsCodeArr = array();
                if(!empty($receivingBatchOrder)){
                    foreach($receivingBatchOrder as $k=>$v){
                        if(!in_array($v['logistics_code'],$logisticsCodeArr)){
                            $logisticsCodeArr[] = $v['logistics_code'];
                        }
                    }
                }else{
                    $logisticsCodeArr = array('notlogisticsCode');
                }
                $condition['logistics_code_arr'] = $logisticsCodeArr;
            }
            $maxHs = 1;

            $count = Service_LogisticsOrder::getJoinOrderByCondition($condition, 'count(*)');
            if($count>0){
                $pageSize = 20;
                $pages = ceil($count/20);
                $index = 2;
                for($page=1;$page<=$pages;$page++){
                    $rows = Service_LogisticsOrder::getJoinOrderByCondition($condition, '*', $pageSize,$page,'lo_id desc');
                    if(!$rows){continue;}

                    foreach($rows as $logisticsRow){
                        $logisticsOrderHs = Service_LogisticsOrderHs::getByCondition(array('logistics_code'=>$logisticsRow['logistics_code']),"*",0,0);
                        if(count($logisticsOrderHs)>$maxHs) $maxHs = count($logisticsOrderHs);
                        $objActSheet->setCellValue('A'.$index,$logisticsRow['customer_code']);
                        $objActSheet->setCellValueExplicit('B'.$index,$logisticsRow['reference_no'],PHPExcel_Cell_DataType::TYPE_STRING);
                        $objActSheet->getStyle('B'.$index)->getNumberFormat()->setFormatCode("@");
                        $objActSheet->setCellValueExplicit('C'.$index,$logisticsRow['logistics_code'],PHPExcel_Cell_DataType::TYPE_STRING);
                        $objActSheet->getStyle('C'.$index)->getNumberFormat()->setFormatCode("@");
                        $objActSheet->setCellValueExplicit('D'.$index,$logisticsRow['ref_tracking_number'],PHPExcel_Cell_DataType::TYPE_STRING);
                        $objActSheet->getStyle('D'.$index)->getNumberFormat()->setFormatCode("@");
                        $objActSheet->setCellValue('E'.$index,$logisticsRow['sm_code']);
                        $loSenderAddress = Service_LogisticsOrderAddress::getByCondition(array('logistics_code'=>$logisticsRow['logistics_code'],'loa_type'=>1),"*",0,0);
                        if(!empty($loSenderAddress)){
                            $objActSheet->setCellValue('F'.$index,$loSenderAddress[0]['loa_name']);
                            $objActSheet->setCellValue('G'.$index,$loSenderAddress[0]['loa_company']);
                            $objActSheet->setCellValue('H'.$index,$loSenderAddress[0]['loa_province']);
                            $objActSheet->setCellValue('I'.$index,$loSenderAddress[0]['loa_city']);
                            $objActSheet->setCellValueExplicit('J'.$index,$loSenderAddress[0]['loa_phone'],PHPExcel_Cell_DataType::TYPE_STRING);
                            $objActSheet->getStyle('J'.$index)->getNumberFormat()->setFormatCode("@");
                            $objActSheet->setCellValue('K'.$index,$loSenderAddress[0]['loa_address']);
                        }else{
                            $objActSheet->setCellValue('F'.$index,"");
                            $objActSheet->setCellValue('G'.$index,"");
                            $objActSheet->setCellValue('H'.$index,"");
                            $objActSheet->setCellValue('I'.$index,"");
                            $objActSheet->setCellValue('J'.$index,"");
                            $objActSheet->setCellValue('K'.$index,"");
                        }
                        $loReceiptAddress = Service_LogisticsOrderAddress::getByCondition(array('logistics_code'=>$logisticsRow['logistics_code'],'loa_type'=>'0'),"*",0,0);
                        $objActSheet->setCellValue('L'.$index,$loReceiptAddress[0]['loa_name']);
                        $objActSheet->setCellValue('M'.$index,$loReceiptAddress[0]['loa_address']);
                        $objActSheet->setCellValue('N'.$index,$loReceiptAddress[0]['loa_province']);
                        $objActSheet->setCellValue('O'.$index,$loReceiptAddress[0]['loa_city']);
                        $objActSheet->setCellValueExplicit('P'.$index,$loReceiptAddress[0]['loa_zipcode'],PHPExcel_Cell_DataType::TYPE_STRING);
                        $objActSheet->getStyle('P'.$index)->getNumberFormat()->setFormatCode("@");
                        $objActSheet->setCellValueExplicit('Q'.$index,$loReceiptAddress[0]['loa_phone'],PHPExcel_Cell_DataType::TYPE_STRING);
                        $objActSheet->getStyle('Q'.$index)->getNumberFormat()->setFormatCode("@");

                        $objActSheet->setCellValue('R'.$index,$logisticsRow['lo_weight']);

                        $RBO = Service_ReceivingBatchOrder::getByField($logisticsRow['logistics_code'],'logistics_code',"*");
                        $weight = isset($RBO['weight'])?$RBO['weight']:"";
                        $objActSheet->setCellValue('S'.$index,$weight);

                        $receiptCountry = Service_Country::getByField($loReceiptAddress[0]['loa_country'],'country_id',"*");
                        $objActSheet->setCellValue('T'.$index,$receiptCountry['country_name']);
                        $objActSheet->setCellValue('U'.$index,$receiptCountry['country_code']);

                        $objActSheet->setCellValue("V".$index,isset($RBO['add_time'])?$RBO['add_time']:"");
                        if(isset($RBO['user_id'])){
                            $user = Service_User::getByField($RBO['user_id'],"user_id","*");
                            $objActSheet->setCellValue("W".$index,$user['user_code']);
                        }else{
                            $objActSheet->setCellValue("W".$index,"");
                        }

                        $chrFirst = 65;
                        $chrSecond = 65;
                        foreach($logisticsOrderHs as $key=>$hs){
                            if($key=='0'){
                                $objActSheet->setCellValue('X'.$index,$hs['loh_hs_name']);
                                $objActSheet->setCellValue('Y'.$index,$hs['loh_total_price']);
                                $objActSheet->setCellValue('Z'.$index,$hs['loh_quantity']);
                            }else{
                                if($chrSecond>90){
                                    $chrFirst++;
                                    $chrSecond = 65;
                                }
                                $objActSheet->setCellValue(chr($chrFirst).chr($chrSecond).$index,$hs['loh_hs_name']);
                                $chrSecond++;
                                if($chrSecond>90){
                                    $chrFirst++;
                                    $chrSecond = 65;
                                }
                                $objActSheet->setCellValue(chr($chrFirst).chr($chrSecond).$index,$hs['loh_total_price']);
                                $chrSecond++;
                                if($chrSecond>90){
                                    $chrFirst++;
                                    $chrSecond = 65;
                                }
                                $objActSheet->setCellValue(chr($chrFirst).chr($chrSecond).$index,$hs['loh_quantity']);
                                $chrSecond++;
                            }
                        }
                        $index++;
                    }
                }
            }
            $chrFirstIndex = 65;
            $chrSecondIndex = 65;
            for($i=0;$i<$maxHs;$i++){
                if($i=="0"){
                    $objActSheet->setCellValue('X1','英文品名1');
                    $objActSheet->setCellValue('Y1','申报价值1');
                    $objActSheet->setCellValue('Z1','数量1');
                }else{
                    if($chrSecondIndex>90){
                        $chrFirstIndex++;
                        $chrSecondIndex = 65;
                    }
                    $objActSheet->setCellValue(chr($chrFirstIndex).chr($chrSecondIndex).'1','英文品名'.($i+1));
                    $chrSecondIndex++;
                    if($chrSecondIndex>90){
                        $chrFirstIndex++;
                        $chrSecondIndex = 65;
                    }
                    $objActSheet->setCellValue(chr($chrFirstIndex).chr($chrSecondIndex).'1','申报价值'.($i+1));
                    $chrSecondIndex++;
                    if($chrSecondIndex>90){
                        $chrFirstIndex++;
                        $chrSecondIndex = 65;
                    }
                    $objActSheet->setCellValue(chr($chrFirstIndex).chr($chrSecondIndex).'1','数量'.($i+1));
                    $chrSecondIndex++;
                }

            }

            $objWriter = PHPExcel_IOFactory::createWriter($table, 'Excel5');
            header( "Pragma: public" );
            header( "Expires: 0" );
            header("Accept-Ranges: bytes");
            header('cache-control:must-revalidate');
            header("Content-Disposition: attachment; filename=orderlist".date("YmdHis").".xls");
            header("Content-Type:APPLICATION/OCTET-STREAM;charset=utf-8");
            $objWriter->save('php://output');
        }

    }
    public function recordedSingleAction() {
        $canScan = '0';
        $order_code = trim($this->_request->getParam('order_code', ''));


        $message = '';
        if ($order_code) {
            $order = Service_LogisticsOrder::getByField($order_code, 'logistics_code');
            if (empty($order)) {
                $message = "<p class='messageFail'>输入订单不存在</p>";
            } else {
                if ($order['sm_code'] != 'HKDHL') {
                    $message = "<p class='messageFail'>必须是hkdhl的运输方式才能录单</p>";
                } elseif ($order['lo_status'] != '2') {
                    $message = "<p class='messageFail'>订单不是提交状态,不能录单</p>";
                } else {
                    $canScan = '1';
                    $addressList = Service_LogisticsOrderAddress::getByCondition(array('logistics_code' => $order_code), '*');

                    $orderAddress = array(); //收件人
                    $orderSendAddress = array(); //发件人
                    foreach ($addressList as $addressRow) {
                        $country_name = "";
                        if ($addressRow['loa_country'] > 0) {
                            $country = Service_Country::getByField($addressRow['loa_country']);
                            if (!empty($country)) {
                                $country_name = $country['country_name'];
                            }
                        }
                        $addressRow['country_name'] = $country_name;
                        if ($addressRow['loa_type'] == '0')
                            $orderAddress = $addressRow;
                        else if ($addressRow['loa_type'] == '1')
                            $orderSendAddress = $addressRow;
                    }
                    $orderProduct = Service_LogisticsOrderHs::getByCondition(array('logistics_code' => $order_code), "*");
                    $countProduct = count($orderProduct);
                    $shipMethod = Service_ShippingMethod::getByField($order['sm_code'], 'sm_code');
                    //print_r($orderProduct);
                    if ($this->_request->isPost()) {
                        $orderInfo['order'] = $order;
                        $orderInfo['receiveAddress'] = $addressRow;
                        $orderInfo['sendAddress'] = $orderSendAddress;
                        $orderInfo['orderProduct'] = $orderProduct;
                        $pices = $this->_request->getParam('pices');
                        $ename = array();
                        if ($pices > $countProduct) {
                            //pices数大于产品数 最后一个产品做一直填充
                            for ($i = 0; $i < $pices; $i++) {
                                if ($i < $countProduct - 1) {
                                    $title_en = $orderProduct[$i]['loh_hs_name'];
                                    $op_id = $orderProduct[$i]['loh_id'];
                                } else {
                                    $title_en = $orderProduct[$countProduct - 1]['loh_hs_name'];
                                    $op_id = $orderProduct[$countProduct - 1]['loh_id'];
                                }
                                $productArr = array(
                                    'title_en' => $title_en,
                                    'op_id' => $op_id
                                );
                                $ename[$i] = $productArr;
                            }
                        } elseif ($pices <= $countProduct) {
                            for ($i = 0; $i < $pices; $i++) {
                                $title_en = $orderProduct[$i]['loh_hs_name'];
                                $op_id = $orderProduct[$i]['loh_id'];
                                $productArr = array(
                                    'title_en' => $title_en,
                                    'op_id' => $op_id
                                );
                                $ename[$i] = $productArr;
                            }
                        }
                        $orderInfo['ename'] = $ename;
                        die(json_encode($orderInfo));
                    }
                }
            }
        }
        if ($order_code) {
            $this->view->message = $message;
            $this->view->order_code = $order_code;
            $this->view->order = $order;
        }
        if ($canScan == '1') {
            $this->view->orderReceive = $orderAddress;
            $this->view->orderSendAddress = $orderSendAddress;
            $this->view->shipMethod = $shipMethod;
        }

        $this->view->canScan = $canScan;
        echo Ec::renderTpl($this->tplDirectory . "recorded-single.tpl", 'layout');
    }

    public function submitSingleAction(){
                    if($this->_request->isPost()){
                        $postData=$this->_request->getPost();
                        $processObj=new Process_OutsideLogistics();
                        $postData=$processObj->dealSinglePostData($postData);//重新组织提交数据
                        $result=$processObj->recordSingle($postData);
                        die(Zend_Json::encode($result));
		
		}
           
       }
			
    
}