<?php

class Common_CalculateOtherFee
{
    protected $_paramsArray = array(); //参数
    protected $_dataArray   = array(); //自定义
    protected $_errorArray  = array(); //错误信息
    //只针对以下运输方式扣费
    protected $allowShipType = array(
        'SZY-EMS',
        'SZY-EUB',
        'WG-EUB',
        'WG-EMS'
    );
    protected $zccqShipType = array(
        'ZCCQ',
    );
    protected $iszccq = false;
    /***
     * 逻辑如下:
     * -----------------------------------------------------------
     *
     *                                 设置客户折扣 可用    （收费，按设置的打折）
     *                1) 默认费用设置  设置客户折扣 不可用  （收费，不打折）
     * 设置费用可用                    无设置客户折扣       （不收费）  
     *                                 
     *
     *                                 无设置客户折扣       （不收费）
     *                2) 非默认费用    设置客户折扣 可用    （收费，按设置的打折）
     *                                 设置客户折扣 不可用  （不收费）
     * ------------------------------------------------------------
     * 设置费用不可用 （不收费）
     */
    public function construct($params = array())
    {
        $this->setParams($params);
    }

    /**
     * @设置参数
     */
    public function setParams($params = array())
    {
        $keys = array(
            'customerCode'      => '',
            'warehouseId'       => '',
            'countryId'         => 0,
            'smId'              => 0,
            'smCode'            => '',
            'weight'            => 0,
            'length'            => 0,
            'width'             => 0,
            'height'            => 0,
            'provinceId'        => 0,
            'cityId'            => 0,
            'zip'               => null,
            //'warehouseName'     => '',
            //'countryCode'       => '',
            //'smClassCode'       => null, //运输方式分类的code
            'smFeeType'         => null, //费用类型：单票,总单
            'smCalcType'        => null, //计费类型：区间,首续重
            'order_code'        => null,
            'receiving_code'    => null,
            'receiving_weight'  => null,
            'orderProducts'     => array(),
            'orderInfo'         => array(),
            'receingInfo'       => array(),
            'realWeight'        => 0,
        );
        if (is_array($params)) {
            foreach ($keys as $key => $val) {
                if (isset($params[$key])) {
                    $keys[$key] = $params[$key];
                }
            }
        }
        unset($params);
        $this->_paramsArray = $keys;
        $ordersProducts = '';
        $orderinfo = '';
        if (isset($this->_paramsArray['order_code']) && $this->_paramsArray['order_code'] != '') {
            $ordersProductCondition = array(
                'order_code' => $this->_paramsArray['order_code']
            );
            $ordersProducts = Service_OrderProduct::getByCondition($ordersProductCondition, '*');
            $orderinfo      = Service_Orders::getByField($this->_paramsArray['order_code'], 'order_code');
            $this->_paramsArray['warehouse_id'] = $orderinfo['warehouse_id'];
        }
        $this->_paramsArray['orderProducts']    = $ordersProducts;
        $this->_paramsArray['orderInfo']        = $orderinfo;
        if (isset($this->_paramsArray['receiving_code']) && $this->_paramsArray['receiving_code'] != '') {
            $receivinginfo                      = Service_Receiving::getByField($this->_paramsArray['receiving_code'], 'receiving_code');
            $this->_paramsArray['receingInfo']  = $receivinginfo;
        }
        $this->getzccq();
    }
    private function getzccq(){
        $smCode = strtoupper($this->_paramsArray['smCode']);
        if(in_array($smCode,$this->zccqShipType)){
            $this->iszccq =true;
        }
    }

    /**
     * @todo 得到其它费用 - 重写
     */
    public function getOtherFee($feeCode = '')
    {
        $feeCode = strtolower($feeCode);
        $result = array(
            'state' => 0,
            'error' => array(),
            'data'  => array()
        );
        $otherFeeMixArr = Process_BillConfig::getOtherFeeArr();
        $otherFeeArr = array_keys($otherFeeMixArr);
        if (!empty($feeCode)) {
            $feeCode = str_replace('-', '', strtolower($feeCode));
            $functionName = 'get'.ucfirst($feeCode).'Fee';
            if(in_array($feeCode, $otherFeeArr) && method_exists($this, $functionName)){
                $this->$functionName();
            }
        }else {
            if(is_array($otherFeeArr) && !empty($otherFeeArr)){
                foreach ($otherFeeArr as $feeCode) {
                    $feeCode = str_replace('-', '', strtolower($feeCode));
                    $functionName = 'get'.ucfirst($feeCode).'Fee';
                    if(in_array($feeCode, $otherFeeArr) && method_exists($this, $functionName)){
                        $this->$functionName();
                    }
                }
            }
        }
        $result = array(
            'state'     => 1,
            'data'      => array(
                'otherFee'  => $this->_dataArray['costArr']['otherFee']
            )
        );
        return $result;
    }

    /**
     * [getFbataxFee 关税预付操作费]
     * @author [felix-tang] <[<email address>]>
     * @todo [计算关税操作费]
     * @return [type] [description]
     */
    private function getFbataxFee()
    {
        $otherfee = Service_OtherFee::getByField('FBATAX', 'fee_code');
        $return = array('currency_code' => $otherfee['fee_currency_code'], 'price' => 0, 'fee_id' => $otherfee['fee_id']);
        if ($this->iszccq) {
            return $return;
        }

        $fee_id = 0;
        $cost = 0;
        $discount = 1; /* 客户折扣，1=100% */
        if (empty($otherfee)) {
            return;
        }
        $fbataxfee = $otherfee['fee_value'];
        $cost = $otherfee['fee_amount'];
        $customerFeeCondition = array(
            'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
            'fee_id' => $otherfee['fee_id'],
        );
        $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
        if ('1' == $otherfee['status']) {
            //杂费状态：可用
            if (!empty($customerOtherFee)) {
                if ($customerOtherFee[0]['status'] == '1') {
                    //客户杂费可用，则参与打折计算
                    $fbataxfee = $customerOtherFee[0]['discount'] * $fbataxfee;
                    $discount = $customerOtherFee[0]['discount'];
                } else {
                    $fbataxfee = 0;
                }
            } else {
                //非默认费用且该客户无此项杂费设置，则此项费用不收
                if ('0' == $otherfee['is_default_fee']) {
                    $fbataxfee = 0;
                    $cost = 0;
                }
            }
        } else {
            //杂费状态：不可用
            $fbataxfee = 0;
            $cost = 0;
        }
        $fbataxfee = sprintf('%.2f', $fbataxfee);
        $this->_dataArray['costArr']['otherFee']['fbatax'] = array(
            'currency_code' => $otherfee['fee_currency_code'],
            'price' => $fbataxfee,
            'fee_id' => $otherfee['fee_id'],
            'discount' => $discount,
            'cost' => $cost,
            'cost_currency_code' => $otherfee['cost_currency_code'],
            'sp_code' => $otherfee['sp_code'],
        );
    }
    /**
     * @author william-fan
     * 由于目前无成本计算公式，所以成本写死为 0
             2014-11-03 
        鹤鸣九天 10:56:34 
          库内拣货费，成本你们设置为零。
          我想问：假如成本不设置为零，那么成本跟产品个数的计算公式是怎样？ 或者如果你们没考虑过，我就直接在程序里面写死这个成本为零。
        大王Heidi 10:57:30 
          拣货费的成本其实就是的仓租以及我们的人工费用
        大王Heidi 10:57:39 
          是无法和产品个数进行联系的
        大王Heidi 10:57:44 
          所以还是写死吧
     * @todo 用于计算库内拣货费
     */
    //包材费
    /*
    
    private function getBaocaiFee(){
        if($this->iszccq){
            return;
        }
        $otherfee = Service_OtherFee::getByField('BAOCAI', 'fee_code');
        if (empty($otherfee)) {
            return;
        }

        $baocaiFee     = sprintf('%.2f', $otherfee['fee_value']);
        $baocaiCost    = sprintf('%.2f', $otherfee['fee_amount']);

        $customerFeeCondition = array(
            'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
            'fee_id'        => $otherfee['fee_id']
        );
        $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
        if ($otherfee['is_default_fee'] == '1') {
            //操作费可用
            if (!empty($customerOtherFee)) {
                if ($customerOtherFee[0]['status'] == 0 && 
                    $customerOtherFee[0]['discount']>0) {
                    $baocaiFee = 0;
                } else { 
                    $baocaiFee = $customerOtherFee[0]['discount'] * $baocaiFee;
                    $discount   = $customerOtherFee[0]['discount'];
                }
            }else{
                    $baocaiFee = $otherfee['fee_discount'] * $baocaiFee;
                    $discount   = $otherfee['fee_discount'];
            }
        } else {
            //操作费不可用
            if ($customerOtherFee[0]['discount']>0 && $customerOtherFee[0]['status'] == '1') {
                $baocaiFee = $customerOtherFee[0]['discount'] * $baocaiFee;
                $discount   = $customerOtherFee[0]['discount'];
            } else {
                $baocaiFee = 0;
            }
        }
        $this->_dataArray['costArr']['otherFee']['baocai'] = array(
            'cost_currency_code'  => $otherfee['cost_currency_code'],
            'currency_code' => $otherfee['fee_currency_code'],
            'price'         => $baocaiFee,
            'discount'      => $discount,
            'cost'          => $baocaiCost,
            'sp_code'       => $otherfee['sp_code'],
            'fee_id'        => $otherfee['fee_id']
        );

    }
    */
    private function getChaochangFee(){
        if($this->iszccq){
            return;
        }
    	$chaochangfee=0;
        $cost=0;
        $sum=0;
    	$otherfee = Service_OtherFee::getByField('CHAOCHANG', 'fee_code');
        if (empty($otherfee)) {
            return;
        }

         $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
                'fee_id'        => $otherfee['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');

            if('1' == $otherfee['status']){
            	if($this->_paramsArray['orderInfo']['sm_code']=='HKDHL'){
            		$order_code=$this->_paramsArray['orderInfo']['order_code'];
            		$shippingMethod = Service_ShippingMethod::getByField('HKDHL',"sm_code");
            		$shipOrderD=Service_ShipOrderDetail::getByCondition(array('order_code'=>$order_code),'*');
                    foreach ($shipOrderD as $key => $shipOrderDetail) {
                        if ((int)$shipOrderDetail['sod_length']>120||(int)$shipOrderDetail['sod_width']>120||(int)$shipOrderDetail['sod_height']>120||(int)$shipOrderDetail['sod_weight']>70){
                            $sum+=1;
                        }else{
                            $sum=0;
                        }
                    }
            		if ($sum>0){
                        if ($customerOtherFee[0]['status'] == '1') {
                        $chaochangfee=$customerOtherFee[0]['discount'] *$otherfee['fee_value'];
                        }else{
                            $chaochangfee=$otherfee['fee_value'];
                        }			
            			$cost=$otherfee['fee_amount']+$otherfee['fee_amount']*$shippingMethod['sm_baf'];
            		}
            	}
            }
            $this->_dataArray['costArr']['otherFee']['chaochang'] = array(
            'cost_currency_code'  => $otherfee['cost_currency_code'],
            'currency_code' => $otherfee['fee_currency_code'],
            'price'         => $chaochangfee,
            'discount'      => 0,
            'cost'          => $cost, /* 成本写死为 0 */
            'sp_code'       => $otherfee['sp_code'],
            'fee_id'        => $otherfee['fee_id']
        );
    }
    private function getChaozhiFee(){
        if($this->iszccq){
            return;
        }
    	//$cost=25;   //订单目的地海关申报价值超过并包含120USD时收取25元/票
    	//$rate=6.3;   //USD转成RMB汇率
    	$add=0.0006;  //超过12800USD加收万分之六
        $caozhifee=0;
    	$otherfee = Service_OtherFee::getByField('CHAOZHI', 'fee_code');
        if (empty($otherfee)) {
            return;
        }
        $caozhi=$otherfee['fee_value'];
        $cost = 0;
        $currency=Service_Currency::getByField("USD",'currency_code');
        $rate=$currency['currency_rate'];
        $customerFeeCondition = array(
            'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
            'fee_id'        => $otherfee['fee_id']
        );
        $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');

        if('1' == $otherfee['status']){
        	if($this->_paramsArray['orderInfo']['sm_code']=='HKUPS-KW'){
        		$sum=0;
        		foreach ($this->_paramsArray['orderProducts'] as $key => $value) {
        			$total=$value['op_quantity']*$value['op_purpose_declared_value'];
        			$sum+=$total;
        		}
        		if ($sum>=120 && $sum<12800) {
                    if ($customerOtherFee[0]['status'] == '1') {
                        $caozhifee  =$customerOtherFee[0]['discount']*$caozhi;
                    }else{
        			     $caozhifee  = $caozhi;
                    }
                    $cost = $otherfee['fee_amount'];
        		}elseif($sum>=12800){
        			$caozhifee =$sum*$rate*$add+$caozhi;
                    $feecost =$sum*$rate*$add;
                    $feevalue=Service_Currency::converByCode('RMB',$otherfee['cost_currency_code'],$feecost);
                    $cost=$feevalue+$otherfee['fee_amount'];
        		}else{
        			$caozhifee  = 0;
                    $cost =0;
        		}
    		}
        }
        $this->_dataArray['costArr']['otherFee']['chaozhi'] = array(
            'cost_currency_code'  => $otherfee['cost_currency_code'],
            'currency_code' => $otherfee['fee_currency_code'],
            'price'         => $caozhifee,
            'discount'      => 0,
            'cost'          => $cost, //$cost/* 成本写死为 0 */
            'sp_code'       => $otherfee['sp_code'],
            'fee_id'        => $otherfee['fee_id']
        );
    }
    private function getCaozuoFee()
    {
        if($this->iszccq){
            return;
        }
        $maxNumber  = 5;    /* 最多只收5件费用，超过5件后不再增加 */
        $feeAdd     = 0.5;  /* 续件0.5元 */
        $discount   = 1;    /* 客户折扣，1=100% */
        $maxMoney = 30;     // 单票订单最高收30
        $otherfee = Service_OtherFee::getByField('CAOZUO', 'fee_code');
        if (empty($otherfee)) {
            return;
        }

        $caozuofee  = $otherfee['fee_value'];
        //$cost       = $otherfee['fee_amount'];
        //1.5元/单+0.5*（n-1）
        if ($this->_paramsArray['orderInfo']['order_mode_type'] == '0') {
            //备货模式才收操作费
            $products = 0;
            if (isset($this->_paramsArray['orderProducts'])) {
                $ordersProducts = $this->_paramsArray['orderProducts'];
                foreach ($ordersProducts as $key => $value) {
                    $products += $value['op_quantity'];
                }
            }
            if ($products > 0) {
                //$products = ($products >= $maxNumber)? $maxNumber : $products;
                if($products <= $maxNumber){
                    $caozuofee  = $caozuofee + ($products - 1) * $feeAdd;
                }else{
                    $caozuofee  = $caozuofee + 2 +($products - 5) * 0.2;
                }
                //$cost       = $cost + ($products - 1) * $feeAdd;
            }
            
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
                'fee_id'        => $otherfee['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');

            if('1' == $otherfee['status']){
            //杂费状态：可用
                if(!empty($customerOtherFee)) {
                    if ($customerOtherFee[0]['status'] == '1') {
                        //客户杂费可用，则参与打折计算
                        $caozuofee  = $customerOtherFee[0]['discount'] * $caozuofee;
                        $cost       = 0;
                        $discount   = $customerOtherFee[0]['discount'];
                    }
                } else {
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if('0' == $otherfee['is_default_fee']){
                        $caozuofee  = 0;
                        $cost       = 0;
                    }
                }
            } else {
            //杂费状态：不可用
                $caozuofee  = 0;
                $cost       = 0;
            }

        } else {
            //集货模式操作费为0
            $caozuofee  = 0;
            $cost       = 0;
        }


        $this->_dataArray['costArr']['otherFee']['caozuo'] = array(
            'cost_currency_code'  => $otherfee['cost_currency_code'],
            'currency_code' => $otherfee['fee_currency_code'],
            'price'         => $caozuofee > $maxMoney ? $maxMoney : $caozuofee,
            'discount'      => $discount,
            'cost'          => 0, /* 成本写死为 0 */
            'sp_code'       => $otherfee['sp_code'],
            'fee_id'        => $otherfee['fee_id']
        );
    }

    /**
     * @author william-fan
     * @todo 用于计算仓储费
     */
    private function getCangchuFee()
    {
        if($this->iszccq){
            return;
        }
        /* 	
         *  首15天全免，
			之后按0.1元/SKU/天 
		*/
        $freeDays   = 30; 	//不免租了就是这么任性 -- 免租期改成 30 天
        $discount   = 1;    /* 客户折扣，1=100% */

        $otherfee = Service_OtherFee::getByField('CANGCHU', 'fee_code');
        if (empty($otherfee) || ($this->_paramsArray['orderInfo']['warehouse_id'] != $otherfee['warehouse_id'] && $otherfee['warehouse_id'] != '0')) {
            return;
        }
        $cangchuFee     = 0;
        $cangchuCost    = 0;
        if ($this->_paramsArray['orderInfo']['order_mode_type'] == '0') {
            $pickingCondition = array(
                'order_code'    => $this->_paramsArray['order_code'],
                'pd_status'     => '1'
            );
            $pickingDetails = Service_PickingDetail::getByCondition($pickingCondition, '*');

            if (!empty($pickingDetails)) {
                $dateTo = $pickingDetails[0]['pd_add_time'];
                foreach ($pickingDetails as $key => $value) {
                    $inventoryBatch = Service_InventoryBatch::getByField($value['ib_id']);
                    if (!empty($inventoryBatch)) {
                        $dateFrom       = $inventoryBatch['ib_add_time'];
                        $diffdate       = $this->getDiffDate($dateFrom, $dateTo);
                        $days           = $diffdate - $freeDays;
                        $days           = $days > 0 ? $days : 0;
                        $cangchuFee     = $cangchuFee  + $otherfee['fee_value']  * $value['pd_quantity'] * $days;
                        $cangchuCost    = $cangchuCost + $otherfee['fee_amount'] * $value['pd_quantity'] * $days;
                    }else{
                        //inventory batch为空核销了
                        //$pickingDetail = Service_PickingDetail::getByCondition(array('order_code'=>$v['order_code'],'product_id'=>$v['product_id']),"*");
                        $inventoryBatchLog = Service_InventoryBatchLog::getByCondition(array('ib_id'=>$value['ib_id'],'application_code'=>'Putaway','ibl_quantity_before'=>'0'),"*",0,0,'ibl_id asc');
                        if(!empty($inventoryBatchLog)){
                            $dateFrom = $inventoryBatchLog[0]['ibl_add_time'];
                            //$dateFrom       = $inventoryBatch['ib_add_time'];
                            $diffdate       = $this->getDiffDate($dateFrom, $dateTo);
                            $days           = $diffdate - $freeDays;
                            $days           = $days > 0 ? $days : 0;
                            $cangchuFee     = $cangchuFee  + $otherfee['fee_value']  * $value['pd_quantity'] * $days;
                            $cangchuCost    = $cangchuCost + $otherfee['fee_amount'] * $value['pd_quantity'] * $days;
                        }
                    }
                }
            }
        } else {
            $cangchuFee     = 0;
            $cangchuCost    = 0;
        }
        $cangchuFee     = sprintf('%.2f', $cangchuFee);
        $cangchuCost    = sprintf('%.2f', $cangchuCost);

        $customerFeeCondition = array(
            'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
            'fee_id'        => $otherfee['fee_id']
        );
        $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
        if ($otherfee['status'] == '1') {
            //操作费可用
            if (!empty($customerOtherFee)) {
                if ($customerOtherFee[0]['status'] == '1') {
                    $cangchuFee = $customerOtherFee[0]['discount'] * $cangchuFee;
                    $discount   = $customerOtherFee[0]['discount'];
                } else {
                    $cangchuFee = 0;
                }
            }
        } else {
            //操作费不可用
            if (!empty($customerOtherFee) && $customerOtherFee[0]['status'] == '1') {
                $cangchuFee = $customerOtherFee[0]['discount'] * $cangchuFee;
                $discount   = $customerOtherFee[0]['discount'];
            } else {
                $cangchuFee = 0;
            }
        }
        $this->_dataArray['costArr']['otherFee']['cangchu'] = array(
            'cost_currency_code'  => $otherfee['cost_currency_code'],
            'currency_code' => $otherfee['fee_currency_code'],
            'price'         => $cangchuFee,
            'discount'      => $discount,
            'cost'          => $cangchuCost,
            'sp_code'       => $otherfee['sp_code'],
            'fee_id'        => $otherfee['fee_id']
        );
    }

    /**
     * @author william-fan
     * @todo 用于计算两个时间段的时间差
     */
    private function getDiffDate($dateFrom, $dateTo)
    {
        list($year, $month, $day) = sscanf($dateFrom, '%d-%d-%d');
        if (!checkdate($month, $day, $year)) {
            return false;
        }
        list($year, $month, $day) = sscanf($dateTo, '%d-%d-%d');
        if (!checkdate($month, $day, $year)) {
            return false;
        }
        $timeStamp = (strtotime($dateTo) - strtotime($dateFrom));
        return ceil($timeStamp / (24 * 3600));
    }

    /**
     * @author solar<solarzheng@cargofe.com.cn>
     * @todo 计算报关费
     */
    private function getBaoguanFee()
    {
        if($this->iszccq){
            return;
        }
        $weight = 2;    // 重量区别
        $baoguanFee     = 0;
        // 重量取计费重量
        $shipOrder  = Service_ShipOrder::getByField($this->_paramsArray['order_code'], 'order_code');

        /*if (isset($shipOrder['so_fee_weight']) && $shipOrder['so_fee_weight'] != 0) {
            $orderWeight    = $shipOrder['so_fee_weight'];
        } else {
            $orderWeight    = $this->_paramsArray['weight'];
        }*/
        $orderWeight    = $this->_paramsArray['weight'];

        $fee_id         = 0;
        $cost           = 0;
        $discount       = 1;    /* 客户折扣，1=100% */
        $is_baoguan2    = false;
        //大于2kg
        if ($orderWeight <= $weight) {
            $baoguan        = Service_OtherFee::getByField('BAOGUAN1', 'fee_code');
            $baoguanFee     = $baoguan['fee_value'];
            $cost           = $baoguan['fee_amount'];
        }else{
            $is_baoguan2    = true;
            $baoguan        = Service_OtherFee::getByField('BAOGUAN2', 'fee_code');
            $baoguanFee     = $baoguan['fee_value']  * $orderWeight;
            $cost           = $baoguan['fee_amount'] * $orderWeight;
        }
        $currency_code  = $baoguan['fee_currency_code'];
        $fee_id         = $baoguan['fee_id'];

        $baoguanFee = sprintf('%.2f', $baoguanFee);

        if (!empty($baoguan)) {
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
                'fee_id'        => $fee_id
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
            if('1' == $baoguan['status']){
            //杂费状态：可用
                if(!empty($customerOtherFee)) {
                    if ($customerOtherFee[0]['status'] == '1') {
                        //客户杂费可用，则直接获取客户杂费里的配置费用
                        if($is_baoguan2){
                            $baoguanFee = $customerOtherFee[0]['fee_value'] * $orderWeight;
                        }else{
                            $baoguanFee = $customerOtherFee[0]['fee_value'];
                        }
                        $discount   = $customerOtherFee[0]['discount'];
                    }
                } else {
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if('0' == $baoguan['is_default_fee']){
                        $baoguanFee = 0;
                        $cost       = 0;
                    }
                }
            } else {
            //杂费状态：不可用
                $baoguanFee = 0;
                $cost       = 0;
            }

            $this->_dataArray['costArr']['otherFee']['baoguan'] = array(
                'cost_currency_code'  => $baoguan['cost_currency_code'],
                'currency_code' => $currency_code,
                'price'         => $baoguanFee,
                'discount'      => $discount,
                'cost'          => $cost,
                'sp_code'       => $baoguan['sp_code'],
                'fee_id'        => $fee_id
            );
        }
    }


    /**
     * @author solar<solarzheng@cargofe.com.cn>
     * @todo 计算提货费
     */
    private function getTiHuoFee()
    {
        if($this->iszccq){
            return;
        }
        $tihuoFee       = 0;
        $cost           = 0;
        $discount       = 1;    /* 客户折扣，1=100% */
        $receivingRow   = $this->_paramsArray['receingInfo'];
        $tihuo          = Service_OtherFee::getByField('TIHUO', 'fee_code');
        if (empty($tihuo)) {
            return;
        }

        if (isset($this->_paramsArray['receiving_weight']) && $this->_paramsArray['receiving_weight'] > 0) {
            $weight = $this->_paramsArray['receiving_weight'];
        } else {
            $weight = 0;
            if ($receivingRow['receive_model_type'] == 1) { //集货
                $weight = Service_ReceivingOrderDetail::sumNetWeight($this->_paramsArray['receiving_code']);
            } /*else { //备货
                $weight = Service_ReceivingDetail::sumNetWeight($this->_paramsArray['receiving_code']);
            }*/
        }
        $tihuoFee   = sprintf('%.2f', $tihuo['fee_value'] * $weight);
        $cost       = sprintf('%.2f', $tihuo['fee_amount'] * $weight);

        //最低100RMB限制
        if($tihuoFee>0){
            $tihuoFeeRMB=Service_Currency::converByCode($tihuo['fee_currency_code'],'RMB',$tihuoFee);
            if($tihuoFeeRMB<100){
                $tihuoFeeRMB = 100;
                $tihuoFee = Service_Currency::converByCode('RMB',$tihuo['fee_currency_code'],$tihuoFeeRMB);
            }
        }


        $customerFeeCondition = array(
            'customer_code' => $this->_paramsArray['receingInfo']['customer_code'],
            'fee_id'        => $tihuo['fee_id']
        );
        $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
        if('1' == $tihuo['status']){
        //杂费状态：可用
            if(!empty($customerOtherFee)) {
                if ($customerOtherFee[0]['status'] == '1') {
                    //客户杂费可用，则参与打折计算
                    $tihuoFee   = $customerOtherFee[0]['discount'] * $tihuoFee;
                    $discount   = $customerOtherFee[0]['discount'];
                }
            } else {
                //非默认费用且该客户无此项杂费设置，则此项费用不收
                if('0' == $tihuo['is_default_fee']){
                    $tihuoFee   = 0;
                    $cost       = 0;
                }
            }
        } else {
        //杂费状态：不可用
            $tihuoFee   = 0;
            $cost       = 0;
        }
        $this->_dataArray['costArr']['otherFee']['tihuo'] = array(
            'cost_currency_code'      => $tihuo['cost_currency_code'],
            'currency_code' => $tihuo['fee_currency_code'],
            'price'         => $tihuoFee,
            'discount'      => $discount,
            'cost'          => $cost,
            'sp_code'       => $tihuo['sp_code'],
            'fee_id'        => $tihuo['fee_id']
        );
    }

    /**
     * @author solar<solarzheng@cargofe.com.cn>
     * @todo 计算中港运输费
     */
    private function getYunshuFee()
    {
        if($this->iszccq){
            return;
        }
        $yunshuFee  = 0;
        $cost       = 0;
        $discount   = 1;    /* 客户折扣，1=100% */
        $yunshu     = Service_OtherFee::getByField('YUNSHU', 'fee_code');
        $weight     = $this->_paramsArray['weight'];
        $allowShip = array(
            'SELF-HF-ASENDIA',
            'SELF-HF-DGM',
            'SELF-HF-PNLP',
            'SELF-HF-DDP'
        );

        if (!empty($yunshu)) {
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
                'fee_id'        => $yunshu['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
            if('1' == $yunshu['status']){
            //杂费状态：可用
                if(!empty($customerOtherFee)) {
                    if ($customerOtherFee[0]['status'] == '1') {
                        if(in_array($this->_paramsArray['orderInfo']['sm_code'],$allowShip)){
                            $yunshuFee  = sprintf('%.2f', $yunshu['fee_value'] * $weight);
                            $cost       = sprintf('%.2f', $yunshu['fee_amount'] * $weight);
                        }
                        //客户杂费可用，则参与打折计算
                        $yunshuFee  = $customerOtherFee[0]['discount'] * $yunshuFee;
                        $discount   = $customerOtherFee[0]['discount'];
                    }
                } else {
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if('0' == $yunshu['is_default_fee']){
                        $yunshuFee  = 0;
                        $cost       = 0;
                    }
                }
            } else {
            //杂费状态：不可用
                $yunshuFee  = 0;
                $cost       = 0;
            }

            $this->_dataArray['costArr']['otherFee']['yunshu'] = array(
                'cost_currency_code'      => $yunshu['cost_currency_code'],
                'currency_code' => $yunshu['fee_currency_code'],
                'price'         => $yunshuFee,
                'discount'      => $discount,
                'cost'          => $cost,
                'sp_code'       => $yunshu['sp_code'],
                'fee_id'        => $yunshu['fee_id']
            );
        }
    }

    /**
     * @author 
     * @todo 计算监管车运输费
     */
    private function getJianguanyunshuFee()
    {
        if($this->iszccq){
            return;
        }
        $yunshuFee  = 0;
        $cost       = 0;
        $discount   = 1;    /* 客户折扣，1=100% */
        $yunshu     = Service_OtherFee::getByField('JIANGUANYUNSHU', 'fee_code');
        $weight     = $this->_paramsArray['weight'];
        $allowShip = array(
            'SELF-HF-EUB',
        );

        if (!empty($yunshu)) {
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
                'fee_id'        => $yunshu['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
            if('1' == $yunshu['status']){
            //杂费状态：可用
                if(!empty($customerOtherFee)) {
                    if ($customerOtherFee[0]['status'] == '1') {
                        if(in_array($this->_paramsArray['orderInfo']['sm_code'],$allowShip)){
                            $yunshuFee  = sprintf('%.2f', $yunshu['fee_value'] * $weight);
                            $cost       = sprintf('%.2f', $yunshu['fee_amount'] * $weight);
                        }
                        //客户杂费可用，则参与打折计算
                        $yunshuFee  = $customerOtherFee[0]['discount'] * $yunshuFee;
                        $discount   = $customerOtherFee[0]['discount'];
                    }
                } else {
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if('0' == $yunshu['is_default_fee']){
                        $yunshuFee  = 0;
                        $cost       = 0;
                    }
                }
            } else {
            //杂费状态：不可用
                $yunshuFee  = 0;
                $cost       = 0;
            }

            $this->_dataArray['costArr']['otherFee']['jianguanyunshu'] = array(
                'cost_currency_code'      => $yunshu['cost_currency_code'],
                'currency_code' => $yunshu['fee_currency_code'],
                'price'         => $yunshuFee,
                'discount'      => $discount,
                'cost'          => $cost,
                'sp_code'       => $yunshu['sp_code'],
                'fee_id'        => $yunshu['fee_id']
            );
        }
    }

    /**
     * @todo 计算入库费
     */
    private function getRukuFee()
    {
        if($this->iszccq){
            return;
        }
        $cost       = 0;
        $discount   = 1;    /* 客户折扣，1=100% */
        if ($this->_paramsArray['receingInfo']['receive_model_type'] == '0') {
            $weight = $this->_paramsArray['receiving_weight'];
            $ruku = Service_OtherFee::getByField("RUKU", "fee_code", "*");
            if (!empty($ruku)) {
                $customerFeeCondition = array(
                    'customer_code' => $this->_paramsArray['receingInfo']['customer_code'],
                    'fee_id'        => $ruku['fee_id']
                );
                $customerOtherFee   = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
                $rukuFee            = $ruku['fee_value'] * $orderWeight;
                $cost               = $ruku['fee_amount'] * $orderWeight;
                $mapCharge=array(
                    '1000'=>array('0','2000'),
                    '1500'=>array('2000','5000'),
                    '2000'=>array('5000'),
                );
                $rukuFee = $ruku['fee_value']*$weight;
                foreach($mapCharge as $maxMoney=>$weightRange){
                    if(isset($weightRange[1])){
                          if($weight<=$weightRange[1]){
                              if($rukuFee>$maxMoney){
                                $rukuFee=$maxMoney;
                              }
                             break;
                          }
                    }else{
                        $rukuFee=$maxMoney;
                    }
                  
                }
                if('1' == $ruku['status']){
                //杂费状态：可用
                    if(!empty($customerOtherFee)) {
                        if ($customerOtherFee[0]['status'] == '1') {
                            //客户杂费可用，则参与打折计算
                            $rukuFee    = $customerOtherFee[0]['discount'] * $rukuFee;
                            $discount   = $customerOtherFee[0]['discount'];
                        }
                    } else {
                        //非默认费用且该客户无此项杂费设置，则此项费用不收
                        if('0' == $ruku['is_default_fee']){
                            $rukuFee    = 0;
                            $cost       = 0;
                        }
                    }
                } else {
                //杂费状态：不可用
                    $rukuFee    = 0;
                    $cost       = 0;
                }
                $this->_dataArray['costArr']['otherFee']['ruku'] = array(
                    'cost_currency_code'      => $ruku['cost_currency_code'],
                    'currency_code' => $ruku['fee_currency_code'],
                    'price'         => $rukuFee,
                    'discount'      => $discount,
                    'cost'          => $cost,
                    'sp_code'       => $ruku['sp_code'],
                    'fee_id'        => $ruku['fee_id']
                );
            }
        }
    }

    /**
     * @todo 计算物流操作费
     */
    private function getWuliucaozuoFee()
    {
        if($this->iszccq){
            return;
        }
        $cost           = 0;
        $discount       = 1;    /* 客户折扣，1=100% */
        $wlcz           = Service_OtherFee::getByField("WULIUCAOZUO", "fee_code", "*");
        $shippingMethod = Service_ShippingMethod::getByField($this->_paramsArray['orderInfo']['sm_code'],"sm_code","*");
        if('1' == $shippingMethod['sm_channel']){
        //自有运输方式不收物流操作费
            $this->_dataArray['costArr']['otherFee']['wuliucaozuo'] = array(
                'currency_code' => $wlcz['fee_currency_code'],
                'price'         => 0,
                'fee_id'        => $wlcz['fee_id']
            );
        } else {
            if (!empty($wlcz)) {
                $customerFeeCondition = array(
                    'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
                    'fee_id'        => $wlcz['fee_id']
                );
                $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
                $wlczFee    = $wlcz['fee_value'];
                $cost       = $wlcz['fee_amount'];

                if('1' == $wlcz['status']){
                //杂费状态：可用
                    if(!empty($customerOtherFee)) {
                        if ($customerOtherFee[0]['status'] == '1') {
                            //客户杂费可用，则参与打折计算
                            $wlczFee    = $customerOtherFee[0]['discount'] * $wlczFee;
                            $discount   = $customerOtherFee[0]['discount'];
                        }
                    } else {
                        //非默认费用且该客户无此项杂费设置，则此项费用不收
                        if('0' == $wlcz['is_default_fee']){
                            $wlczFee    = 0;
                            $cost       = 0;
                        }
                    }
                } else {
                //杂费状态：不可用
                    $wlczFee    = 0;
                    $cost       = 0;
                }

                $this->_dataArray['costArr']['otherFee']['wuliucaozuo'] = array(
                    'cost_currency_code'      => $wlcz['cost_currency_code'],
                    'currency_code' => $wlcz['fee_currency_code'],
                    'price'         => $wlczFee,
                    'discount'      => $discount,
                    'cost'          => $cost,
                    'sp_code'       => $wlcz['sp_code'],
                    'fee_id'        => $wlcz['fee_id']
                );
            }
        }
    }

    /**
     * @author william-fan
     * @todo 计算集中申报费
     */
    private function getJzsbFee() {
        if($this->iszccq){
            return;
        }
		$cost = 0;
		$discount = 1; /* 客户折扣，1=100% */
        $jzsb = Service_OtherFee::getByField("JZSB","fee_code","*");
		if (! empty ( $jzsb )) {
			$customerFeeCondition = array (
					'customer_code' => $this->_paramsArray ['orderInfo'] ['customer_code'],
					'fee_id' => $jzsb ['fee_id']
			);
			$customerOtherFee = Service_CustomerOtherFee::getByCondition ( $customerFeeCondition, '*' );
			$jzsbFee = $jzsb ['fee_value'] ;
			$cost = $jzsb ['fee_amount'];
			
			if ('1' == $jzsb ['status']) {
				// 杂费状态：可用
				if (! empty ( $customerOtherFee )) {
					if ($customerOtherFee [0] ['status'] == '1') {
						// 客户杂费可用，则参与打折计算
                        $orderWeight = $this->_paramsArray ['weight'];
                        $jzsb = Service_OtherFee::getByField ( "JZSB", "fee_code", "*" );
                        switch($jzsb['fee_unit']){
                            case '1':
                                $jzsbFee     = $jzsb['fee_value']*$orderWeight;
                                $cost           = $jzsb['fee_amount']*$orderWeight;
                                break;
                            case '2':
                                $jzsbFee     = $jzsb['fee_value'];
                                $cost           = $jzsb['fee_amount'];
                                break;
                        }
                        $jzsbFee = $customerOtherFee [0] ['discount'] * $jzsbFee;
						$discount = $customerOtherFee [0] ['discount'];
					}
				} else {
					// 非默认费用且该客户无此项杂费设置，则此项费用不收
					if ('0' == $jzsb ['is_default_fee']) {
                        $jzsbFee = 0;
						$cost = 0;
					}
				}
			} else {
				// 杂费状态：不可用
                $jzsbFee = 0;
				$cost = 0;
			}
			$this->_dataArray ['costArr'] ['otherFee'] ['jzbg'] = array (
                    'cost_currency_code' => $jzsb ['cost_currency_code'],
					'currency_code' => $jzsb ['fee_currency_code'],
					'price' => $jzsbFee,
					'discount' => $discount,
					'cost' => $cost,
					'sp_code' => $jzsb ['sp_code'],
					'fee_id' => $jzsb ['fee_id']
			);
		}
	}

    /**
     * @author william-fan
     * @todo 计算偏远费
     */
    private function getPianyuanFee(){
        if($this->iszccq){
            return;
        }
        //是偏远的订单
        if($this->_paramsArray['orderInfo']['is_remote_city']=='1'){
            //4PX-HKDHL该渠道只扣偏远地区附加费
            if($this->_paramsArray['orderInfo']['sm_code']=='4PX-HKDHL'){
                return;
            }
            //偏远城市，计算偏远费
            $pianyuan = Service_OtherFee::getByField ( "PIANYUAN", "fee_code", "*" );
            if (! empty ( $pianyuan )) {
                $customerFeeCondition = array (
                    'customer_code' => $this->_paramsArray ['orderInfo'] ['customer_code'],
                    'fee_id' => $pianyuan ['fee_id']
                );
                $customerOtherFee = Service_CustomerOtherFee::getByCondition ( $customerFeeCondition, '*' );
                $smCode = $this->_paramsArray['smCode'];
                $pianyuanFee = $pianyuan ['fee_value'] ;
                //$cost = $pianyuan ['fee_amount'];
                
                //echo $cost;exit;
                $discount = 1;
                if(!empty($smCode)){
                    $shippingMethod = Service_ShippingMethod::getByField($smCode,"sm_code");
                    if('CRE' == $shippingMethod['sm_class_code']){
                        $baf =  $shippingMethod['sm_baf'];
                        $pianyuanFee = $pianyuanFee*$baf+$pianyuanFee;
                    }
                }
                $cost=$pianyuan['fee_amount']+$pianyuan['fee_amount']*$shippingMethod['sm_baf'];
                if ('1' == $pianyuan ['status']) {
                    // 杂费状态：可用
                    if (! empty ( $customerOtherFee )) {
                        if ($customerOtherFee [0] ['status'] == '1') {
                            // 客户杂费可用，则参与打折计算
                            $pianyuanFee = $customerOtherFee [0] ['discount'] * $pianyuanFee;
                            $discount = $customerOtherFee [0] ['discount'];
                        }
                    } else {
                        // 非默认费用且该客户无此项杂费设置，则此项费用不收
                        if ('0' == $pianyuan ['is_default_fee']) {
                            $pianyuanFee = 0;
                            $cost = 0;
                        }
                    }
                } else {
                    // 杂费状态：不可用
                    $pianyuanFee = 0;
                    $cost = 0;
                }
                $this->_dataArray ['costArr'] ['otherFee'] ['pianyuan'] = array (
                    'cost_currency_code' => $pianyuan ['cost_currency_code'],
                    'currency_code' => $pianyuan ['fee_currency_code'],
                    'price' => $pianyuanFee,
                    'discount' => $discount,
                    'cost' => $cost,
                    'sp_code' => $pianyuan ['sp_code'],
                    'fee_id' => $pianyuan ['fee_id']
                );
            }

        }
    }

    /**
     * @author william-fan
     * @todo 计算物料费
     */
    private function getWuliaoFee(){
        if($this->iszccq){
            return;
        }
        $wuliaoFee  = 0;
        $cost       = 0;
        $discount   = 1;    /* 客户折扣，1=100% */
        $wuliao     = Service_OtherFee::getByField('WULIAO', 'fee_code');
        $weight     = $this->_paramsArray['weight'];

        if (!empty($wuliao)) {
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
                'fee_id'        => $wuliao['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
            if('1' == $wuliao['status']){
                //杂费状态：可用
                if(!empty($customerOtherFee)) {
                    if(in_array($this->_paramsArray['smCode'],$this->allowShipType)){
                        $wuliaoFee  = sprintf('%.2f', $wuliao['fee_value'] * $weight);
                        $cost       = sprintf('%.2f', $wuliao['fee_amount'] * $weight);
                    }
                    if ($customerOtherFee[0]['status'] == '1') {
                        //客户杂费可用，则参与打折计算
                        $wuliaoFee  = $customerOtherFee[0]['discount'] * $wuliaoFee;
                        $discount   = $customerOtherFee[0]['discount'];
                    }
                } else {
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if('0' == $wuliao['is_default_fee']){
                        $wuliaoFee  = 0;
                        $cost       = 0;
                    }
                }
            } else {
                //杂费状态：不可用
                $wuliaoFee  = 0;
                $cost       = 0;
            }

            $this->_dataArray['costArr']['otherFee']['wuliao'] = array(
                'cost_currency_code'      => $wuliao['cost_currency_code'],
                'currency_code' => $wuliao['fee_currency_code'],
                'price'         => $wuliaoFee,
                'discount'      => $discount,
                'cost'          => $cost,
                'sp_code'       => $wuliao['sp_code'],
                'fee_id'        => $wuliao['fee_id']
            );
        }
    }
    /**
     * @author william-fan
     * @todo 计算管理费
     */
    private function getGuanliFee(){
        if($this->iszccq){
            return;
        }
        $guanliFee  = 0;
        $cost       = 0;
        $discount   = 1;    /* 客户折扣，1=100% */
        $guanli     = Service_OtherFee::getByField('GUANLI', 'fee_code');
        $weight     = $this->_paramsArray['weight'];


        if (!empty($guanli)) {
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
                'fee_id'        => $guanli['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
            if('1' == $guanli['status']){
                //杂费状态：可用
                if(!empty($customerOtherFee)) {
                    if(in_array($this->_paramsArray['smCode'],$this->allowShipType)){
                        $guanliFee  = sprintf('%.2f', $guanli['fee_value'] * $weight);
                        $cost       = sprintf('%.2f', $guanli['fee_amount'] * $weight);
                    }
                    if ($customerOtherFee[0]['status'] == '1') {
                        //客户杂费可用，则参与打折计算
                        $guanliFee  = $customerOtherFee[0]['discount'] * $guanliFee;
                        $discount   = $customerOtherFee[0]['discount'];
                    }
                } else {
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if('0' == $guanli['is_default_fee']){
                        $guanliFee  = 0;
                        $cost       = 0;
                    }
                }
            } else {
                //杂费状态：不可用
                $guanliFee  = 0;
                $cost       = 0;
            }

            $this->_dataArray['costArr']['otherFee']['guanli'] = array(
                'cost_currency_code'      => $guanli['cost_currency_code'],
                'currency_code' => $guanli['fee_currency_code'],
                'price'         => $guanliFee,
                'discount'      => $discount,
                'cost'          => $cost,
                'sp_code'       => $guanli['sp_code'],
                'fee_id'        => $guanli['fee_id']
            );
        }
    }
    private function getBhdpdremotefeeFee(){
        $BHDPDRemoteFee     = Service_OtherFee::getByField('BHDPDREMOTEFEE', 'fee_code');
        if(!empty($BHDPDRemoteFee)){
            if($BHDPDRemoteFee['status'] =="1"){

            }
            $this->_dataArray['costArr']['otherFee']['BHDPDRemoteFee'] = array(
                'cost_currency_code' => $BHDPDRemoteFee['cost_currency_code'],
                'currency_code' => $BHDPDRemoteFee['fee_currency_code'],
                'price'         => $BHDPDRemoteFee['fee_value'],
                'discount'      => $BHDPDRemoteFee['fee_discount'],
                'cost'          => $BHDPDRemoteFee['fee_value'],
                'sp_code'       => $BHDPDRemoteFee['sp_code'],
                'fee_id'        => $BHDPDRemoteFee['fee_id']
            );
        }
    }
     /**
     * @author kevin-wang
     * @todo 计算超值报关费
     */
    private function getCzbgfFee(){
        $otherfee = Service_OtherFee::getByField('CZBGF','fee_code');
        $return = array('currency_code'=>$otherfee['fee_currency_code'],'price'=>0,'fee_id'=>$otherfee['fee_id']);
        if($this->iszccq){
            return $return;
        }
        $chaozhiFee = 0;
        $cost = 0;
        $discount=1;
            if (! empty ( $otherfee )) {
                $customerFeeCondition = array (
                    'customer_code' => $this->_paramsArray ['orderInfo'] ['customer_code'],
                    'fee_id' => $otherfee ['fee_id']
                );
                $customerOtherFee = Service_CustomerOtherFee::getByCondition ( $customerFeeCondition, '*' );
                $sum=0;
                foreach ($this->_paramsArray['orderProducts'] as $key => $value) {
                    $total=$value['op_quantity']*$value['op_purpose_declared_value'];
                    $sum+=$total;
                }
                // 杂费状态：可用
                if ('1' == $otherfee ['status']) { 
                    
                    if('1' == $otherfee['is_default_fee']){
                        if($this->_paramsArray['orderInfo']['sm_code']=='HKDHL'&&$sum>120){
                            $chaozhiFee = $otherfee['fee_value'] ;
                            $cost = $otherfee ['fee_amount'];
                            if (!empty($customerOtherFee)) {
                                if ($customerOtherFee[0]['status'] == '1') {
                                $chaozhiFee = $customerOtherFee [0] ['discount'] * $chaozhiFee;
                                $discount = $customerOtherFee [0] ['discount']; 
                                }
                            }
                        }
                    }else{
                        if (!empty($customerOtherFee)) {
                            if($this->_paramsArray['orderInfo']['sm_code']=='HKDHL'&&$sum>120){
                            $chaozhiFee = $otherfee['fee_value'] ;
                            $cost = $otherfee ['fee_amount'];
                                if ($customerOtherFee[0]['status'] == '1') {
                                $chaozhiFee = $customerOtherFee [0] ['discount'] * $chaozhiFee;
                                $discount = $customerOtherFee [0] ['discount']; 
                                }
                            }
                        }
                        //非默认费用且该客户无此项杂费设置，则此项费用不收
                    }
                } else {
                    // 杂费状态：不可用
                    $chaozhiFee = 0;
                    $cost = 0;
                }
                $this->_dataArray ['costArr'] ['otherFee'] ['chaozhibaoguan'] = array (
                    'cost_currency_code'=>$otherfee['cost_currency_code'],
                    'currency_code' => $otherfee['fee_currency_code'],
                    'price' => $chaozhiFee,
                    'discount' => $discount,
                    'cost' => $cost,
                    'sp_code' => $otherfee['sp_code'],
                    'fee_id' => $otherfee['fee_id']
                );
            }

    }
    /* @author kevin-wang
     * @todo 空运费
     */
    /*private function getKyfFee(){
        if($this->iszccq){
            return;
        }
        $kongyunFee  = 0;
        $cost       = 0;
        $discount   = 1;    /* 客户折扣，1=100% */
        /*$kongyun     = Service_OtherFee::getByField('KYF', 'fee_code');
        $weight     = 0;
        if (!empty($this->_paramsArray['orderProducts'])) {
            foreach ($this->_paramsArray['orderProducts'] as $key => $value) {
                $product=Service_Product::getByField($value['product_id'],'product_id');
                $weight+=$product['product_weight'];
            }
        }
        $allowShip=array('PNLG','PNLN','PNLP');
        if (!empty($kongyun)) {
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
                'fee_id'        => $kongyun['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
            if('1' == $kongyun['status']){
                //杂费状态：可用
                if('1' == $kongyun['is_default_fee']){
                    if(in_array($this->_paramsArray['orderInfo']['sm_code'],$allowShip)){
                            $cost       = $kongyun['fee_amount'] * $weight;
                        }
                    if(!empty($customerOtherFee)) {
                        
                        if ($customerOtherFee[0]['status'] == '1') {
                            //客户杂费可用，则参与打折计算
                            $cost  = $customerOtherFee[0]['discount'] * $cost;
                            $discount   = $customerOtherFee[0]['discount'];
                        }
                    } 
                   
                }else{
                    if(!empty($customerOtherFee)) {
                        if(in_array($this->_paramsArray['orderInfo']['sm_code'],$allowShip)){
                            $cost       = $kongyun['fee_amount'] * $weight;
                        }
                        if ($customerOtherFee[0]['status'] == '1') {
                            //客户杂费可用，则参与打折计算
                            $cost  = $customerOtherFee[0]['discount'] * $cost;
                            $discount   = $customerOtherFee[0]['discount'];
                        }
                    } 
                }
            } else {
                //杂费状态：不可用
                $cost       = 0;
            }
            $this->_dataArray['costArr']['otherFee']['kongyun'] = array(
                'cost_currency_code'      => $kongyun['cost_currency_code'],
                'currency_code' => $kongyun['fee_currency_code'],
                'price'         => $kongyunFee,
                'discount'      => $discount,
                'cost'          => $cost,
                'sp_code'       => $kongyun['sp_code'],
                'fee_id'        => $kongyun['fee_id']
            );
        }
    }
    }*/
    /* @author kevin-wang
     * @todo 高风险附加费
     */
    public function getGfxFee(){
        if($this->iszccq){
            return;
        }
        $gfx    = Service_OtherFee::getByField('Elevated Risk', 'fee_code');
        $cost       = 0;  //费用
        $gfxFee     = 0;  //成本
        //高风险地区附加费
        //受限制地区附加费
       /* $cityArr1=array("中非共和国","科特迪瓦","刚果民主共和国","厄立特里亚","伊拉克","伊朗","北韩","利比亚","利比利亚","索马里","苏丹","叙利亚","也门");*/
        if (!empty($gfx)) {
            if('1' == $gfx['status']){
                //杂费状态：可用
                if ($this->_paramsArray['orderInfo']['sm_code'] == 'HKDHL'||$this->_paramsArray['orderInfo']['sm_code'] == 'BH-HKDHL') {
                    $allowCountry=array("阿富汗","布隆迪","伊拉克","利比亚","马里","尼日尔","南苏丹","叙利亚","也门");
                    $country=Service_Country::getByField($this->_paramsArray['countryId'],'country_id');
                    if (in_array($country['country_name'],$allowCountry)){
                        // 当月燃油费率
                        $shippingMethod = Service_ShippingMethod::getByField($this->_paramsArray['orderInfo']['sm_code'], 'sm_code');
                        $cost = $gfx['fee_value'] * (1 + $shippingMethod['sm_baf']);
                        $gfxFee = $gfx['fee_amount'] * (1 + $shippingMethod['sm_baf']);
                    }
                } else if ($this->_paramsArray['orderInfo']['sm_code'] == 'DHL-TH' ) {
                    $allowCountry=array('阿富汗','伊拉克','利比亚','叙利亚','也门');
                    $country=Service_Country::getByField($this->_paramsArray['countryId'],'country_id');
                    if (in_array($country['country_name'],$allowCountry)){
                        // 当月燃油费率
                        $shippingMethod = Service_ShippingMethod::getByField($this->_paramsArray['orderInfo']['sm_code'], 'sm_code');
                        $cost = $gfx['fee_value'] * (1 + $shippingMethod['sm_baf']);
                        $gfxFee = $gfx['fee_amount'] * (1 + $shippingMethod['sm_baf']);
                    }
                }
            } else {
                //杂费状态：不可用
                $cost       = 0;
                $gfxFee     = 0;
            }

            $this->_dataArray['costArr']['otherFee']['gfx'] = array(
                'cost_currency_code'      => $gfx['cost_currency_code'],
                'currency_code' => $gfx['fee_currency_code'],
                'price'         => $cost,
                'discount'      => 1,
                'cost'          => $gfxFee,
                'sp_code'       => $gfx['sp_code'],
                'fee_id'        => $gfx['fee_id']
            );
        }
    }
    /* @author kevin-wang
     * @todo 受限制附加费
     */
    public function getSxzFee(){
        if($this->iszccq){
            return;
        }
        $sxz    = Service_OtherFee::getByField('Restricted Destination', 'fee_code');
        $cost       = 0;  //费用
        $sxzFee     = 0;  //成本
        //受限制地区附加费
        if (!empty($sxz)) {
            if('1' == $sxz['status']){
                //杂费状态：可用
                if ($this->_paramsArray['orderInfo']['sm_code'] == 'HKDHL'||$this->_paramsArray['orderInfo']['sm_code'] == 'BH-HKDHL') {
                    $allowCountry=array("中非共和国","象牙海岸","刚果民主共和国","厄立特里亚","伊拉克","伊朗","朝鲜","利比亚","利比里亚","索马里","苏丹","叙利亚","也门");
                    $country=Service_Country::getByField($this->_paramsArray['countryId'],'country_id');
                    if (in_array($country['country_name'],$allowCountry)){
                        $cost = $sxz['fee_value'];
                        $sxzFee = $sxz['fee_amount'];
                    }
                } else if ($this->_paramsArray['orderInfo']['sm_code'] == 'DHL-TH') {
                    $allowCountry=array('伊朗','伊拉克','朝鲜','利比亚','叙利亚','也门');
                    $country=Service_Country::getByField($this->_paramsArray['countryId'],'country_id');
                    if (in_array($country['country_name'],$allowCountry)){
                        $cost = $sxz['fee_value'];
                        $sxzFee = $sxz['fee_amount'];
                    }
                }
            } else {
                //杂费状态：不可用
                $cost       = 0;
                $sxzFee     = 0;
            }

            $this->_dataArray['costArr']['otherFee']['sxz'] = array(
                'cost_currency_code'      => $sxz['cost_currency_code'],
                'currency_code' => $sxz['fee_currency_code'],
                'price'         => $cost,
                'discount'      => 1,
                'cost'          => $sxzFee,
                'sp_code'       => $sxz['sp_code'],
                'fee_id'        => $sxz['fee_id']
            );
        }
    }
    
    // POD服务费
    public function getPodFee() {
        $pod = Service_OtherFee::getByField('POD', 'fee_code');
        $cost = 0;  //成本
        $podFee = 0;  //费用
        $discount = 1;   /* 客户折扣，1=100% */
        if (!empty($pod)) {
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
                'fee_id' => $pod['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
            if ('1' == $pod['status']) {
                //杂费状态：可用
                if ($this->_paramsArray['orderInfo']['sm_code'] == '4PX-LYT_GH' && $this->_paramsArray['orderInfo']['is_pod'] == 1) {
                    $podFee = $pod['fee_value'];
                    $cost = $pod['fee_amount'];
                }
                if (!empty($customerOtherFee)) {
                    if ($customerOtherFee[0]['status'] == '1') {
                        //客户杂费可用，则参与打折计算
                        $podFee = $customerOtherFee[0]['discount'] * $podFee;
                        $discount = $customerOtherFee[0]['discount'];
                    }
                }else{
                     //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if('0' == $pod['is_default_fee']){
                        $podFee  = 0;
                        $cost       = 0;
                    }
                }
            }
            $this->_dataArray['costArr']['otherFee']['pod'] = array(
                'cost_currency_code' => $pod['cost_currency_code'],
                'currency_code' => $pod['fee_currency_code'],
                'price' => $podFee,
                'discount' => $discount,
                'cost' => $cost,
                'sp_code' => $pod['sp_code'],
                'fee_id' => $pod['fee_id']
            );
        }
    }
       /**
     * @author yao
     * @todo 计算英国税金
     */
    private function get4pxdutyFeee(){
        $taxFee  = 0;
        $cost       = 0;
        $discount   = 1;    /* 客户折扣，1=100% */
        $tax     = Service_OtherFee::getByField('4PX-DUTY', 'fee_code');
        if (!empty($tax)) {
                $smCode=$this->_paramsArray['orderInfo']['sm_code'];
                $orderAderss=Service_OrderAddressBook::getByField($this->_paramsArray['orderInfo']['order_code'],'order_code');
                //针对4PX-LYT_GH渠道和4PX-EU_PACKET渠道，发往英国的，其目的海关申报价值大于等于20美金的订单扣税费
            if(  $smCode=='4PX-LYT_GH'&& in_array($orderAderss['oab_country_id'],array('252','89'))
               ||$smCode=='4PX-EU_PACKET'){
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
                'fee_id'        => $tax['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
         
            if('1' == $tax['status']){
                //杂费状态：可用
                if($this->_paramsArray['orderProducts']){
                    $totalMony=0;
                    foreach($this->_paramsArray['orderProducts'] as $product){
                        $totalMony+=($product['op_purpose_declared_value']*$product['op_quantity']);
                    }
                    $totalMony=sprintf('%.2f',$totalMony);
                    if($totalMony>=20){
                        $taxFee=$totalMony*0.2;
                        $cost=$taxFee;
                        if(!empty($customerOtherFee)) {
                            if ($customerOtherFee[0]['status'] == '1') {
                                //客户杂费可用，则参与打折计算
                                $taxFee  = $customerOtherFee[0]['discount'] * $tax;
                                $discount   = $customerOtherFee[0]['discount'];
                            }
                        } else {
                            //非默认费用且该客户无此项杂费设置，则此项费用不收
                            if('0' == $guanli['is_default_fee']){
                                $taxFee  = 0;
                                $cost       = 0;
                            }
                        }
                    }  
                }
            }
            $this->_dataArray['costArr']['otherFee']['4pxduty'] = array(
                'currency_code' => $tax['fee_currency_code'],
                'price'         => $taxFee,
                'discount'      => $discount,
                'cost'          => $cost,
                'sp_code'       => $tax['sp_code'],
                'fee_id'        => $tax['fee_id']
            );
            }
        }
    }
    /*
     * @desc 4px高风险附加费 4PX-HKDHL
     */
    public function get4pxgfxdqFee(){
        if($this->iszccq){
            return;
        }
        $gfx    = Service_OtherFee::getByField('4PXGFXDQ', 'fee_code');
        $cost       = 0;  //成本
        $gfxFee     = 0;  //费用
        $discount   = 1;  //客户折扣，1=100%
        //高风险地区附加费
        $allowCountry=array("阿富汗","布隆迪","伊拉克","利比亚","马里","尼日尔","南苏丹","叙利亚","也门");
        $country=Service_Country::getByField($this->_paramsArray['countryId'],'country_id');
        if (!empty($gfx)) {
            // 费用状态可用 且地区为高风险地区 且渠道为4PX-HKDHL
            if($gfx['status'] == '1' && in_array($country['country_name'],$allowCountry) && $this->_paramsArray['orderInfo']['sm_code'] == '4PX-HKDHL'){
                // 计算当前渠道的全额费用
                // 当月燃油费率
                $shippingMethod = Service_ShippingMethod::getByField($this->_paramsArray['orderInfo']['sm_code'], 'sm_code');
                $gfxFee = $gfx['fee_value'] * (1 + $shippingMethod['sm_baf']);
                $cost = $gfx['fee_amount'] * (1 + $shippingMethod['sm_baf']);
                // 查找当前客户当前费用可用配置
                $customerFeeCondition = array(
                    'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
                    'fee_id'        => $gfx['fee_id'],
                    'status'        => 1,
                );
                $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
                // 是否是默认收费
                if ($gfx['is_default_fee'] == '1') {
                    // 默认收费 则查看当前渠道当前客户是否配置折扣 不存在条目则全额收费 存在按照相应折扣处理
                    if (isset($customerOtherFee[0]['discount']) && $customerOtherFee[0]['discount'] != 0) {
                        $gfxFee = $customerOtherFee[0]['discount'] * $gfxFee;
                        $discount = $customerOtherFee[0]['discount'];
                    }
                } else {
                    // 非默认收费 查看当前渠道当前客户是否配置折扣 不存在条目则不收费
                    if (empty($customerOtherFee)) {
                        $gfxFee  = 0;
                        $cost       = 0;
                    } else {
                        $gfxFee = $customerOtherFee[0]['discount'] * $gfxFee;
                        $discount = $customerOtherFee[0]['discount'];
                    }
                }
            } else {
                //杂费状态：不可用
                $cost       = 0;
                $gfxFee     = 0;
            }

            $this->_dataArray['costArr']['otherFee']['4pxgfxdq'] = array(
                'cost_currency_code'      => $gfx['cost_currency_code'],
                'currency_code' => $gfx['fee_currency_code'],
                'price'         => $gfxFee,
                'discount'      => $discount,
                'cost'          => $cost,
                'sp_code'       => $gfx['sp_code'],
                'fee_id'        => $gfx['fee_id']
            );
        }
    }

    /**
     * @author events
     * @todo 偏远地区附加费
     */
    private function get4pxpydqFee(){
        if($this->iszccq){
            return;
        }
        //是偏远的订单
        if($this->_paramsArray['orderInfo']['is_remote_city']=='1'){
            //偏远城市，计算偏远费
            $pydqfjf = Service_OtherFee::getByField ( "4PXPYDQ", "fee_code", "*" );
            //获取计费重
            $keys  = array(
                'warehouseId'               => $this->_paramsArray['warehouse_id'],
                'countryId'                 => $this->_paramsArray['countryId'],
                'smCode'                    => $this->_paramsArray['smCode'],
                'weight'                    => $this->_paramsArray['weight'],
                'order_code'                => $this->_paramsArray['order_code'],
                'realWeight'                => $this->_paramsArray['realWeight'],
                'customerCode'              => $this->_paramsArray['customerCode'],
            );
            $objCalculate   = new Common_CalculateShipping();
            $objCalculate->setParams($keys);
            $aCalculate = $objCalculate->getRate();
            if (! empty ( $pydqfjf )) {
                if($this->_paramsArray['orderInfo']['sm_code']=='4PX-HKDHL'){
                    $customerFeeCondition = array (
                        'customer_code' => $this->_paramsArray ['orderInfo'] ['customer_code'],
                        'fee_id' => $pydqfjf ['fee_id']
                    );
                    $customerOtherFee = Service_CustomerOtherFee::getByCondition ( $customerFeeCondition, '*' );
                    $smCode = $this->_paramsArray['smCode'];
                    $soFeeWeight    = $aCalculate['data']['cost']['fee_weight'];
                    $cost = 0;  //成本
                    $pydqfjfFee = 0;  //费用
                    $discount = 1;
                    if(!empty($smCode)){
                        $shippingMethod = Service_ShippingMethod::getByField($smCode,"sm_code");
                        if('CRE' == $shippingMethod['sm_class_code']){
                            //计费逻辑：RMB3.6/KG,费用=RMB3.6*订单计费重*(1+燃油附加费率)=A，判断A与RMB176的大小，若小于，则偏远地区附加费为RMB176,否则偏远地区附加费为A。成本与费用计算逻辑一样。
                            $pydqfjfFee = $pydqfjf ['fee_value']*$soFeeWeight*(1+$shippingMethod['sm_baf'])>176 ? $pydqfjf ['fee_value']*$soFeeWeight*(1+$shippingMethod['sm_baf']) : 176;
                        }
                    }
                    $cost=$pydqfjf ['fee_amount']*$soFeeWeight*(1+$shippingMethod['sm_baf'])>178 ? $pydqfjf ['fee_amount']*$soFeeWeight*(1+$shippingMethod['sm_baf']) : 178;
                    if ('1' == $pydqfjf ['status']) {
                        // 杂费状态：可用
                        if (! empty ( $customerOtherFee )) {
                            if ($customerOtherFee [0] ['status'] == '1') {
                                // 客户杂费可用，则参与打折计算
                                $pydqfjfFee = $customerOtherFee [0] ['discount'] * $pydqfjfFee;
                                $discount = $customerOtherFee [0] ['discount'];
                            }
                        } else {
                            // 非默认费用且该客户无此项杂费设置，则此项费用不收
                            if ('0' == $pydqfjf ['is_default_fee']) {
                                $pydqfjfFee = 0;
                                $cost = 0;
                            }
                        }
                    } else {
                        // 杂费状态：不可用
                        $pydqfjfFee = 0;
                        $cost = 0;
                    }
                    // echo $pydqfjfFee;exit;
                    $this->_dataArray ['costArr'] ['otherFee'] ['4pxpydq'] = array (
                        'cost_currency_code' => $pydqfjf ['cost_currency_code'],
                        'currency_code' => $pydqfjf ['fee_currency_code'],
                        'price' => $pydqfjfFee,
                        'discount' => $discount,
                        'cost' => $cost,
                        'sp_code' => $pydqfjf ['sp_code'],
                        'fee_id' => $pydqfjf ['fee_id']
                    );
                }
            }
        }
    }

    /**
     * @author events
     * @todo 限运目的地附加费
     */
    public function get4pxxymddFee(){
        if($this->iszccq){
            return;
        }
        $xymdfjf    = Service_OtherFee::getByField('4PXXYMDD', 'fee_code');
        $cost       = 0;  //费用
        $xymdfjfFee     = 0;  //成本
        //限运目的地
        $allowCountry=array("中非共和国","科特迪瓦","刚果民主共和国","厄立特里亚","伊朗","伊拉克","朝鲜","利比里亚","利比亚","索马里","苏丹","叙利亚","也门");
        if (!empty($xymdfjf)) {
            if('1' == $xymdfjf['status']){
                //杂费状态：可用
                if ($this->_paramsArray['orderInfo']['sm_code'] == '4PX-HKDHL') {
                    $country=Service_Country::getByField($this->_paramsArray['countryId'],'country_id');
                    //费用的金额为：限运目的地附加费（杂费里维护的费用）*（1+当月燃油费率），成本为：限运目的地附加费（成本）*（1+当月燃油费率）。
                    if (in_array($country['country_name'],$allowCountry)){
                        $smCode = $this->_paramsArray['smCode'];
                        $shippingMethod = Service_ShippingMethod::getByField($smCode,"sm_code");
                        $cost = $xymdfjf['fee_value']*(1+$shippingMethod['sm_baf']);
                        $xymdfjfFee = $xymdfjf['fee_amount']*(1+$shippingMethod['sm_baf']);
                    }
                }    
            } else {
                //杂费状态：不可用
                $cost       = 0;
                $xymdfjfFee     = 0;
            }

            $this->_dataArray['costArr']['otherFee']['4pxxymdd'] = array(
                'cost_currency_code'      => $xymdfjf['cost_currency_code'],
                'currency_code' => $xymdfjf['fee_currency_code'],
                'price'         => $cost,
                'discount'      => 1,
                'cost'          => $xymdfjfFee,
                'sp_code'       => $xymdfjf['sp_code'],
                'fee_id'        => $xymdfjf['fee_id']
            );
        }
    }

    /**
     * [get4pxddbgFee 单独报关费]
     * @return [type] [description]
     */
    private function get4pxddbgFee(){
        if($this->iszccq){
            return;
        }
        $sdData = Service_OtherFee::getByField('4PXDDBG', 'fee_code');
        if(empty($sdData)){
            return;
        }
        $customerFeeCondition = array(
            'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
            'fee_id'        => $sdData['fee_id']
        );
        $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
        $feeValue = $sdCost = 0;  //费用//成本
        if (!empty($sdData)) {
            $country = Service_Country::getByField($this->_paramsArray['countryId'], 'country_id');
            // 杂费状态：可用
            if('1' == $sdData['status']){
                //订单的收件人国家为哈萨克斯坦 - 运输代码为4PX-HKDHL, 收取该费用
                if (strtoupper($this->_paramsArray['orderInfo']['sm_code']) == '4PX-HKDHL' && strtoupper($country['country_code']) == 'KZ') {
                    //配置折扣
                    if ($customerOtherFee[0]['status'] == '1') {
                        $feeValue = $customerOtherFee[0]['discount'] * $sdData['fee_value'];    
                    }else {
                        $feeValue = $sdData['fee_value'];
                    }
                    //成本
                    $sdCost = $sdData['fee_amount'];
                }
            }
            $this->_dataArray['costArr']['otherFee']['4pxddbg'] = array(
                'cost_currency_code' => $sdData['cost_currency_code'],
                'currency_code' => $sdData['fee_currency_code'],
                'price'         => $feeValue,
                'discount'      => 1,
                'cost'          => $sdCost,
                'sp_code'       => $sdData['sp_code'],
                'fee_id'        => $sdData['fee_id']
            );
        }
    }

    /**
     * [get4pxccczFee 超长超重费]
     * @return [type] [description]
     */
    private function get4pxccczFee(){
        if($this->iszccq){
            return;
        }
        $ccczfee =$cost = $sum = 0;
        $otherfee = Service_OtherFee::getByField('4PXCCCZ', 'fee_code');
        if (empty($otherfee)) {
            return;
        }
        $customerFeeCondition = array(
            'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
            'fee_id'        => $otherfee['fee_id']
        );
        $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
        //配置生效
        if('1' == $otherfee['status']){
            if(strtoupper($this->_paramsArray['orderInfo']['sm_code']) == '4PX-HKDHL'){
                $order_code = $this->_paramsArray['orderInfo']['order_code'];
                $shippingMethod = Service_ShippingMethod::getByField('4PX-HKDHL', 'sm_code', array('sm_baf'));
                $shipOrderD = Service_ShipOrderDetail::getByCondition(array('order_code'=>$order_code),'*');
                foreach ($shipOrderD as $shipOrderDetail) {
                    if ((int)$shipOrderDetail['sod_length']>=120||(int)$shipOrderDetail['sod_width']>=120||(int)$shipOrderDetail['sod_height']>=120){
                        $sum += 1;
                    }
                }
                if ( $sum > 0 ){
                    if (!empty($customerOtherFee) && $customerOtherFee[0]['status'] == '1') {
                        $ccczfee = $customerOtherFee[0]['discount'] * $otherfee['fee_value'];
                        $ccczfee = $ccczfee * ( 1 + $shippingMethod['sm_baf']) * $sum;
                        $cost = $otherfee['fee_amount'] * ( 1 + $shippingMethod['sm_baf']) * $sum;
                    }else {
                        $ccczfee = $otherfee['fee_value'] * ( 1 + $shippingMethod['sm_baf']) * $sum;
                        $cost = $otherfee['fee_amount'] * ( 1 + $shippingMethod['sm_baf']) * $sum;
                        //非默认费用且该客户无此项杂费设置，则此项费用不收
                        if($otherfee['is_default_fee'] == 0){
                            $ccczfee = 0;
                            $cost = 0;
                        }
                    }
                }
            }
        }
        $this->_dataArray['costArr']['otherFee']['4pxcccz'] = array(
            'cost_currency_code'  => $otherfee['cost_currency_code'],
            'currency_code' => $otherfee['fee_currency_code'],
            'price'         => $ccczfee,
            'discount'      => 0,
            'cost'          => $cost,
            'sp_code'       => $otherfee['sp_code'],
            'fee_id'        => $otherfee['fee_id']
        );
    }

    /**
     * [getSanzuFee 散租费]
     * @return [type] [description]
     */
    private function getSanzuFee(){
        $sanzuFee  = 0;
        $cost = 0;
        //客户折扣 1=100% 
        $discount = 1;   
        $sanzuRow = Service_OtherFee::getByField('SANZU', 'fee_code');
        if (!empty($sanzuRow) && array_key_exists('status', $sanzuRow) && $sanzuRow['status'] == '1') {
            $trueWeight = 0;
            if (isset($this->_paramsArray['receiving_weight']) && $this->_paramsArray['receiving_weight'] > 0) {
                $trueWeight = $this->_paramsArray['receiving_weight'];
            } else {
                $receivingRow   = $this->_paramsArray['receingInfo'];
                //集货
                if ($receivingRow['receive_model_type'] == 1) {
                    $trueWeight = Service_ReceivingOrderDetail::sumNetWeight($this->_paramsArray['receiving_code']);
                //备货
                }/*else {
                    $trueWeight = Service_ReceivingDetail::sumNetWeight($this->_paramsArray['receiving_code']);
                }*/
            }
            if($trueWeight > 0){
                //录入的重量来计费，RMB0.5 /KG。
                $sanzuFee = $trueWeight * $sanzuRow['fee_value'];
                $cost = $trueWeight * $sanzuRow['fee_amount'];
                $customerFeeCondition = array(
                    'customer_code' => $this->_paramsArray['receingInfo']['customer_code'],
                    'fee_id'        => $sanzuRow['fee_id']
                );
                $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
                //客户杂费可用，则参与打折计算
                if(!empty($customerOtherFee) && $customerOtherFee[0]['status'] == '1') {
                    $sanzuFee = $customerOtherFee[0]['discount'] * $sanzuFee;
                    $discount = $customerOtherFee[0]['discount'];
                }else {
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if($sanzuRow['is_default_fee'] == 0){
                        $sanzuFee = 0;
                        $cost = 0;
                    }
                }
            }
        }
        $this->_dataArray['costArr']['otherFee']['sanzu'] = array(
            'currency_code' => $sanzuRow['fee_currency_code'],
            'price'         => $sanzuFee,
            'discount'      => $discount,
            'cost'          => $cost,
            'sp_code'       => $sanzuRow['sp_code'],
            'fee_id'        => $sanzuRow['fee_id']
        );
    }

    /**
     * [getDabaoFee 易货单质检打包费]
     * @return [type] [description]
     */
    private function getDbfFee(){
        $cost = $dabaoFee = 0;
        //客户折扣 1=100% 
        $discount = 1;   
        $dabaoFeeRow = Service_OtherFee::getByField('DBF', 'fee_code');
        if (!empty($dabaoFeeRow) && array_key_exists('status', $dabaoFeeRow) && $dabaoFeeRow['status'] == '1') {
            //打包为是收取费用 is_package
            if( isset($this->_paramsArray['sodRow']) && !empty($this->_paramsArray['sodRow']) && isset($this->_paramsArray['sodRow']['is_package']) && $this->_paramsArray['sodRow']['is_package'] == 1 ){
            //if( isset($this->_paramsArray['sodRow']) && !empty($this->_paramsArray['sodRow']) ){
                $sodRow = $this->_paramsArray['sodRow'];
                $soRow = Service_SwapOrder::getByField($sodRow['swo_id'], 'swo_id', array('customer_code'));
                $dabaoFee = $sodRow['quantity'] * $dabaoFeeRow['fee_value'];
                $customerFeeCondition = array(
                    'customer_code' => $soRow['customer_code'],
                    'fee_id'        => $dabaoFeeRow['fee_id']
                );
                $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
                //客户杂费可用，则参与打折计算
                if(!empty($customerOtherFee) && $customerOtherFee[0]['status'] == '1') {
                    $dabaoFee = $customerOtherFee[0]['discount'] * $dabaoFee;
                    $discount = $customerOtherFee[0]['discount'];
                }else {
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if($dabaoFeeRow['is_default_fee'] == 0){
                        $dabaoFee = 0;
                        $cost = 0;
                    }
                }
            }
        }
        $this->_dataArray['costArr']['otherFee']['dbf'] = array(
            'currency_code' => $dabaoFeeRow['fee_currency_code'],
            'price'         => $dabaoFee,
            'discount'      => $discount,
            'cost'          => $cost,
            'sp_code'       => $dabaoFeeRow['sp_code'],
            'fee_id'        => $dabaoFeeRow['fee_id']
        );
    }

    /**
     * [setQualityParams 易货单]
     */
    public function setQualityParams($sodRow){
        $this->_paramsArray['sodRow'] = $sodRow;
    }

    /**
     * [setQcParams 卡位费]
     * @param [type] $wcRow [卡位数组]
     */
    public function setQcParams($wcRow){
        $this->_paramsArray['wcRow'] = $wcRow;
    }
    
    public function setDsParams($dsRow){
        $this->_paramsArray['dsRow'] = $dsRow;
    }
    
    public function setAtParams($atRow){
        $this->_paramsArray['atRow'] = $atRow;
    }
    
    public function setCoParams($coRow){
        $this->_paramsArray['coRow'] = $coRow;
    }

    /**
     * [getQckwf01Fee QC卡位费1]
     * @return [type] [description]
     */
    private function getQckwf01Fee(){
        $feeCode = 'QCKWF-01';
        $cost = $qckwFee = 0;
        //客户折扣 1=100% 
        $discount = 1;   
        $qckwfFeeRow = Service_OtherFee::getByField($feeCode, 'fee_code');
        //费用状态可用 
        if (!empty($qckwfFeeRow) && array_key_exists('status', $qckwfFeeRow) && $qckwfFeeRow['status'] == '1' && isset($this->_paramsArray['wcRow']) && !empty($this->_paramsArray['wcRow'])) {
            $wcdRow = $this->_paramsArray['wcRow'];
            if(strtolower($wcmRow['wcm_warehouse_code']) == 'all'){
                $warehouseData['warehouse_id'] = 0;
            }else {
                $warehouseData = Service_Warehouse::getByField($wcdRow['wcd_warehouse_code'], 'warehouse_code', array('warehouse_id'));
            }
            //仓库一致收费 1、 配置为全部仓库 2、 卡位维护为全部仓库 3、配置仓库相同
            if($qckwfFeeRow['warehouse_id'] == 0 || $warehouseData['warehouse_id'] == 0 || $qckwfFeeRow['warehouse_id'] == $warehouseData['warehouse_id']){
                $qckwFee = $wcdRow['wcd_card_day_num'] * $qckwfFeeRow['fee_value'];
                $cost = $wcdRow['wcd_card_day_num'] * $qckwfFeeRow['fee_amount'];
                $customerFeeCondition = array(
                    'customer_code' => $wcdRow['wcd_customer_code'],
                    'fee_id'        => $qckwfFeeRow['fee_id']
                );
                $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
                //客户杂费可用，则参与打折计算
                if(!empty($customerOtherFee) && $customerOtherFee[0]['status'] == '1') {
                    $qckwFee = $customerOtherFee[0]['discount'] * $qckwFee;
                    $discount = $customerOtherFee[0]['discount'];
                }else {
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if($qckwfFeeRow['is_default_fee'] == 0){
                        $qckwFee = 0;
                        $cost = 0;
                    }
                }
            }
        }
        $this->_dataArray['costArr']['otherFee'][strtolower($feeCode)] = array(
            'currency_code' => $qckwfFeeRow['fee_currency_code'],
            'price'         => $qckwFee,
            'discount'      => $discount,
            'cost'          => $cost,
            'sp_code'       => $qckwfFeeRow['sp_code'],
            'fee_id'        => $qckwfFeeRow['fee_id']
        );
    }

    /**
     * [getQckwf2Fee QC卡位费2]
     * @return [type] [description]
     */
    private function getQckwf02Fee(){
        $feeCode = 'QCKWF-02';
        $cost = $qckwFee = 0;
        //客户折扣 1=100% 
        $discount = 1;   
        $qckwfFeeRow = Service_OtherFee::getByField($feeCode, 'fee_code');
        //费用状态可用
        if (!empty($qckwfFeeRow) && array_key_exists('status', $qckwfFeeRow) && $qckwfFeeRow['status'] == '1' && isset($this->_paramsArray['wcRow']) && !empty($this->_paramsArray['wcRow'])) {
            $wcmRow = $this->_paramsArray['wcRow'];
            if(strtolower($wcmRow['wcm_warehouse_code']) == 'all'){
                $warehouseData['warehouse_id'] = 0;
            }else {
                $warehouseData = Service_Warehouse::getByField($wcmRow['wcm_warehouse_code'], 'warehouse_code', array('warehouse_id'));
            }
            //仓库一致收费 1、 配置为全部仓库 2、 卡位维护为全部仓库 3、配置仓库相同
            if($qckwfFeeRow['warehouse_id'] == 0 || $warehouseData['warehouse_id'] == 0 || $qckwfFeeRow['warehouse_id'] == $warehouseData['warehouse_id']){
                $qckwFee = $wcmRow['wcm_card_month_num'] * $qckwfFeeRow['fee_value'];
                $cost = $wcmRow['wcm_card_month_num'] * $qckwfFeeRow['fee_amount'];
                //日期计算费率
                list($year, $month, $day) = explode('-', $wcmRow['wcm_card_month_time']);
                if(intval($month) == intval(date('m'))){
                    //$days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
                    $days = date("t", strtotime("$year-$month"));
                    $monthDiscount = round((( $days - $day + 1) / $days), 4);
                    $qckwFee = round(($qckwFee * $monthDiscount), 4);
                }
                $customerFeeCondition = array(
                    'customer_code' => $wcmRow['wcm_customer_code'],
                    'fee_id'        => $qckwfFeeRow['fee_id']
                );
                $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
                //客户杂费可用，则参与打折计算
                if(!empty($customerOtherFee) && $customerOtherFee[0]['status'] == '1') {
                    $qckwFee = $customerOtherFee[0]['discount'] * $qckwFee;
                    $discount = $customerOtherFee[0]['discount'];
                }else {
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if($qckwfFeeRow['is_default_fee'] == 0){
                        $qckwFee = 0;
                        $cost = 0;
                    }
                }
            }
        }
        $this->_dataArray['costArr']['otherFee'][strtolower($feeCode)] = array(
            'currency_code' => $qckwfFeeRow['fee_currency_code'],
            'price'         => $qckwFee,
            'discount'      => $discount,
            'cost'          => $cost,
            'sp_code'       => $qckwfFeeRow['sp_code'],
            'fee_id'        => $qckwfFeeRow['fee_id']
        );
    }

    private function getVatFee(){
        if($this->iszccq){
            return;
        }
        $cost = 0;
        $discount = 1; /* 客户折扣，1=100% */
        $VAT = Service_OtherFee::getByField("VAT","fee_code","*");
        $op_purpose_declared_value = 0;
        foreach($this->_paramsArray['orderProducts'] as $key=>$op){
            $op_purpose_declared_value += $op['op_quantity']*$op['op_purpose_declared_value'];
        }
        if($op_purpose_declared_value>18.44&&$op_purpose_declared_value<165){
            if(in_array($this->_paramsArray['orderInfo']['sm_code'],array('BH-3HPA','BH-3H','BH-UKECSLTYD','BH-UKECSLTRM','BH-CORREOS','BH-19EURDPDDE','BH-DAC','BH-SL018','BH-IESLTANPOST'))){
                $vatFee = $op_purpose_declared_value*1.1*0.25;
                $cost = $vatFee;
            }else{
                $vatFee = 0;
                $cost = 0;
            }
        }else{
            $vatFee = 0;
            $cost = 0;
        }
        $this->_dataArray ['costArr'] ['otherFee'] ['vat'] = array (
            'cost_currency_code' => $VAT ['cost_currency_code'],
            'currency_code' => $VAT ['fee_currency_code'],
            'price' => $vatFee,
            'discount' => $discount,
            'cost' => $cost,
            'sp_code' => $VAT ['sp_code'],
            'fee_id' => $VAT ['fee_id']
        );
    }
    //哲盟关税预付金
    private function getThfbataxFee()
    {
        $otherfee = Service_OtherFee::getByField('THFBATAX', 'fee_code');
        $return = array('currency_code' => $otherfee['fee_currency_code'], 'price' => 0, 'fee_id' => $otherfee['fee_id']);
        if ($this->iszccq) {
            return $return;
        }

        $fee_id = 0;
        $cost = 0;
        $discount = 1; /* 客户折扣，1=100% */
        if (empty($otherfee) || $this->_paramsArray['orderInfo']['sm_code'] != 'DHL-TH' || $this->_paramsArray['orderInfo']['is_fba_tax'] != 1 ) {
            return;
        }

        $price = $otherfee['fee_value'];
        $cost = $otherfee['fee_amount'];
        $customerFeeCondition = array(
            'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
            'fee_id' => $otherfee['fee_id'],
        );
        $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
        if ('1' == $otherfee['status']) {
            //杂费状态：可用
            if (!empty($customerOtherFee)) {
                if ($customerOtherFee[0]['status'] == '1') {
                    //客户杂费可用，则参与打折计算
                    $price = $customerOtherFee[0]['discount'] * $price;
                    $discount = $customerOtherFee[0]['discount'];
                } else {
                    $fbataxfee = 0;
                }
            } else {
                //非默认费用且该客户无此项杂费设置，则此项费用不收
                if ('0' == $otherfee['is_default_fee']) {
                    $price = 0;
                    $cost = 0;
                }
            }
        } else {
            //杂费状态：不可用
            $price = 0;
            $cost = 0;
        }
        $fbataxfee = sprintf('%.2f', $price);
        $this->_dataArray['costArr']['otherFee']['thfbatax'] = array(
            'currency_code' => $otherfee['fee_currency_code'],
            'price' => $price,
            'fee_id' => $otherfee['fee_id'],
            'discount' => $discount,
            'cost' => $cost,
            'cost_currency_code' => $otherfee['cost_currency_code'],
            'sp_code' => $otherfee['sp_code'],
        );
    }
    //哲盟偏远费
    private function getThremoteFee()
    {
        $otherfee = Service_OtherFee::getByField('THPIANYUAN', 'fee_code');
        $return = array('currency_code' => $otherfee['fee_currency_code'], 'price' => 0, 'fee_id' => $otherfee['fee_id']);
        if ($this->iszccq) {
            return $return;
        }

        $fee_id = 0;
        $cost = 0;
        $discount = 1; /* 客户折扣，1=100% */
        if (empty($otherfee) || $this->_paramsArray['orderInfo']['sm_code'] != 'DHL-TH' || $this->_paramsArray['orderInfo']['is_remote_city'] != 1) {
            return;
        }

        $shipMethod = Service_ShippingMethod::getByField( $this->_paramsArray['orderInfo']['sm_code'], 'sm_code' );
        $smBaf = $shipMethod ? $shipMethod['sm_baf'] : 0 ;

        $price = $otherfee['fee_value'] * ( 1 + $smBaf ); //费用金额*（1+燃油费率）/ 票
        $cost  = $otherfee['fee_amount'] * ( 1 + $smBaf );//成本金额*（1+燃油费率）/票

        $customerFeeCondition = array(
            'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
            'fee_id' => $otherfee['fee_id'],
        );
        $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
        if ('1' == $otherfee['status']) {
            //杂费状态：可用
            if (!empty($customerOtherFee)) {
                if ($customerOtherFee[0]['status'] == '1') {
                    //客户杂费可用，则参与打折计算
                    $price = $customerOtherFee[0]['discount'] * $price;
                    $discount = $customerOtherFee[0]['discount'];
                } else {
                    $price = 0;
                }
            } else {
                //非默认费用且该客户无此项杂费设置，则此项费用不收
                if ('0' == $otherfee['is_default_fee']) {
                    $price = 0;
                    $cost = 0;
                }
            }
        } else {
            //杂费状态：不可用
            $price = 0;
            $cost = 0;
        }
        $price = sprintf('%.2f', $price);
        $this->_dataArray['costArr']['otherFee']['thremote'] = array(
            'currency_code' => $otherfee['fee_currency_code'],
            'price' => $price,
            'fee_id' => $otherfee['fee_id'],
            'discount' => $discount,
            'cost' => $cost,
            'cost_currency_code' => $otherfee['cost_currency_code'],
            'sp_code' => $otherfee['sp_code'],
        );
    }

/**
     * @todo 获得派送通知费用
     * @author by Felix
     */
    private function getDispatchnoticeFee() {
        $dispatchNotice = Service_OtherFee::getByField('PAISONG', 'fee_code');
        $cost = 0;  //成本
        $dispatchNoticeFee = 0;  //费用
        $discount = 1;   /* 客户折扣，1=100% */
        if (!empty($dispatchNotice)) {
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
                'fee_id' => $dispatchNotice['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
            if ('1' == $dispatchNotice['status']) {
                //杂费状态：可用
                if ($this->_paramsArray['orderInfo']['dispatch_notice'] == 1) {
                    $dispatchNoticeFee = $dispatchNotice['fee_value'];
                    $cost = $dispatchNotice['fee_amount'];
                }
                if (!empty($customerOtherFee)) {
                    if ($customerOtherFee[0]['status'] == '1') {
                        //客户杂费可用，则参与打折计算
                        $dispatchNoticeFee = $customerOtherFee[0]['discount'] * $dispatchNoticeFee;
                        $discount = $customerOtherFee[0]['discount'];
                    }
                }else{
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if('0' == $dispatchNotice['is_default_fee']){
                        $dispatchNoticeFee  = 0;
                        $cost       = 0;
                    }
                }
            }
            $this->_dataArray['costArr']['otherFee']['dispatchnotice'] = array(
                'cost_currency_code' => $pod['cost_currency_code'],
                'currency_code' => $dispatchNotice['fee_currency_code'],
                'price' => $dispatchNoticeFee,
                'discount' => $discount,
                'cost' => $cost,
                'sp_code' => $dispatchNotice['sp_code'],
                'fee_id' => $dispatchNotice['fee_id']
            );
        }
    }
    
    /**
     * @todo 获得保障费用
     * @author by Felix
     */
    private function getGuaranteeFee() {
        $guarantee = Service_OtherFee::getByField('BAOZHANG', 'fee_code');
        $cost = 0;  //成本
        $guaranteeFee = 0;  //费用
        $discount = 1;   /* 客户折扣，1=100% */
        if (!empty($guarantee)) {
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
                'fee_id' => $guarantee['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
            if ('1' == $guarantee['status']) {
                //杂费状态：可用
                if ($this->_paramsArray['orderInfo']['guarantee'] == 1) {
                    $guaranteeFee = $guarantee['fee_value'];
                    $cost = $guarantee['fee_amount'];
                }
                if (!empty($customerOtherFee)) {
                    if ($customerOtherFee[0]['status'] == '1') {
                        //客户杂费可用，则参与打折计算
                        $guaranteeFee = $customerOtherFee[0]['discount'] * $guaranteeFee;
                        $discount = $customerOtherFee[0]['discount'];
                    }
                }else{
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if('0' == $guarantee['is_default_fee']){
                        $guaranteeFee  = 0;
                        $cost       = 0;
                    }
                }
            }
            $this->_dataArray['costArr']['otherFee']['guarantee'] = array(
                'cost_currency_code' => $guarantee['cost_currency_code'],
                'currency_code' => $guarantee['fee_currency_code'],
                'price' => $guaranteeFee,
                'discount' => $discount,
                'cost' => $cost,
                'sp_code' => $guarantee['sp_code'],
                'fee_id' => $guarantee['fee_id']
            );
        }
    }
	
	/**
     * @todo 根据对应配置客户点数分货费，获得相应重量的费用
     * @author by Felix
     */
    private function getDsfhfFee() {
        $dsfhFeeRow = Service_OtherFee::getByField('DSFHF', 'fee_code');
        $cost = 0;  //成本
        $dsfhFee = 0;  //费用
        $discount = 1;   /* 客户折扣，1=100% */
        if (!empty($dsfhFeeRow)) {
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['dsRow']['customer_code'],
                'fee_id' => $dsfhFeeRow['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
            if ('1' == $dsfhFeeRow['status']) {
                //杂费状态：可用
                $dsfhFee = $dsfhFeeRow['fee_value'];
                $cost = $dsfhFeeRow['fee_amount'];
                if (!empty($customerOtherFee)) {
                    if ($customerOtherFee[0]['status'] == '1') {
                        //客户杂费可用，则参与打折计算
                        $dsfhFee = $customerOtherFee[0]['discount'] * $dsfhFee;
                        $discount = $customerOtherFee[0]['discount'];
                    }
                }else{
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if('0' == $dsfhFeeRow['is_default_fee']){
                        $dsfhFee  = 0;
                        $cost     = 0;
                    }
                }
            }
            //对应重量费用
            $dsfhFee = $dsfhFee * $this->_paramsArray['dsRow']['weight'];
            $cost    = $cost    * $this->_paramsArray['dsRow']['weight'];
            
            $this->_dataArray['costArr']['otherFee']['dsfhf'] = array(
                'cost_currency_code' => $dsfhFeeRow['cost_currency_code'],
                'currency_code' => $dsfhFeeRow['fee_currency_code'],
                'price' => $dsfhFee,
                'discount' => $discount,
                'cost' => $cost,
                'sp_code' => $dsfhFeeRow['sp_code'],
                'fee_id'  => $dsfhFeeRow['fee_id'],
                'fee_name'=> $dsfhFeeRow['fee_name']
            );
        }
    }
    
    /**
     * @todo 获得过夜停车费用
     * @author by Felix
     */
    private function getOvernightparkingFee() {
        $overnightparking = Service_OtherFee::getByField('GYTCF', 'fee_code');
        $cost = 0;  //成本
        $overnightparkingFee = 0;  //费用
        $discount = 1;   /* 客户折扣，1=100% */
        if (!empty($overnightparking)) {
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['atRow']['customer_code'],
                'fee_id' => $overnightparking['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
            if ('1' == $overnightparking['status']) {
                //杂费状态：可用
                $overnightparkingFee = $overnightparking['fee_value'];
                $cost = $overnightparking['fee_amount'];
                if (!empty($customerOtherFee)) {
                    if ($customerOtherFee[0]['status'] == '1') {
                        //客户杂费可用，则参与打折计算
                        $overnightparkingFee = $customerOtherFee[0]['discount'] * $overnightparkingFee;
                        $discount = $customerOtherFee[0]['discount'];
                    }
                }else{
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if('0' == $overnightparking['is_default_fee']){
                        $overnightparkingFee  = 0;
                        $cost       = 0;
                    }
                }
            }
            $this->_dataArray['costArr']['otherFee']['overnightparking'] = array(
                'cost_currency_code' => $overnightparking['cost_currency_code'],
                'currency_code' => $overnightparking['fee_currency_code'],
                'price' => $overnightparkingFee,
                'discount' => $discount,
                'cost' => $cost,
                'sp_code' => $overnightparking['sp_code'],
                'fee_id' => $overnightparking['fee_id']
            );
        }
    }
    
    /**
     * @todo 获得海关库内查验费1费用
     * @author by Felix
     */
    private function getKncyf01Fee() {
        $kncyFeeRow = Service_OtherFee::getByField('KNCYF-01', 'fee_code');
        $cost       = 0;  //成本
        $kncyFee    = 0;  //费用
        $discount   = 1;  /* 客户折扣，1=100% */
        if (!empty($kncyFeeRow)) {
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['atRow']['customer_code'],
                'fee_id'        => $kncyFeeRow['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
            if ('1' == $kncyFeeRow['status']) {
                //杂费状态：可用
                $kncyFee = $kncyFeeRow['fee_value'];
                $cost    = $kncyFeeRow['fee_amount'];
                if (!empty($customerOtherFee)) {
                    if ($customerOtherFee[0]['status'] == '1') {
                        //客户杂费可用，则参与打折计算
                        //设置了客户特殊报价，改成按特殊报价计算
                        $kncyFee  = $customerOtherFee[0]['discount'] * (!empty($customerOtherFee[0]['fee_value']) ? $customerOtherFee[0]['fee_value'] : $kncyFee);
                        $discount = $customerOtherFee[0]['discount'];
                    }
                }else{
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if('0' == $kncyFeeRow['is_default_fee']){
                        $kncyFee    = 0;
                        $cost       = 0;
                    }
                }
            }
            $this->_dataArray['costArr']['otherFee'][strtolower($kncyFeeRow['fee_code'])] = array(
                'cost_currency_code' => $kncyFeeRow['cost_currency_code'],
                'currency_code'      => $kncyFeeRow['fee_currency_code'],
                'price'              => $kncyFee,
                'discount'           => $discount,
                'cost'               => $cost,
                'sp_code'            => $kncyFeeRow['sp_code'],
                'fee_id'             => $kncyFeeRow['fee_id']
            );
        }
    }
    
    /**
     * @todo 获得海关库内查验费2费用
     * @author by Felix
     */
    private function getKncyf02Fee() {
        $kncyFeeRow = Service_OtherFee::getByField('KNCYF-02', 'fee_code');
        $cost     = 0;  //成本
        $kncyFee  = 0;  //费用
        $discount = 1;  /* 客户折扣，1=100% */
        if (!empty($kncyFeeRow)) {
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['atRow']['customer_code'],
                'fee_id'        => $kncyFeeRow['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
            if ('1' == $kncyFeeRow['status']) {
                //杂费状态：可用
                $kncyFee = $kncyFeeRow['fee_value'];
                $cost = $kncyFeeRow['fee_amount'];
                if (!empty($customerOtherFee)) {
                    if ($customerOtherFee[0]['status'] == '1') {
                        //客户杂费可用，则参与打折计算
 						//设置了客户特殊报价，改成按特殊报价计算
                        $kncyFee  = $customerOtherFee[0]['discount'] * (!empty($customerOtherFee[0]['fee_value']) ? $customerOtherFee[0]['fee_value'] : $kncyFee);
                        $discount = $customerOtherFee[0]['discount'];
                    }
                }else{
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if('0' == $kncyFeeRow['is_default_fee']){
                        $kncyFee  = 0;
                        $cost     = 0;
                    }
                }
            }
            $this->_dataArray['costArr']['otherFee'][strtolower($kncyFeeRow['fee_code'])] = array(
                'cost_currency_code' => $kncyFeeRow['cost_currency_code'],
                'currency_code'      => $kncyFeeRow['fee_currency_code'],
                'price'              => $kncyFee,
                'discount'           => $discount,
                'cost'               => $cost,
                'sp_code'            => $kncyFeeRow['sp_code'],
                'fee_id'             => $kncyFeeRow['fee_id']
            );
        }
    }
    
    /**
     * @todo 获得改单费1费用
     * @author by Felix
     */
    private function getGdf01Fee() {
        $gdFeeRow = Service_OtherFee::getByField('GDF-01', 'fee_code');
        $cost     = 0;  //成本
        $gdFee  = 0;  //费用
        $discount = 1;  /* 客户折扣，1=100% */
        if (!empty($gdFeeRow)) {
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['coRow']['customer_code'],
                'fee_id'        => $gdFeeRow['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
            if ('1' == $gdFeeRow['status']) {
                //杂费状态：可用
                $gdFee = $gdFeeRow['fee_value'];
                $cost = $gdFeeRow['fee_amount'];
                if (!empty($customerOtherFee)) {
                    if ($customerOtherFee[0]['status'] == '1') {
                        //客户杂费可用，则参与打折计算
                        //设置了客户特殊报价，改成按特殊报价计算
                        $gdFee  = $customerOtherFee[0]['discount'] * (!empty($customerOtherFee[0]['fee_value']) ? $customerOtherFee[0]['fee_value'] : $gdFee);
                        $discount = $customerOtherFee[0]['discount'];
                    }
                }else{
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if('0' == $kncyFeeRow['is_default_fee']){
                        $gdFee  = 0;
                        $cost     = 0;
                    }
                }
            }
            //费用逻辑为单价*份数计算费用
            $gdFee   = $gdFee   * $this->_paramsArray['coRow']['quantity'];
            $cost    = $cost    * $this->_paramsArray['coRow']['quantity'];
            $this->_dataArray['costArr']['otherFee'][strtolower($gdFeeRow['fee_code'])] = array(
                'cost_currency_code' => $gdFeeRow['cost_currency_code'],
                'currency_code'      => $gdFeeRow['fee_currency_code'],
                'price'              => $gdFee,
                'discount'           => $discount,
                'cost'               => $cost,
                'sp_code'            => $gdFeeRow['sp_code'],
                'fee_id'             => $gdFeeRow['fee_id']
            );
        }
    }
    
    /**
     * @todo 获得改单费2费用
     * @author by Felix
     */
    private function getGdf02Fee() {
    $gdFeeRow = Service_OtherFee::getByField('GDF-02', 'fee_code');
        $cost     = 0;  //成本
        $gdFee  = 0;  //费用
        $discount = 1;  /* 客户折扣，1=100% */
        if (!empty($gdFeeRow)) {
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['coRow']['customer_code'],
                'fee_id'        => $gdFeeRow['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
            if ('1' == $gdFeeRow['status']) {
                //杂费状态：可用
                $gdFee = $gdFeeRow['fee_value'];
                $cost = $gdFeeRow['fee_amount'];
                if (!empty($customerOtherFee)) {
                    if ($customerOtherFee[0]['status'] == '1') {
                        //客户杂费可用，则参与打折计算
                        //设置了客户特殊报价，改成按特殊报价计算
                        $gdFee  = $customerOtherFee[0]['discount'] * (!empty($customerOtherFee[0]['fee_value']) ? $customerOtherFee[0]['fee_value'] : $gdFee);
                        $discount = $customerOtherFee[0]['discount'];
                    }
                }else{
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if('0' == $kncyFeeRow['is_default_fee']){
                        $gdFee  = 0;
                        $cost     = 0;
                    }
                }
            }
            //费用逻辑为单价*份数计算费用
            $gdFee   = $gdFee   * $this->_paramsArray['coRow']['quantity'];
            $cost    = $cost    * $this->_paramsArray['coRow']['quantity'];
            $this->_dataArray['costArr']['otherFee'][strtolower($gdFeeRow['fee_code'])] = array(
                'cost_currency_code' => $gdFeeRow['cost_currency_code'],
                'currency_code'      => $gdFeeRow['fee_currency_code'],
                'price'              => $gdFee,
                'discount'           => $discount,
                'cost'               => $cost,
                'sp_code'            => $gdFeeRow['sp_code'],
                'fee_id'             => $gdFeeRow['fee_id']
            );
        }
    }
    
    /**
     * @todo 获得报关删单费
     * @author by Felix
     */
    private function getSdfFee() {
        $bgdsdfFeeRow = Service_OtherFee::getByField('SDF', 'fee_code');
        $cost     = 0;  //成本
        $bgdsdfFee  = 0;  //费用
        $discount = 1;  /* 客户折扣，1=100% */
        if (!empty($bgdsdfFeeRow)) {
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['atRow']['customer_code'],
                'fee_id'        => $bgdsdfFeeRow['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
            if ('1' == $bgdsdfFeeRow['status']) {
                //杂费状态：可用
                $bgdsdfFee = $bgdsdfFeeRow['fee_value'];
                $cost = $bgdsdfFeeRow['fee_amount'];
                if (!empty($customerOtherFee)) {
                    if ($customerOtherFee[0]['status'] == '1') {
                        //客户杂费可用，则参与打折计算
                        //设置了客户特殊报价，改成按特殊报价计算
                        $bgdsdfFee  = $customerOtherFee[0]['discount'] * (!empty($customerOtherFee[0]['fee_value']) ? $customerOtherFee[0]['fee_value'] : $bgdsdfFee);
                        $discount = $customerOtherFee[0]['discount'];
                    }
                }else{
                    //非默认费用且该客户无此项杂费设置，则此项费用不收
                    if('0' == $bgdsdfFeeRow['is_default_fee']){
                        $bgdsdfFee  = 0;
                        $cost     = 0;
                    }
                }
            }
            //费用逻辑为单价*份数计算费用
            $bgdsdfFee   = $bgdsdfFee   * $this->_paramsArray['atRow']['quantity'];
            $cost    = $cost    * $this->_paramsArray['atRow']['quantity'];
            $this->_dataArray['costArr']['otherFee'][strtolower($bgdsdfFeeRow['fee_code'])] = array(
                'cost_currency_code' => $bgdsdfFeeRow['cost_currency_code'],
                'currency_code'      => $bgdsdfFeeRow['fee_currency_code'],
                'price'              => $bgdsdfFee,
                'discount'           => $discount,
                'cost'               => $cost,
                'sp_code'            => $bgdsdfFeeRow['sp_code'],
                'fee_id'             => $bgdsdfFeeRow['fee_id']
            );
        }
    }
    /**
     * @todo 获得操作费-M
     * @author by Felix
     */
    private function getCzfmFee(){
        $czfmFee  = 0;
        $cost = 0;
        //客户折扣 1=100%
        $discount = 1;
        $czfmRow = Service_OtherFee::getByField('CZF-M', 'fee_code');
        if (!empty($czfmRow) && array_key_exists('status', $czfmRow) && $czfmRow['status'] == '1') {
            $receiving_weight = $this->_paramsArray['receiving_weight'];
            if($receiving_weight > 0){
                //根据ASN下的录入的重量*费用单价进行实扣
                $czfmFee = $receiving_weight * sprintf('%.2f', $czfmRow['fee_value']);
                $cost = $receiving_weight * sprintf('%.2f', $czfmRow['fee_amount']);
                $customerFeeCondition = array(
                    'customer_code' => $this->_paramsArray['receingInfo']['customer_code'],
                    'fee_id'        => $czfmRow['fee_id']
                );
                $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
                //客户杂费可用，则参与打折计算
                if(!empty($customerOtherFee) && $customerOtherFee[0]['status'] == '1') {
                    $czfmFee = $customerOtherFee[0]['fee_value'] * $receiving_weight;
                    $discount = $customerOtherFee[0]['discount'];
                }
                //非默认费用且该客户无此项杂费设置，则此项费用不收
                if(($czfmRow['is_default_fee'] == 0) && empty($customerOtherFee)){
                    $czfmFee = 0;
                    $cost = 0;
                }
            }
        }
        $this->_dataArray['costArr']['otherFee'][strtolower($czfmRow['fee_code'])] = array(
            'cost_currency_code'      => $czfmRow['cost_currency_code'],
            'currency_code' => $czfmRow['fee_currency_code'],
            'price'         => $czfmFee,
            'discount'      => $discount,
            'cost'          => $cost,
            'sp_code'       => $czfmRow['sp_code'],
            'fee_id'        => $czfmRow['fee_id'],
            'fee_name'      => $czfmRow['fee_name'],
            'customer_ft_code' => $czfmRow['customer_ft_code']
        );
    }
    
    /**
     * @todo 获得操作费-B
     * @author by Felix
     */
    private function getCzfbFee(){
        $czfbFee  = 0;
        $cost = 0;
        //客户折扣 1=100%
        $discount = 1;
        $czfbRow = Service_OtherFee::getByField('CZF-B', 'fee_code');
        if (!empty($czfbRow) && array_key_exists('status', $czfbRow) && $czfbRow['status'] == '1') {
            $weight = $this->_paramsArray['receiving_weight'];
            if($weight > 0){
                //根据订单实重*费用单价进行实扣
                $czfbFee = $weight * sprintf('%.2f', $czfbRow['fee_value']);
                $cost = $weight * sprintf('%.2f', $czfbRow['fee_amount']);
                $customerFeeCondition = array(
                    'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
                    'fee_id'        => $czfbRow['fee_id']
                );
                $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
                //客户杂费可用，则参与打折计算
                if(!empty($customerOtherFee) && $customerOtherFee[0]['status'] == '1') {
                    $czfbFee = $customerOtherFee[0]['fee_value'] * $weight;
                    $discount = $customerOtherFee[0]['discount'];
                }
                //非默认费用且该客户无此项杂费设置，则此项费用不收
                if(($czfbRow['is_default_fee'] == 0) && empty($customerOtherFee)){
                    $czfbFee = 0;
                    $cost = 0;
                }
            }
        }
        $this->_dataArray['costArr']['otherFee'][strtolower($czfbRow['fee_code'])] = array(
            'cost_currency_code'      => $czfbRow['cost_currency_code'],
            'currency_code' => $czfbRow['fee_currency_code'],
            'price'         => $czfbFee,
            'discount'      => $discount,
            'cost'          => $cost,
            'sp_code'       => $czfbRow['sp_code'],
            'fee_id'        => $czfbRow['fee_id'],
            'fee_name'      => $czfbRow['fee_name'],
            'customer_ft_code' => $czfbRow['customer_ft_code']
        );
    }
    
    /**
     * @todo 获得易货打包费
     * @author by Felix
     */
    private function getYhdbfFee(){
        $yhdbfFee  = 0;
        $cost = 0;
        //客户折扣 1=100%
        $discount = 1;
        $yhdbfRow = Service_OtherFee::getByField('YHDBF', 'fee_code');
        if (!empty($yhdbfRow) && array_key_exists('status', $yhdbfRow) && $yhdbfRow['status'] == '1') {
            //根据数量*费用单价进行实扣
            $yhdbfFee = $yhdbfRow['fee_value'] * $this->_paramsArray['coRow']['quantity'];
            $cost = $yhdbfRow['fee_amount'];
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['coRow']['customer_code'],
                'fee_id'        => $yhdbfRow['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
            //客户杂费可用，则参与打折计算
            if(!empty($customerOtherFee) && $customerOtherFee[0]['status'] == '1') {
                $yhdbfFee = $customerOtherFee[0]['fee_value'] * $this->_paramsArray['coRow']['quantity'];
                $discount = $customerOtherFee[0]['discount'];
            }
            //非默认费用且该客户无此项杂费设置，则此项费用不收
            if(($yhdbfRow['is_default_fee'] == 0) && empty($customerOtherFee)){
                $yhdbfFee = 0;
                $cost = 0;
            }
        }
        $this->_dataArray['costArr']['otherFee'][strtolower($yhdbfRow['fee_code'])] = array(
            'cost_currency_code'      => $yhdbfRow['cost_currency_code'],
            'currency_code' => $yhdbfRow['fee_currency_code'],
            'price'         => $yhdbfFee,
            'discount'      => $discount,
            'cost'          => $cost,
            'sp_code'       => $yhdbfRow['sp_code'],
            'fee_id'        => $yhdbfRow['fee_id'],
            'fee_name'      => $yhdbfRow['fee_name'],
            'customer_ft_code' => $yhdbfRow['customer_ft_code']
        );
    }
    
    /**
     * @todo 获得旺季附加费
     * @author by Felix
     */
    private function getWjfjfFee(){
        $wjfjfFee  = 0;
        $cost = 0;
        //客户折扣 1=100%
        $discount = 1;
        $wjfjfRow = Service_OtherFee::getByField('WJFJF', 'fee_code');
        if (!empty($wjfjfRow) && array_key_exists('status', $wjfjfRow) && $wjfjfRow['status'] == '1') {
            //根据订单计费重量*费用单价进行实扣
            // 重量取计费重量
            $shipOrder  = Service_ShipOrder::getByField($this->_paramsArray['order_code'], 'order_code');
            
            if (isset($shipOrder['so_fee_weight']) && $shipOrder['so_fee_weight'] != 0) {
                $orderWeight    = $shipOrder['so_fee_weight'];
            } else {
                $orderWeight    = $this->_paramsArray['weight'];
            }
            $wjfjfFee = $wjfjfRow['fee_value'] * $orderWeight;
            $cost = $wjfjfRow['fee_amount'];
            $customerFeeCondition = array(
                'customer_code' => $this->_paramsArray['orderInfo']['customer_code'],
                'fee_id'        => $wjfjfRow['fee_id']
            );
            $customerOtherFee = Service_CustomerOtherFee::getByCondition($customerFeeCondition, '*');
            //客户杂费可用，则参与打折计算
            if(!empty($customerOtherFee) && $customerOtherFee[0]['status'] == '1') {
                $wjfjfFee = $customerOtherFee[0]['fee_value'] * $orderWeight;
                $discount = $customerOtherFee[0]['discount'];
            }
            //非默认费用且该客户无此项杂费设置，则此项费用不收
            if(($wjfjfRow['is_default_fee'] == 0) && empty($customerOtherFee)){
                $wjfjfFee = 0;
                $cost = 0;
            }
        }
        $this->_dataArray['costArr']['otherFee'][strtolower($wjfjfRow['fee_code'])] = array(
            'cost_currency_code'      => $wjfjfRow['cost_currency_code'],
            'currency_code' => $wjfjfRow['fee_currency_code'],
            'price'         => $wjfjfFee,
            'discount'      => $discount,
            'cost'          => $cost,
            'sp_code'       => $wjfjfRow['sp_code'],
            'fee_id'        => $wjfjfRow['fee_id'],
            'fee_name'      => $wjfjfRow['fee_name'],
            'customer_ft_code' => $wjfjfRow['customer_ft_code']
        );
    }
}
