Index.php 6.77 KB
<?php 
use Action\WebAction;
use LibModels\Web\Product\BrandData;
use LibModels\Web\Product\FavoriteData;
use Product\BrandsModel;

use LibModels\Web\Product\HotrankData;
use product\HotrankModel;

class IndexController extends WebAction
{
    /**
     * 品牌首页
     */
    public function brandAction()
    {
        //品牌域名,没有获取到品牌域名的跳转首页
        $domain = $this->param('named');
        if (empty($domain)) {
            $this->go(SITE_MAIN);
        }    
        //根据品牌域名获取品牌id(同时判断品牌域名是否有效),无效跳转首页
        $fields = 'id,brand_name,brand_name_cn,brand_name_en,brand_domain,brand_alif,brand_banner,brand_ico,static_content_code';
        $result = BrandsModel::getBrandByDomain($domain, $fields);
        if (!$result) {
            $this->go(SITE_MAIN);
        }
        
        //获取uid
        $uid = $this->getUid();
        
        //传品牌ID参数
        $condition = array();
        $condition['brand'] = isset($result['brandId']) ? $result['brandId'] : '';
        
        //品牌系列参数
        $folderId = $this->get('folder_id');
        $condition['folder_id'] = $folderId;
        
        //$options参数数组
        $options = array();
        $options['brandName'] = $domain;
        $options['uid'] = $uid;
        $options['brandId'] = isset($result['brandId']) ? $result['brandId'] : '';
        $options['node'] = isset($result['node']) ? $result['node'] : '';
        $options['brandBanner'] = isset($result['brandBanner']) ? $result['brandBanner'] : '';
        $options['brandNameEn'] = isset($result['brandNameEn']) ? $result['brandNameEn'] : '';
        $options['brandNameCn'] = isset($result['brandNameCn']) ? $result['brandNameCn'] : '';
        $options['reviewNum'] = 6;
        
        //调用模型获得数据
        $data = BrandsModel::getBrandSearchData($condition, $options);
        
        $data = array(
            //初始化js
            'searchListPage' => true,
            'list' => $data
        );
        
        $this->setWebNavHeader();
        //渲染模板
        $this->_view->display('list',$data);
    }
    
    //品牌介绍页
    public function brandIntroAction()
    {
        //品牌域名
        $domain = $this->param('named');
        if (empty($domain)) {
            $this->go(SITE_MAIN);
        }    
        $uid = $this->getUid();
        
        
        //根据品牌域名获取品牌id(同时判断品牌域名是否有效),无效跳转首页
        $fields = 'id,brand_name,brand_name_cn,brand_banner,brand_ico,brand_intro';
        $result = BrandsModel::getBrandByDomain($domain, $fields);
        if (!$result) {
            $this->go(SITE_MAIN);
        }
        
        //品牌ID参数
        $condition = array();
        $condition['brand'] = isset($result['brandId']) ? $result['brandId'] : '';
        
        //$options参数数组
        $options = array();
        $options['brandName'] = $domain;
        $options['uid'] = $uid;
        $options['brandId'] = isset($result['brandId']) ? $result['brandId'] : '';
        $options['brandBanner'] = isset($result['brandBanner']) ? $result['brandBanner'] : '';
        $options['brandAbout'] = isset($result['brandAbout']) ? $result['brandAbout'] : '';
        //调用模型获得数据
        $data = Product\BrandsModel::getBrandIntro($condition, $options);
        
        $data = array(
            //初始化js
            'searchListPage' => true,
            'list' => $data
        );
        
        $this->setWebNavHeader();
        //渲染模板
        $this->_view->display('list',$data);
    }
    
    //收藏品牌
    public function favoriteBrandAction()
    {
        if (!$this->isAjax()) {
            return;
        }
        $uid = $this->post('uid');
        
        $brandId = $this->post('brandId');
        if ($uid && $brandId) {
            //调用接口收藏或取消收藏
            $result = FavoriteData::changeFavoriteBrand($uid, $brandId);
            if (isset($result['code']) && $result['code'] == 200) {
                $this ->echoJson($result);
            }
        }
    }
    
 /**
     * 热销排行
     */
    public function hotrankAction() 
    {
        //获取频道
        $channel = HotrankModel::getChannelResource();
        $this->setWebNavHeader($channel['channel']);
        $data = array( 'hotrankPage' => true,
                        'footerTop'=> true,
                        'hotrank' => array()
                    );
        
        //焦点图 热门品牌
       $focus = HotrankModel::getFocusResource($channel['channel'], $channel['code']);
       $data['hotrank']['slide'] = $focus[0]['slide'];
       $data['hotrank']['hotBrands'] = $focus[1]['hotBrands'];

        //人气单品 一周热卖
       $page = $this->get('page',1);		
       $sort_id = $this->get('sid',0);
       $config = array('sort' =>$sort_id,'gender' => $channel['gender'],'road' => $channel['road']);
       $publiclist = HotrankModel::getSearchData($config,$page,0);
       $data['hotrank']['popular'] = $publiclist['popular'];
       $data['hotrank']['hotWeek'] = $publiclist['hotWeek'];
       
       //分类标签
       $nav = HotrankModel::getHotranktag('web',$channel['road'],true);
       $data['hotrank']['hotWeek']['nav'] = $nav;
       $this->_view->display('hotrank', $data);
    }
    
    /*
     * 一周热卖加载更多
     */
    public function getdataAction()
    {
        $page = $this->get('page',1);
        //加载到100个以后停止
        if($page > 2)
        {
            echo json_encode(array('code'=>201,'data'=>''));
            exit;
        }
        $sid = $this->get('sid',1);
        $sort = '';		
        //是否是默认标签
        if($sid > 1)
        {
            //通过ID获取标签信息
            $info = HotrankData::getTagById($sid, false);
            if(!empty($info['data']))
            {
                $sort = $info['data']['category_id'];
            }				
        }
        //获取频道资源
        $channel = HotrankModel::getChannelResource();
        //一周热卖
        $config = array('sort' =>$sort,'gender' => $channel['gender'],'road' => $channel['road']);
        $list = HotrankModel::getSearchData($config, $page, 1);
        $lister = $list['hotWeek']['list'];
        $lister = array_values($lister);
        if($sid == 1 && $page == 1)
        {
            $lister = array_slice($lister, 10, 50);
        }else{
            $lister = array_slice($lister, 0, 50);
        }
        $data = array( 'code'=>200, 'data'=>$lister,);
        echo json_encode($data);
        exit;   
    }
}