<?php
/**
 * Created by JetBrains PhpStorm.
 * User: user
 * Date: 13-11-13
 * Time: 下午4:32
 * To change this template use File | Settings | File Templates.
 */
class Api_ServiceForAsn
{
    protected $_customerId = null;

    protected $_customer = null;

    protected $_token = null;

    protected $_key = null;

    protected $_auth = false;

    protected $_error = null;

    protected $_date = null;

    protected $_paramterArr = array();//将传递过来的对象转为数组存储

    public static  $underlineToUpper = array(
        'ASNCode'=>'ASNCode',
        'receiving_id'=>'receivingId',
        'receiving_code'=>'receivingCode',
        'reference_no'=>'referenceNo',
        'is_delivery'=>'isDelivery',
        'ref_code'=>'refCode',
        'warehouse_code'=>'warehouseCode',
        'supplier_id'=>'supplierId',
        'receiving_update_user'=>'receivingUpdateUser',
        'receiving_add_user'=>'receivingAddUser',
        'customer_id'=>'customerId',
        'customer_code'=>'customerCode',
        'receiving_type'=>'receivingType',
        'receiving_status'=>'receivingStatus',
        'contacter'=>'contacter',
        'contact_phone'=>'contactPhone',
        'receiving_description'=>'receivingDescription',
        'receiving_add_time'=>'receivingAddtime',
        'receiving_update_time'=>'receivingUpdatetime',
        'refercence_form_id'=>'refercenceFormId',
        'ie_port'=>'iePort',
        'form_type'=>'formType',
        'traf_name'=>'trafName',
        'wrap_type'=>'wrapType',
        'pack_no'=>'packNo',
        'traf_mode'=>'trafMode',
        'trade_mode'=>'tradeMode',
        'trans_mode'=>'transMode',
        'conta_id'=>'contaId',
        'conta_model'=>'contaModel',
        'conta_wt'=>'contaWt',
        'haveconta'=>'haveconta',
        'eda_date'=>'edaDate',
        'expected_date'=>'expectedDate',
        'receive_model_type'=>'receiveMode',
        'roughweight'=>'roughWeight',
        'netweight'=>'netWeight',
    );

    public static $upperToUnderline = array(
        'ASNCode'=>'ASNCode',
        'receivingId'=>'receiving_id',
        'receivingCode'=>'receiving_code',
        'refCode'=>'ref_code',
        'isDelivery'=>'is_delivery',
        'referenceNo'=>'reference_no',
        'warehouseCode'=>'warehouse_code',
        'supplierId'=>'supplier_id',
        'receivingUpdateUser'=>'receiving_update_user',
        'receivingAddUser'=>'receiving_add_user',
        'customerId'=>'customer_id',
        'customerCode'=>'customer_code',
        'receivingType'=>'receiving_type',
        'receivingStatus'=>'receiving_status',
        'contacter'=>'contacter',
        'contactPhone'=>'contact_phone',
        'receivingDescription'=>'receiving_description',
        'receivingAddtime'=>'receiving_add_time',
        'receivingUpdatetime'=>'receiving_update_time',
        'refercenceFormId'=>'refercence_form_id',
        'iePort'=>'ie_port',
        'formType'=>'form_type',
        'trafName'=>'traf_name',
        'wrapType'=>'wrap_type',
        'packNo'=>'pack_no',
        'trafMode'=>'traf_mode',
        'tradeMode'=>'trade_mode',
        'transMode'=>'trans_mode',
        'contaId'=>'conta_id',
        'contaModel'=>'conta_model',
        'contaWt'=>'conta_wt',
        'haveconta'=>'haveconta',
        'edaDate'=>'eda_date',
        'expectedDate'=>'expected_date',
        'receiveMode'=>'receive_model_type',
        'roughWeight'=>'roughweight',
        'netWeight'=>'netweight',
    );

    private function _init ($headerRequest) {
        $this->_customerId = (string) $headerRequest['customerCode'];
        $this->_token = (string) $headerRequest['appToken'];
        $this->_key = (string) $headerRequest['appKey'];
    }
    /**
     * @author william-fan
     * @todo Authenticate
     */
    private function authenticate(){
        $customer = Service_Customer::getByField($this->_customerId, 'customer_code');
        if (! $customer || $customer['customer_status'] != 2) {
            $this->_error = 'No Authority For ' . $this->_customerId . '.';
            return false;
        }
        $this->_customer = $customer;
        $customerAuth = Service_CustomerApi::getByField($this->_customerId, 'customer_code');

        if ($customerAuth && $customerAuth['ca_token'] == $this->_token && $customerAuth['ca_key'] == $this->_key) {
            $this->_auth = true;
            return true;
        }
        $this->_error = 'App Token/App Key Not match for ' . $this->_customerId . '.';
        return false;
    }
    /**
     * @todo 写日志
     */
    private function logError ($error) {
        $logger = new Zend_Log();
        $uploadDir = APPLICATION_PATH . "/../data/log/";
        $writer = new Zend_Log_Writer_Stream($uploadDir . 'api-receiving.log');
        $logger->addWriter($writer);
        $logger->info(date('Y-m-d H:i:s') . ': ' . $error . " \n");
    }

    private function common ($paramter) {

        $this->_paramterArr = Common_Common::objectToArray($paramter);//对象转数组
        $headRequest = $this->_paramterArr['HeaderRequest'];
        $this->_init($headRequest);

        $this->_date = date('Y-m-d H:i:s');


        $this->authenticate();

    }

    public function createAsn($data){
        $this->common($data);
        $result = array(
            'ask' => 'Error',
            'message' => '',
            'ASNCode' => '',
            'error'=>'',
        );


        $headerRequest = $this->_paramterArr['HeaderRequest'] ;
        $customerCode = $headerRequest['customerCode'];
        $customerRow = Service_Customer::getByField($customerCode,'customer_code',"*");

        $asnInfo = $this->_paramterArr['ASNInfo'];
        //$filePath = APPLICATION_PATH.'/../data/log/'.'asn.txt';
        /*if(!file_exists($filePath)){
            $fp= fopen($filePath,"w");
            fclose($fp);
        }
        file_put_contents($filePath,var_export($asnInfo,true),FILE_APPEND);*/
        $asnData = array();
        $relateArr = self::$upperToUnderline;
        foreach($asnInfo as $k=>$v){
            if($k!="ASNItems"){
                $asnData[$relateArr[$k]] = $v;
            }
        }
        $warehouseRow = Service_Warehouse::getByField($asnData['warehouse_code'],"warehouse_code","*");
        $asnData['warehouseId'] = $warehouseRow['warehouse_id'];
        $asnInfo['warehouseId'] = $warehouseRow['warehouse_id'];

        if($asnData['receive_model_type']=="1"){
            $errorMsg = "";
            $orderCodeArr = array();
            if(is_array($asnInfo['ASNItems']['OrderInfo'])){
                foreach($asnInfo['ASNItems']['OrderInfo'] as $key=>$value){
                    $orderRow = Service_Orders::getByField($value,"order_code","*");
                    if(!empty($orderRow)){
                        $orderCodeArr[$orderRow['order_id']] = $orderRow['order_code'];
                    }else{
                        $errorMsg.="订单:".$value."不存在;";
                    }
                }
            }else{
                $orderRow = Service_Orders::getByField($asnInfo['ASNItems']['OrderInfo'],"order_code","*");
                if(!empty($orderRow)){
                    $orderCodeArr[$orderRow['order_id']] = $orderRow['order_code'];
                }else{
                    $errorMsg.="订单:".$asnInfo['ASNItems']['OrderInfo']."不存在;";
                }
                //$orderCodeArr[$orderRow['order_id']] = $orderRow['order_code'];
            }
            if($errorMsg!=""){
                $result['ask'] = "0";
                $result['message'] = $errorMsg;
                return $result;
            }
            $asnData['asn_order'] = $orderCodeArr;
        }else{
            $productSku = array();
            $sku = array();
            $decleardValue = array();
            $productInfos = $asnInfo['ASNItems']['productInfo'];
            if(!isset($productInfos[0])){
                //处理只有一个sku的情况bug
                $productInfos = array($productInfos);
            }
            foreach($productInfos as $key=>$value){
                $product = Service_Product::getByCondition(
                    array('product_sku'=>$value['productSku'],'customer_code'=>$customerCode),"*");
                $productSku[$product[0]['product_id']] = $product[0]['product_sku'];
                $sku[$product[0]['product_id']] = $value['quantity'];
                if(isset($value['declaredValue'])&&$value['declaredValue']!=""){
                    $decleardValue[$product[0]['product_id']] = $value['declaredValue'];
                }
            }
            $asnData['product_sku'] = $productSku;
            $asnData['sku'] = $sku;
            if(!empty($decleardValue))
                $asnData['declared_value'] = $decleardValue;
            /*$filePath = APPLICATION_PATH.'/../data/log/'.'asn.txt';
            if(!file_exists($filePath)){
                $fp= fopen($filePath,"w");
                fclose($fp);
            }*/
            //file_put_contents($filePath,var_export($asnData,true),FILE_APPEND);
        }

        $ASNObj = new Service_AsnProccess();
        $doresult = array();
        $asnData['trade_mode'] = 1210;//固定值 保税电商
        if($asnData['receive_model_type']=="1"){
            //集货模式
            if($asnData['receiving_status']=="3"){
                $doresult = $ASNObj->createJHAsnToDsh($asnData, $customerRow['customer_id'], $asnInfo['warehouseId']);
            }else{
                $doresult = $ASNObj->createjihuoTransaction($asnData, $customerRow['customer_id'], $asnInfo['warehouseId']);
            }
            //exit('cc');
        }else{
            if($asnData['receiving_status']=="3"){
                $doresult = $ASNObj->createBHAsnToDsh($asnData, $customerRow['customer_id'], $asnInfo['warehouseId']);
            }else{
                $doresult = $ASNObj->createTransaction($asnData, $customerRow['customer_id'], $asnInfo['warehouseId']);
            }
        }
        if (isset($doresult['msg'])) {
            $result['message'] = $doresult['msg'];
        }
        /*$filePath = APPLICATION_PATH.'/../data/log/'.'asn.txt';
        if(!file_exists($filePath)){
            $fp= fopen($filePath,"w");
            fclose($fp);
        }
        file_put_contents($filePath,var_export($doresult,true),FILE_APPEND);*/
        //$result['error'] =implode(";",$doresult['error']);
        $result['error'] = implode(";",$doresult['error']);// Common_TransError::Transerror($result['error']);
        $result['message'].=$result['error'];
        $result['ask']=$doresult['ask'];
        $result['ASNCode'] = $doresult['ASNCode'];
        if(in_array($customerCode,array('E0728','E0174','E0207'))){
            $message = array(
                'msgJson'=>isset($doresult['detail'])?$doresult['detail']:"",
                'msgInfo'=>$result['message'],
            );
            $result['message'] = json_encode($message);
        }
        //$result['time'] = date("Y-m-d H:i:s");
        //$return['message'] = "";
        /*if($doresult['ask']=='0'){
            $result['message'] = $doresult['msg'];
            $result['error'] = implode(";",$doresult['error']);
            return $result;
        }else{
            if($asnData['receiving_status']=="2"){
                $return = Service_AsnProccess::confirmASn($doresult['ASNCode'],$customerRow['customer_id']);
                if($return['ask']=="0"){
                    $error = array_merge($doresult['error'],$return['error']);
                    $result['error'] = implode(";",$error);// Common_TransError::Transerror($result['error']);
                    $return['message'] = "收货单号".$doresult['ASNCode']."创建成功,提交确认失败!";
                    $result['ask'] = "0";
                    return $result;
                }
                $return['message'] = "收货单号".$doresult['ASNCode']."创建成功,已提交到确认状态";
            }elseif($asnData['receiving_status']=="3"){
                $return = Service_AsnProccess::confirmASn($doresult['ASNCode'],$customerRow['customer_id']);
                if($return['ask']=="0"){
                    $error = array_merge($doresult['error'],$return['error']);
                    $error[] = $return['message'];
                    $result['error'] = implode(";",$error);// Common_TransError::Transerror($result['error']);
                    $result['error'] = "收货订单[".$doresult['ASNCode']."]确认失败:".$result['error'];
                    $result['ask'] = "0";
                    return $result;
                }

                $return2 = Service_AsnProccess::PendingAsn($doresult['ASNCode'],$customerRow['customer_id']);
                if($return2['ask']=="0"){
                    $error = array_merge($doresult['error'],$return['error']);
                    $result['error'] = implode(";",$error);// Common_TransError::Transerror($result['error']);
                    $result['ask'] = "0";
                    return $result;
                }
                $result['message'] = "收货单号".$doresult['ASNCode']."创建成功,且已提交到待审核状态";
            }
        }*/
        //$result['error'] = Common_TransError::Transerror($result['error']);
        return $result;
    }

    public function updateAsn($data){
        $this->common($data);
        $result = array(
            'ask'=>'0',
            'message'=>'',
            'error'=>'',
            'ASNCode'=>'',
        );

        $headerRequest = $this->_paramterArr['HeaderRequest'];
        $customerCode = $headerRequest['customerCode'];
        $customerRow = Service_Customer::getByField($customerCode,'customer_code',"*");

        $asnCoode = $this->_paramterArr['UpdateASNInfo']['ASNCode'];
        if(empty($asnCoode)){
            $result['message'] = 'ASN单号为空';
            return $result;
        }else{
            $receiving = Service_Receiving::getByField($asnCoode,'receiving_code');
            if(empty($receiving)){
                $result['message'] = 'ASN单号不存在';
                return $result;
            }else{
                $receivingCondition = array(
                    'receiving_code'=>$asnCoode,
                );
                if($receiving['receive_model_type']=='1'){
                    //集货模式
                    //传错参数
                    if(isset($this->_paramterArr['UpdateASNInfo']['ASNItems']['productInfo'])){
                        $result['message'] = '集货的ASN,不能传递产品信息';
                        return $result;
                    }
                    $detail = Service_ReceivingOrderDetail::getByCondition($receivingCondition,'*');
                }elseif($receiving['receive_model_type']=='0'){
                    //备货模式
                    print_r($this->_paramterArr);
                    if(isset($this->_paramterArr['UpdateASNInfo']['ASNItems']['OrderInfo'])){
                        $result['message'] = '备货的ASN,不能传递订单信息';
                        return $result;
                    }
                    $detail = Service_ReceivingDetail::getByCondition($receivingCondition,'*');
                }else{
                    $result['message'] = '订单模式错误';
                    return $result;
                }
            }
        }
        $asnInfo = $this->_paramterArr['UpdateASNInfo'];
        //print_r($this->_paramterArr);

        $asnInfo = $this->ASNupdateTransParam($asnInfo,$receiving,$detail,$receiving['receive_model_type']);

        $asnData = array();
        $relateArr = self::$upperToUnderline;
        foreach($asnInfo as $k=>$v){
            if($k!="ASNItems"){
                $asnData[$relateArr[$k]] = $v;
            }
        }

        $warehouseRow = Service_Warehouse::getByField($asnData['warehouse_code'],"warehouse_code","*");
        $asnData['warehouseId'] = $warehouseRow['warehouse_id'];

        if($asnData['receive_model_type']=="1"){
            $orderCodeArr = array();
            foreach($asnInfo['ASNItems']['OrderInfo'] as $key=>$value){
                if($key=="orderCode"){
                    $orderRow = Service_Orders::getByField($value,"order_code","*");
                    $orderCodeArr[$orderRow['order_id']] = $orderRow['order_code'];
                }else{
                    $orderRow = Service_Orders::getByField($value['orderCode'],"order_code","*");
                    $orderCodeArr[$orderRow['order_id']] = $value['orderCode'];
                }
            }
            $asnData['asn_order'] = $orderCodeArr;
        }else{
            $productSku = array();
            $sku = array();
            $decleardValue = array();
            foreach($asnInfo['ASNItems']['productInfo'] as $key=>$value){
                $product = Service_Product::getByCondition(
                    array('product_sku'=>$value['productSku'],'customer_code'=>$customerCode),"*");
                $productSku[$product[0]['product_id']] = $product[0]['product_sku'];
                $sku[$product[0]['product_id']] = $value['quantity'];
                if(isset($value['declaredValue'])&&$value['declaredValue']!=""){
                    $decleardValue[$product[0]['product_id']] = $value['declaredValue'];
                }
            }
            $asnData['product_sku'] = $productSku;
            $asnData['sku'] = $sku;
            if(!empty($decleardValue))
                $asnData['declared_value'] = $decleardValue;
        }

        $ASNObj = new Service_AsnProccess();

        $asn_arrays = Service_AsnProccess::checkReferenceNo(array('reference_no'=>$asnData['ref_code'],'customer_id'=>$customerRow['customer_id']));
        echo "<pre>";
        print_r($asn_arrays);
        print_r($asnData);
        $error = array();
        if($asn_arrays){
                foreach($asn_arrays as $row){
                    if($row['receiving_code']!=$asnData['ASNCode']){
                        $error[] =  '客户参考号已存在!';
                        break;
                    }
                }
        }
        if(!empty($error)){
            //$result['error'] = $error;
            $result['error'] = implode(";",$error);
            $result['ask'] = "0";
            $result['ASNCode'] = $asnData['ASNCode'];
            return $result;
        }

        if($asnData['receive_model_type']=="0"){
            //备货模式
            $doresult = $ASNObj->updateTransaction($asnData, $customerRow['customer_id'], $asnData['warehouseId']);
        }else{
            $doresult = $ASNObj->updatejihuoTransaction($asnData, $customerRow['customer_id'], $asnData['warehouseId']);
        }
        /*if (isset($doresult['msg'])) {
            $result['msg'] = $doresult['msg'];
        }*/
        //$result['error']=$doresult['error'];
        $result['error'] = empty($doresult['error'])?"":implode(";",$doresult['error']);
        $result['ask']=$doresult['ask'];
        $result['message'] = $doresult['msg'];
        $result['ASNCode'] = $doresult['ASNCode'];
        return $result;
    }

    public function getAsnByCode($data){
        $this->common($data);
        $result = array(
            'ask'=>'Error',
            'message'=>'',
            'error'=>'',
            'Data'=>'',
        );
        //$receivingRow = array();
        $receivingCode = $this->_paramterArr['ASNCode'];

        $row = Service_Receiving::getByField($receivingCode,'receiving_code',"*");
        $warehouseRow = Service_Warehouse::getByField($row['warehouse_id'],"warehouse_id","*");
        $row['warehouse_code'] = $warehouseRow['warehouse_code'];
        $receivingRow = array();
        $relate = self::$underlineToUpper;
        foreach($row as $k=>$v){
            $receivingRow[$relate[$k]] = $v;
        }
        if($receivingRow['receiveMode']=="1"){
            $receivingOrderDetail = Service_ReceivingOrderDetail::getByCondition(array('receiving_code'=>$receivingCode),"*");
            $orders = array();
            foreach($receivingOrderDetail as $key=>$value){
                $orderRow = Service_Orders::getByField($value['order_code'],"order_code","*");
                $orderRow['orderCode'] = $orderRow['order_code'];
                $orders[] = $orderRow;
            }
            $receivingRow['OrderDetail'] = $orders;
        }else{
            $receivingDetail = Service_ReceivingDetail::getByCondition(array('receiving_code'=>$receivingCode),"*");
            $products = array();
            foreach($receivingDetail as $k=>$v){
                $p = Service_Product::getByField($v['product_id'],"product_id","*");
                $p['productSku'] = $p['product_sku'];
                $products[] = $p;
                $receivingDetail[$k]['product_sku'] = $p['product_sku'];
            }
            $receivingRow['productDetail'] = $products;
            $receivingRow['receivingDetail'] = $receivingDetail;
        }
        $result['ask'] = "1";
        $result['error'] = "";
        $result['message'] = "";
        $result['Data'] = $receivingRow;

        return $result;
    }

    public function confirmAsn($data){
        $this->common($data);
        $result = array(
            'ask'=>'1',
            'message'=>'',
            'error'=>'',
            'ASNCode'=>'',
        );
        $receivingCode = $this->_paramterArr['ASNCode'];

        $headerRequest = $this->_paramterArr['HeaderRequest'];
        $customerCode = $headerRequest['customerCode'];
        $customerRow = Service_Customer::getByField($customerCode,'customer_code',"*");

        $return = Service_AsnProccess::confirmASn($receivingCode,$customerRow['customer_id']);

        $result['ask'] = $return['ask'];
        $result['error'] = empty($return['error'])?"":implode(";",$result['error']);
        $result['message'] = $return['message'];
        $result['ASNCode'] = $receivingCode;

        return $result;
    }

    public function pendingAsn($data){
        $this->common($data);
        $result = array(
            'ask'=>'1',
            'message'=>'',
            'error'=>'',
            'ASNCode'=>'',
        );
        $receivingCode = $this->_paramterArr['ASNCode'];

        $headerRequest = $this->_paramterArr['HeaderRequest'];
        $customerCode = $headerRequest['customerCode'];
        $customerRow = Service_Customer::getByField($customerCode,'customer_code',"*");

        $return = Service_AsnProccess::PendingAsn($receivingCode,$customerRow['customer_id']);

        $result['ask'] = $return['ask'];
        $result['error'] = empty($return['error'])?"":implode(";",$result['error']);
        $result['message'] = $return['message'];
        $result['ASNCode'] = $receivingCode;

        return $result;
    }
    /**
     * @author william-fan
     * @todo 处理更新问题
     */
    public function  ASNupdateTransParam($receivingRow,$receivingInfo,$detail,$type='1'){
        $updateRow = array();


        $referenceNo = isset($receivingRow['refCode'])&&$receivingRow['refCode']!==''?$receivingRow['refCode']:$receivingInfo['reference_no'];
        $isDelivery = isset($receivingRow['isDelivery'])&&$receivingRow['isDelivery']!==''?$receivingRow['isDelivery']:$receivingInfo['is_delivery'];
        $iePort = isset($receivingRow['iePort'])&&$receivingRow['iePort']!==''?$receivingRow['iePort']:$receivingInfo['ie_port'];
        $formType = isset($receivingRow['formType'])&&$receivingRow['formType']!==''?$receivingRow['formType']:$receivingInfo['form_type'];
        $trafName = isset($receivingRow['trafName'])&&$receivingRow['trafName']!==''?$receivingRow['trafName']:$receivingInfo['traf_name'];
        $wrapType = isset($receivingRow['wrapType'])&&$receivingRow['wrapType']!==''?$receivingRow['wrapType']:$receivingInfo['wrap_type'];
        $packNo = isset($receivingRow['packNo'])&&$receivingRow['packNo']!==''?$receivingRow['packNo']:$receivingInfo['pack_no'];
        $trafMode = isset($receivingRow['trafMode'])&&$receivingRow['trafMode']!==''?$receivingRow['trafMode']:$receivingInfo['traf_mode'];
        $tradeMode = isset($receivingRow['tradeMode'])&&$receivingRow['tradeMode']!==''?$receivingRow['tradeMode']:$receivingInfo['trade_mode'];
        $transMode = isset($receivingRow['transMode'])&&$receivingRow['transMode']!==''?$receivingRow['transMode']:$receivingInfo['trans_mode'];
        $roughWeight = isset($receivingRow['roughWeight'])&&$receivingRow['roughWeight']!==''?$receivingRow['roughWeight']:$receivingInfo['roughweight'];

        $instructions = isset($receivingRow['roughWeight'])&&$receivingRow['roughWeight']!==''?$receivingRow['roughWeight']:$receivingInfo['roughweight'];




        if(isset($receivingRow['warehouseCode']) && $receivingRow['warehouseCode']!==''){
            $updateRow['warehouseCode'] = $receivingRow['warehouseCode'];
        }else{
            $warehouseId = $receivingInfo['warehouse_id'];
            $warehouse = Service_Warehouse::getByField($warehouseId);
            $updateRow['warehouseCode'] = $warehouse['warehouse_code'];
        }

        $updateRow['refCode'] = $referenceNo;
        $updateRow['isDelivery'] = $isDelivery;
        $updateRow['iePort'] = $iePort;
        $updateRow['formType'] = $formType;
        $updateRow['trafName'] = $trafName;
        $updateRow['wrapType'] = $wrapType;
        $updateRow['packNo'] = $packNo;
        $updateRow['trafMode'] = $trafMode;
        $updateRow['tradeMode'] = $tradeMode;
        $updateRow['transMode'] = $transMode;
        $updateRow['receiveMode'] = $receivingInfo['receive_model_type'];
        $updateRow['roughWeight'] = $roughWeight;
        $updateRow['instructions'] = $instructions;
        $updateRow['ASNCode'] = $receivingRow['ASNCode'];

        if($type=='1'){
            //集货模式
            if(!isset($receivingRow['ASNItems']['OrderInfo'])){
                //没传递值用原来的
                $details = array();
                foreach($detail as $key=>$value){
                    $detailArr = array(
                        'orderCode'=>$value['order_code']
                    );
                    $details[] = $detailArr;
                }
                $updateRow['ASNItems']['OrderInfo'] = $details;
            }else{
                 $updateRow['ASNItems']['OrderInfo'] =  $receivingRow['ASNItems']['OrderInfo'];
            }
        }else{
            //备货模式
            if(!isset($receivingRow['ASNItems']['productInfo'])){
                //没传递值用原来的
                $details = array();
                foreach($detail as $key=>$value){
                    $product = Service_Product::getByField($value['product_id']);
                    $detailArr = array(
                        'productSku'=>$product['product_sku'],
                        'quantity'=>$value['rd_receiving_qty'],
                        'declaredValue'=>$value['op_declared_value']
                    );
                    $details[] = $detailArr;
                }
                $updateRow['ASNItems']['productInfo'] = $details;
            }else{
                $updateRow['ASNItems']['productInfo'] = $receivingRow['ASNItems']['productInfo'];
            }
        }
        return $updateRow;
    }

}
