Amount.php 904 Bytes
<?php

/**
 * Created by PhpStorm.
 * User: ziy
 * Date: 14-8-6
 * Time: 下午3:03
 */
class YHMCart_Hook_Calculate_Amount extends YHMCart_Hook_Abstract
{
    static function run(YHMCart_Hook_Orders $package)
    {
        $lastOrderAmount = $package->getOrderData('last_order_amount');
        $last_shipping_fee=$package->getOrderData('last_shipping_fee');
        $goods_list=$package->getOrderData('goods_list');
        if (empty($lastOrderAmount)) {
            return;
        }
        $tmp_amount=0;
        foreach($goods_list as $k =>$val)
        {
        	$tmp_amount+=empty($val['last_price'])?0:$val['last_price']*$val['buy_number'];
        }
        if($tmp_amount+$last_shipping_fee>$lastOrderAmount)
        {
        	throw new Exception('实际付款金额小于订单金额、运费的和');
        }
        $package->setOrderData('last_order_amount', $lastOrderAmount);
    }
}