Brand.class.php 4.37 KB
<?php
/**
 * 默认控制器
 */
class Controller_Brand extends Controller_Abstract
{
    
    public function indexAction()
    {
        $limit = 1000 ;
        $total = Facade_Brand::getBrandTotal(1);
        $pagination = new Lib_Helper_Pagination($total, $limit);
        $list = Facade_Brand::getBrandByState( $pagination->getOffset(), $limit,1);
        foreach ($list as $k => $v)
        {
            if ($v['logo'])
            {
                $thumb = $v['logo']; 
            }
            else
            {
                $thumb = SITE_IMG.'/pic01.png';
            }
            $list[$k]['logo'] = $thumb ;
        }
        $this->_view['list'] = $list ;
        $this->_view['pagination'] = $pagination->getPagination() ;
        /***设置网站的SEO信息***/
        $seo = C('APP.Seo');
        $this->setTitle($seo['channel_brand_title']);
        $this->setKeywords($seo['channel_brand_keywords']);
        $this->setDescription($seo['channel_brand_description']);
        $seo = null; unset($seo);
    }
    /**
     * 详情页
     */
    public function detailAction()
    {
        $id = intval($this->_request->id);
        if (empty($id))
        {
            return $this->_redirect('brand/index');
        }
        $total = 0;
        $page = new Lib_Helper_Pagination($total, 100);
        list($offset, $limit) = $page->getLimit();
        $info = Facade_Brand::getBrandbyID($id);
        $news = array();
        $goodsList = $this->getGoods($id, intval($offset), intval($limit), $total);
        $page->setRecordCount($total)->setParames(array('id'=> $id))->setModel('ajax','#goods_list');
        $this->_view['goods'] = $goodsList;
        $this->_view['isAjax'] = $this->_request->isAjax();
        if(!$this->_request->isAjax())
        {     
	        if(isset($info['news_ids']) && $info['news_ids'])
	        {
	            $ids = explode(',', $info['news_ids']);
	            foreach ($ids as $id)
	            {
	                $new = Facade_News::getOneById($id);
	                if($new)
	                {
	                    $news[] = $new;
	                }
	            }
	            $news = $this->procNews($news);
	        }
	        $this->_view['news'] = $news;
	        if (!$info)
	        {
	            return $this->_redirect('brand/index');
	        }
	        $this->_view['info'] = $info ;
	        /***设置网站的SEO信息***/
	        $seo = C('APP.Seo');
	        $this->setTitle($info['name']."|YO'HOOD 品牌 | YO'HOOD, 2013非常潮流盛事");
	        $this->setKeywords($seo['channel_brand_keywords']);
	        $this->setDescription($seo['channel_brand_description']);
	        $seo = null; unset($seo);
        }
        $this->_view['pagination'] = $page->getPagination();
   
    }
    
    /**
     * 处理新闻
     */
   private function procNews($list, $num1 = 90, $num2 = 100)
   {
       foreach ($list as $k => $v)
       {
           if ($v['thumb'])
           {
               $thumb = Lib_Images::getImageUrl($v['thumb'], 'source','fragmentimg');
           }else
           {
               $thumb = SITE_IMG.'/pic01.png';
           }
           $list[$k]['thumb'] = $thumb ;
           $list[$k]['desc'] = Util_StringHelper::substr_cn( $this->stripTags($v['content']), $num1);
           $list[$k]['desc']=str_replace(array("\r\n", "\n", "\r"), "", $list[$k]['desc']);
           $list[$k]['type_name'] =  $v['tag'] ;
           $list[$k]['title'] = Util_StringHelper::substr_cn('['.$v['tag'].'] '.$v['title'], $num2);
       }
       
       return $list;
   }

   /**
    * 获取商品
    */
    private function getGoods($brandId, $offset, $limit, &$total = 0)
    {
        $goodsList = Facade_Prod::getProdByBrandId($offset, $limit ,$brandId);
        $total = Facade_Prod::getProdTotalByBrandId($brandId);
        foreach ($goodsList as $k => $v)
        {
            $thumb = explode('|', $v['pic']);
            $goodsList[$k]['pic'] = $thumb;
            $goodsList[$k]['thumb'] = preg_replace('/-(\w+\d+)-/','-0150x0200-', $thumb[0]);
            foreach ($thumb as $key => $val)
            {
                $thumb[$key] = preg_replace('/-(\w+\d+)-/','-0362x0481-', $val);
            }
            $goodsList[$k]['big'] = $thumb;
            $goodsList[$k]['shortTitle'] = Util_StringHelper::substr_cn($v['name'], 21);
            $goodsList[$k]['info'] = Util_StringHelper::substr_cn($v['text'], 20);
        }
        return $goodsList;
    }
}