Brands.php 8.34 KB
<?php

use Action\WebAction;
use WebPlugin\Helpers;
use WebPlugin\Paging;
use Index\BrandsModel;
use Index\HomeModel;
use Guang\PlusstarModel;

/**
 * 品牌相关的控制器
 */
class BrandsController extends WebAction
{

    /**
     * 品牌一览
     */
    public function indexAction()
    {
        $channel = Helpers::getChannelNameByCookie();

        //品牌一览头部
        $this->setWebNavHeader($channel);

        // 品牌一览列表
        $brandTop = BrandsModel::getBrandViewTop($channel);
        $brandList = BrandsModel::getBrandViewList($channel, 1, 5); //分屏加载 取第一屏数据 前5个数据
        $navigation = $brandList['navigation']; //导航
        unset($brandList['navigation']);
        // 添加网站的SEO
        switch ($channel) {
            default:
            case 'boys':
                $this->setTitle('品牌一览|男装品牌排行榜,男装品牌大全|YOHO!有货 100%正品保证');
                $this->setKeywords('品牌一览,男装品牌,男装品牌排行榜,男装品牌大全,YOHO!有货');
                $this->setDescription('YOHO!有货男装品牌一览汇集国内国际各大男装品牌大全,为广大爱好时尚的男士青年提供品牌男装、休闲男装、商务男装.YOHO!有货,100%正品保证');
                break;
            case 'girls':
                $this->setTitle('品牌一览|女装品牌排行榜,女装品牌大全|YOHO!有货 100%正品保证');
                $this->setKeywords('品牌一览,女装品牌,女装品牌排行榜,女装品牌大全,YOHO!有货');
                $this->setDescription('YOHO!有货女装品牌一览汇集国内国际各大女装品牌,为广大爱美女生提供品牌女装、休闲女装、商务女装.买品牌女装就上YOHO!有货,100%正品保证');
                break;
            case 'kids':
                $this->setTitle('品牌一览|童装童鞋品牌,儿童鞋包配饰排行榜,潮童品牌大全|YOHO!有货 100%正品保证');
                $this->setKeywords('童装品牌,童装童鞋排行榜,儿童鞋包配饰排行榜,潮童品牌大全,品牌一览,YOHO!有货');
                $this->setDescription('YOHO!有货童装品牌一览汇集国内国际各大童装品牌大全,为广大爱好潮流的儿童提供品牌童装、童鞋,儿童鞋包配饰.YOHO!有货,100%正品保证');
                break;
            case 'lifestyle':
                $this->setTitle('品牌一览|数码3c,居家,玩具娱乐,文具,美妆品牌|YOHO!有货 100%正品保证');
                $this->setKeywords('数码3c品牌,居家品牌,玩具娱乐品牌,文具品牌,美妆品牌');
                $this->setDescription('YOHO!有货女装品牌一览汇集国内国际各大数码3c品牌,居家品牌,玩具娱乐品牌,文具品牌,美妆品牌.买创意生活家居就上YOHO!有货,100%正品保证');
                break;
        }

        // 数据整合
        $data = array();
        $data['brandsHomePage'] = true;
        $data['brands'] = $brandTop;
        $data['brands']['navigation'] = $navigation;
        $data['brands']['category'] = $brandList;
        $data['brands']['pathNav'] = array(
            HomeModel::getHomeChannelNav($channel),
            array('name' => '品牌一览')
        );
        $this->_view->display('brands', $data);
    }

    /**
     * brandList-Ajax调用
     */
    public function brandListAction()
    {
        $data['category'] = array();
        do {
            /* 判断是不是AJAX请求 */
            if (!$this->isAjax()) {
                break;
            }
            $start = intval($this->post('start'));
            $channel = Helpers::getChannelNameByCookie();
            $brandList = BrandsModel::getBrandViewList($channel, $start);
            unset($brandList['navigation']);
            $data['category'] = $brandList;
        }
        while (false);
        $this->_view->display('brand-list', $data);
    }

    /**
     * 品牌接口数据
     *
     * @param string brandId 获取品牌ID
     * @return json
     */
    public function brandinfoAction()
    {
        do {
            /* 判断是不是AJAX请求 */
            if (!$this->isAjax()) {
                break;
            }
            $brandId = $this->get('brandId', 0);
            $uid = $this->getUid(false);
            $data = BrandsModel::getBrandInfo($brandId, $uid);
            $brand = empty($data) ? array() : $data;
            $code = empty($data) ? 400 : 200;
            $result = array(
                'code' => $code,
                'brand' => $brand
            );
        }
        while (false);

        $this->echoJson($result);
    }

    /**
     * 品牌plusstar列表
     */
    public function plusstarAction()
    {
        $this->setWebNavHeader();

        $id = $this->get('id', 1);
        $gender = $this->get('gender', Helpers::getGenderByCookie());
        $channel = Helpers::getChannelNameByCookie();
        $brandType = 1;
        $offset = 0;
        $limit = 20;
        $items = BrandsModel::getPlusstarBrandListItem($channel);
        // 添加网站的SEO
        switch ($channel) {
            default:
            case 'boys':
                $this->setTitle('品牌一览|男装品牌排行榜,男装品牌大全|YOHO!有货 100%正品保证');
                $this->setKeywords('品牌一览,男装品牌,男装品牌排行榜,男装品牌大全,YOHO!有货');
                break;
            case 'girls':
                $this->setTitle('品牌一览|女装品牌排行榜,女装品牌大全|YOHO!有货 100%正品保证');
                $this->setKeywords('品牌一览,女装品牌,女装品牌排行榜,女装品牌大全,YOHO!有货');
                break;
            case 'kids':
                $this->setTitle('品牌一览|童装童鞋品牌,儿童鞋包配饰排行榜,潮童品牌大全|YOHO!有货 100%正品保证');
                $this->setKeywords('童装品牌,童装童鞋排行榜,儿童鞋包配饰排行榜,潮童品牌大全,品牌一览,YOHO!有货');
                break;
            case 'lifestyle':
                $this->setTitle('品牌一览|数码3c,居家,玩具娱乐,文具,美妆品牌|YOHO!有货 100%正品保证');
                $this->setKeywords('数码3c品牌,居家品牌,玩具娱乐品牌,文具品牌,美妆品牌');
                break;
        }
        if (isset($items[$id])) {
            $brandType = $items[$id]['brandType'];
        }
        $brandIds = array();
        $brands = array();
        $list = PlusstarModel::getPlustarList($brandType, $gender);
        $paging = new Paging('yoho');
        if (!empty($list)) {
            $paging->setTotal(count($list))->setSize($limit)->setQuery(array('id' => $id));
            $offset = $paging->getOffset();
            $brandIds = array_slice(array_keys($list), $offset, $limit);
        }
        if (!empty($brandIds)) {
            //获取品牌信息
            $brandsInfo = BrandsModel::getBrandInfoByIds($brandIds);
            foreach ($brandIds as $brandId) {
                if (isset($brandsInfo[$brandId])) {
                    $list[$brandId]['desc'] = $brandsInfo[$brandId]['desc'];
                    $list[$brandId]['url'] = $brandsInfo[$brandId]['url'] . '?gender=' . $gender;
                }
                $brands[] = $list[$brandId];
            }
        }
        $brandList = array('items' => $brands, 'tabs' => $items, 'page' => $paging->view(false), 'home' => HomeModel::getHomeChannelNav());
        $data = array(
            'brandsHomePage' => true,
            'brands' => $brandList
        );
        $this->_view->display('plusstar', $data);
    }

    /**
     * plusstar首页
     */
    public function plusstarindexAction()
    {
        $this->setWebNavHeader();
        $gender = $this->get('gender', Helpers::getGenderByCookie());
        $channel = Helpers::getChannelNameByCookie();
        $articles = PlusstarModel::getArticleBySortId(0, $gender, 1, 11);
        if(empty($articles)) {
            $articles = array();
        }
        $brands = BrandsModel::getPlusstarIndexInfo($channel, $articles);
        $data = array(
            'brandsHomePage' => true,
            'brands' => $brands
        );
        $this->_view->display('plusstarindex', $data);
    }
}