Dao.php
1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?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();
}
}