<?php
class ProductModel extends Model{
   /* 取产品的方法 product表
	*$type   只能等于yicms
	* $id 可不传,自动获取GET的id.
	*/
	public function pro($type,$id=-1){
		if($type != 'yicms') exit ('type必须为yicms');
		$pro = $this->where("id = {$id}")->find();
		$id  = $pro['id'];
		$pid = $pro['pid'];
		$prev = $this->field('title,pid,id,time')->where("id < {$id} AND pid = {$pid}")->order('id DESC')->limit(1)->find();
		$next = $this->field('title,pid,id,time')->where("id > {$id} AND pid = {$pid}")->order('id ASC')->limit(1)->find();
		$list = M('Nav')->field('id,name,dir')->where("id = {$pid}")->find();
		$pro['mpic'] = C('URL').'/Public/product/m_'.$pro['pic'];
		$pro['fullmpic'] = '<img src="'.$pro['mpic'].'" title="'.$pro['title'].'" alt="'.$pro['title'].'" border="0"/>';
		$pro['spic'] = C('URL').'/Public/product/s_'.$pro['pic'];
		$pro['fullspic'] = '<img src="'.$pro['spic'].'" title="'.$pro['title'].'" alt="'.$pro['title'].'" border="0"/>';
		$pro['name'] = $list['name'];
		$pro['time'] = switchtime($pro['time']);
		if(C('ISHTML')){
			$pro['nurl'] = C('URL').'/'.$list['dir'];
			$data = M('Nav');
			$nav = $data->field('dir,conname')->where("id = $pid")->find();
			/*上一条*/
			$conname = str_replace('{id}',$prev['id'],$nav['conname']);
			$conname = str_replace('{Y}',date('Y',$prev['time']),$conname);
			if(empty($prev)) $pro['prev']='没有了';
			else $pro['prev']= '<a href="'.C('URL').'/'.$nav['dir'].'/'.$conname.'" tile="'.$prev['title'].'">'.$prev['title'].'</a>';
			/*下一条*/
			$conname = str_replace('{id}',$next['id'],$nav['conname']);
			$conname = str_replace('{Y}',date('Y',$next['time']),$conname);
			if(empty($next)) $pro['next']='没有了';
			else $pro['next']= '<a href="'.C('URL').'/'.$nav['dir'].'/'.$conname.'" tile="'.$next['title'].'">'.$next['title'].'</a>';
		}else{
			$pro['nurl']= C('URL').'/index.php/Index/plist/id/'.$list['id'];
			if(empty($prev)) $pro['prev']='没有了';
			else $pro['prev']= '<a href="'.C('URL').'/index.php/Index/pro/id/'.$prev['id'].'" tile="'.$prev['title'].'">'.$prev['title'].'</a>';
			if(empty($next)) $pro['next']='没有了';
			else $pro['next']= '<a href="'.C('URL').'/index.php/Index/pro/id/'.$next['id'].'" tile="'.$next['title'].'">'.$next['title'].'</a>';
		}
		$pro['fullnurl'] = '<a href="'.$pro['nurl'].'" title="'.$pro['name'].'">'.$pro['name'].'</a>';
		return $pro;
	}
}
?>