<?php
class order_cartapiControl extends skymvc{
	public $oc_where;
	public function __construct(){
		parent::__construct();
		$this->loadModel(array("login","order_cart","product","shop"));
		$this->oc_where=$this->login->userid?" (userid=".$this->login->userid." or oc_ssid='".OC_SSID."') ":"oc_ssid='".OC_SSID."' ";
	}
	
	public function onDefault(){
		
	}
	
	public function Cart(){
		$where=$this->oc_where;
		$list=$this->order_cart->select(array("where"=>$where));
		$shopid=0;
		if($list){
			foreach($list as $v){				
				if(!$shopid) $shopid=$v['shopid'];
				$ids[]=$v['object_id'];
			}
			
			$ids && $t_d=$this->product->id_list(array("where"=>" id in("._implode($ids).") "));
			$total_money=0; 
			foreach($list as $k=>$v){
				$t_c=$t_d[$v['object_id']];
				/**处理购物车的商品**/
				if(SHOWWEEK){
					if(!$t_c['week'.getweek()]){
						$this->order_cart->delete("id=".$v['id']);
					}
				}
				if(empty($t_c)){
					$this->order_cart->delete("id=".$v['id']);
				}
				/**处理结束***/
				$v['title']=$t_c['title'];
				$v['imgurl']=$t_c['imgurl'];
				$v['price']=$t_c['lower_price']>0?$t_c['lower_price']:$t_c['price'];
				$total_money+=$v['price']*$v['amount'];
				$list[$k]=$v;
			}
			if($shopid){
				$shop=$this->shop->selectRow(array("where"=>" shopid=".$shopid." "));
			}
			//print_r($list);
			return array("list"=>$list,"total_money"=>$total_money,"num"=>count($list),"shop"=>$shop); 
		}
		
	}
	
}
?>