<?php
class productControl extends skymvc{
	public $user;
	public $userid;
	function __construct(){
		parent::__construct();
		$this->loadModel(array("login","user","loves","product","shop"));
		$this->user=$user=$this->login->getUser(get('userid','i'));
		$this->userid=$this->login->userid;
		
		if($user['userid']==$this->login->userid){
			$this->smarty->assign("heorme",'我的');
		}else{
			$this->smarty->assign("heorme",'她的');
		}
		$this->smarty->assign("user",$user);
	}
	
	public function onDefault(){
		
	}
	
	public function onHot(){
		$this->loadControl("productapi");
		$data=$this->productapiControl->hot(90);
		$this->smarty->assign(array(
			"data"=>$data
		));
		$this->smarty->display("product/hot.html");
	}
	
	public function onMylove(){
		if(!$this->login->userid){
			$this->gomsg($this->lang['user_no_exists'],"/index.php");
		}
		$userid=$this->login->userid;
		if(get('userid')){
			$userid=intval(get('userid'));	
		}
		 
		if(empty($userid)){
			$this->gomsg("参数出错","/index.php?m=login");
		}
		
		$pagesize=ISWAP?24:48;
		$start=get('per_page','i');
		$option=array(
			"where"=>" userid='$userid' ",
			"order"=>" id DESC ",
			"start"=>$start,
			"limit"=>$pagesize,
			"fields"=>"object_id"
		);
		$rscount=true;
		$object_ids=$this->loves->selectCols($option,$rscount);
		!empty($object_ids) && $list=$this->product->getAll("SELECT * FROM ".table('product')." WHERE id in("._implode($object_ids).") and  status<10   ");
		
		if($list){
			foreach($list as $k=>$v){
				$sid[]=$v['shopid'];
			}
			$sid && $ss=$this->shop->id_shop(array("where"=>"shopid in("._implode($sid).")"));
			foreach($list as $k=>$v){
				$v['shopname']=$ss[$v['shopid']]['shopname'];
				$list[$k]=$v;
			}
		}
		
		if(get('ajax')){
			exit(json_encode($list));
		}
		$user=$this->user;
		$seotitle=$user['nickname']."订阅的商品"; 
		$seo=array(
			"title"=>$seotitle,
			"keywords"=>$seotitle,
			"description"=>$seotitle
		);
		
		$this->smarty->assign(array(
			"baseurl"=>"/index.php?m=product&a=mylove&userid={$userid}",
			"pagelist"=>$this->pagelist($rscount,$pagesize,"/index.php?m=product&a=mylove&userid={$userid}"),
			"list"=>$list,
			"rscount"=>$rscount
		));
		
		if($this->userid!=$userid){
			$this->smarty->display("member/love_product.html");
		}else{
			
			$this->smarty->display("user/love_product.html");
		}
			
	}
	
	public function onMy(){
		$userid=$this->login->userid;
		if(get('userid')){
			$userid=intval(get('userid'));	
		}
		if(empty($userid)){
			$this->gomsg("参数出错","/index.php?m=login");
		}
		
		$pagesize=ISWAP?24:48;
		$start=get('per_page','i');
		$option=array(
			"where"=>" userid='$userid' AND (status>0 AND status<10) ",
			"order"=>" id DESC ",
			"start"=>$start,
			"limit"=>$pagesize,
		);
		$rscount=true;
		$list=$this->product->select($option,$rscount);
		$this->smarty->assign(array(
			"baseurl"=>"/index.php?m=product&a=my&userid={$userid}",
			"pagelist"=>$this->pagelist($rscount,$pagesize,"/index.php?m=product&a=my&userid={$userid}"),
			"list"=>$list,
		));
		$this->smarty->display("member/product.html");
	}

	
}
?>