Dao.php 1.49 KB
<?php
use YHMOrders\SqlMap\Cart;
class YHMOrders_Models_Cart_Dao extends YHMOrders_Dao {
	
	private $_tag = 'orders_cart_';
	private $fields=array('uid','product_sku','product_skc','salse_price','last_price','buy_number','store_id','goods_type','is_change');
	
	public function __construct() {
		$this->router = 'cart.yhm_orders';
	}
	
	/**
	 * 
	 * @param int $uid
	 * @param int $product_sku
	 * @param float $last_price
	 * @return int
	 */
	public function getDetailByUid($uid,$product_sku,$last_price)
	{
		return $this->dao()->cache(false)->fetchOne(Orders\Cart::COUNT_ProductSku_Uid_LastPrice,array('uid'=>$uid,'product_sku'=>$product_sku,'last_price'=>$last_price));
	}
	
	/**
	 * 插入购物车
	 * @param array $params
	 * @return number
	 */
	public function setGoodsByUid($params)
	{
		if(empty($params)) return 0;
		$paramVal=array();
		foreach($this->fields as $f)
		{
			if(isset($params[$f]))
			{
				$paramVal[$f]=$params[$f];
			}
			else {
				throw new Exception($f . '没有赋值');
				break;
			}
		}
		return $this->dao()->insert(Orders\Cart::Set_Goods_By_Uid,$paramVal)->lastInsertId();
	}
	
	/**
	 * 更新购物车
	 * @param int $uid
	 * @param int $product_sku
	 * @param deciaml $last_price
	 * @param number $buy_number
	 */
	public function updateGoodsByNum($uid,$product_sku,$last_price,$buy_number=1)
	{
		return $this->dao()->update(Orders\Cart::UPDATE_ProductSku_NUMS,array('uid'=>$uid,'product_sku'=>$product_sku,'last_price'=>$last_price,'buy_number'=>$buy_number))->status();
	}
	
}