Product.class.php 3.63 KB
<?php
/**
 * 默认控制器
 */
class Controller_Product extends Controller_Abstract
{
    
    public function indexAction()
    {
       return $this->_forward('news/index');
    }
    
    
    /**
     * 详情页
     *
     */
    public function detailAction()
    {
        $id = intval($this->_request->id);
        if (empty($id))
        {
            return $this->_redirect('news/index');
        }
        $info = Facade_News::getOneById($id);
        if (!$info)
        {
            return $this->_redirect('news/index');
        }
        //增加浏览量
        Facade_News::updateHits($id);
        
        //获取上一个
        $prev = Facade_News::getPrevNews($id);
        if ($prev)
        {
            if ($prev['thumb'])
            {
                $thumb = Lib_Images::getImageUrl($prev['thumb'], '0138x0075','fragmentimg'); 
            }else
            {
                $thumb = SITE_IMG.'/pic01.png';
            }
            $prev['thumb'] = $thumb ;
            $prev['title'] = Util_StringHelper::substr_cn( $this->stripTags($prev['title']),20 );
            $prev['desc'] = Util_StringHelper::substr_cn( $this->stripTags($prev['content']),40 );
            
        }
        //获取下一个
        $next = Facade_News::getNextNews($id);
        if ($next)
        {
            if ($next['thumb'])
            {
                $thumb = Lib_Images::getImageUrl($next['thumb'], '0138x0075','fragmentimg'); 
            }else
            {
                $thumb = SITE_IMG.'/pic01.png';
            }
            $next['thumb'] = $thumb ;
            $next['title'] = Util_StringHelper::substr_cn( $this->stripTags($next['title']),20 );
            $next['desc'] = Util_StringHelper::substr_cn( $this->stripTags($next['content']),40 );
            
        }
        
        $this->_view['next'] = $next ; 
        $this->_view['prev'] = $prev ; 
        $this->_view['info'] = $info ;
        /***设置网站的SEO信息***/
        $seo = C('APP.Seo');
        $this->setTitle($info['title']);
        $this->setKeywords($seo['channel_news_keywords']);
        $this->setDescription($seo['channel_news_description']);
    }
    
    /**
     * 限量推荐
     */
    public function recommendAction()
    {
    	/*
    	 * $test = $this->_request->query('test', 1);
    	if($test)
    	{
    		$this->_viewname ='recommend_ad';
    	}*/
    	$limit = 10;
    	$recomStatus = 1;
    	$total = Facade_Prod::getProdTotal($recomStatus);
    	$page = new Lib_Helper_Pagination($total, $limit);
    	list($offset, $limit) = $page->getLimit();
    	$products = Facade_Prod::getProd($recomStatus, $offset, $limit);
    	$brands = array();
    	foreach($products as $product)
    	{
    		if(!isset($brands[$product['brand_id']]))
    		{
    			$brand = Facade_Brand::getBrandbyID($product['brand_id']);
    			if ($brand['logo'])
    			{
    				$thumb = Lib_Images::getImageUrl($brand['logo'], '0110x0073','fragmentimg');
    			}
    			else
    			{
    				$thumb = SITE_IMG.'/pic01.png';
    			}
    			$brand['logo'] = $thumb;
    			$brands[$product['brand_id']] = $brand;
    		}
    	}
    	$this->_view['products'] = $products;
    	$this->_view['brands'] = $brands;
    	$this->_view['pagination'] = $page->getPagination();
    }
    
    /**
     * 获取限量推荐
     * 
     * @return json
     */    
    public function getrecommendAction()
    {
         $offset = intval($this->_request->query('offset', 0));
         $limit = intval($this->_request->query('limit', 5));
         $recomStatus = 1;
         $products = Facade_Prod::getProd($recomStatus, $offset, $limit);
         return $this->returnJson(true, 200, $products, '');     
    }
}