<?php
class b2b_ymdianControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
	}
	public function onDefault(){
		$ymShopid=get("ymShopid","i");
		if(!$ymShopid){
			$ymShopid=intval($_COOKIE["ckYmShopid"]);
		}
		$shop=array();
		if(!$ymShopid){
			$ymShopid=0;
		}else{
			$shop=MM("b2b","b2b_shop")->get($ymShopid);
		}
		$this->smarty->goAssign(array(
			"shopid"=>$ymShopid,
			"shop"=>$shop
		));
		$this->smarty->display("ymdian/index.html");
	}
	
	public function onShopList(){
		$where=" siteid=".SITEID." AND shoptype='ymdian' AND status=1 ";
		$option=array(
			"where"=>$where
		);
		$list=MM("b2b","b2b_shop")->Dselect($option);
		echo json_encode(array(
			"error"=>0,
			"data"=>array(
				"list"=>$list
			)
		));
	}
	public function onSetShop(){
		$shopid=get("shopid","i");
		$shop=M("mod_b2b_shop")->selectRow("shopid=".$shopid);
		if($shop){
			setcookie("ckYmShopid",$shopid,time()+3600*24*10000,"/",DOMAIN);
			$this->goAll("success");
		}else{
			$this->goAll("商家不存在",1);
		}
		
	}
	
}