Plusstar.php 4.67 KB
<?php

use Action\AbstractAction;
use LibModels\Wap\Guang\PlusstarData;
use Plugin\Helpers;
use Plugin\Cache;

/**
 * 明星品牌和原创品牌
 */
class PlusstarController extends AbstractAction
{

    /**
     * 国际优选-品牌列表页
     * 明星原创-品牌列表页
     * 
     * @param int gender "1,3"表示男, "2,3"表示女
     * @param int type 1表示国际优选, 2表示明星原创
     */
    public function indexAction()
    {
        $gender = $this->get('gender', '1,3');
        $type = $this->get('type', 1);
        if ($type == '2') {
            $this->setTitle('明星原创');
            $this->setNavHeader('明星原创', true, SITE_MAIN);
            
            $data = Guang\PlusstarModel::getBrands($gender);
            $data['psList'] = true; // 控制模板中的JS使用
            
            $this->_view->display('list', $data);
        } else {
            $this->setTitle('国际优选');
            $this->setNavHeader('国际优选', true, SITE_MAIN);
            
            $data = Guang\PlusstarModel::getFirstBrands($gender);
            $data['psList'] = true; // 控制模板中的JS使用
            
            $this->_view->display('index', $data);
        }
    }

    /**
     * 明星原创-品牌列表页
     * 
     * 备注:已不使用暂留着,可去掉
     * @param int gender "1,3"表示男, "2,3"表示女
     */
    public function listAction()
    {
        $this->setTitle('明星原创');
        $this->setNavHeader('明星原创', true, SITE_MAIN);
        
        $gender = $this->get('gender', '1,3');

        $data = Guang\PlusstarModel::getBrands($gender);
        $data['psList'] = true; // 控制模板中的JS使用

        $this->_view->display('list', $data);
    }

    /**
     * 品牌介绍页
     */
    public function detailAction()
    {
        $data = array();

        $id = $this->get('id');
        $gender = $this->get('gender', '1,3');
        $uid = $this->getUid();
        $udid = $this->getUdid();

        do {
            /* 判断参数是否有效 */
            if (!is_numeric($id) || ($gender !== '1,3' && $gender !== '2,3')) {
                break;
            }

            /* 判断品牌信息是否为空 */
            $brandInfo = PlusstarData::brandInfo($id, $gender, $uid, $udid);
            if (empty($brandInfo['getBrandInfo']['data']['brand_id'])) {
                break;
            }
            $brandId = $brandInfo['getBrandInfo']['data']['brand_id'];
                    
            /* 获取更多品牌的链接 */
            $url = '/brands';
            $brandDomains = Product\ListModel::getAllBrandDomains();
            if (isset($brandDomains[$brandId])) {
                // 构建成 品牌域名.xxx.com
                $url = Helpers::url('', null, $brandDomains[$brandId]);
            }
            
            $data['psDetail'] = true;
            $data['ps']['id'] = $brandId;
            $data['ps']['banner'] = Helpers::getImageUrl($brandInfo['getBrandInfo']['data']['cover_img'], 640, 309);
            $data['ps']['logo'] = Helpers::getImageUrl($brandInfo['getBrandInfo']['data']['brand_ico'], 160, 160);
            $data['ps']['name'] = $brandInfo['getBrandInfo']['data']['brand_name'];
            $data['ps']['isLike'] = $brandInfo['getUidBrandFav'];
            $data['ps']['likeUrl'] = false; //"http://guang.m.yohobuy.com/plustar/brandinfo?id=285&amp;openby:yohobuy={&quot;action&quot;:&quot;go.weblogin&quot;,&quot;params&quot;:{&quot;jumpurl&quot;:{&quot;url&quot;:&quot;http:\/\/guang.m.yohobuy.com\/plustar\/brandinfo&quot;,&quot;param&quot;:{&quot;id&quot;:285}},&quot;requesturl&quot;:{&quot;url&quot;:&quot;\/guang\/api\/v1\/favorite\/togglebrand&quot;,&quot;param&quot;:{&quot;brand_id&quot;:&quot;701&quot;}},&quot;priority&quot;:&quot;Y&quot;}}";
            $data['ps']['intro'] = empty($brandInfo['getBrandInfo']['data']['brand_intro']) ? '' : strtr(strip_tags($brandInfo['getBrandInfo']['data']['brand_intro']), array('&nbsp;' => ' '));
            $data['ps']['newArrival'] = array();
            $data['ps']['newArrival']['moreUrl'] = $url; 
            $data['ps']['newArrival']['naList'] = $brandInfo['getNewProduct'];
            $data['ps']['infos'] = array();

            if (empty($brandInfo['getArticleByBrand'])) {
                break;
            }

            // 相关文章
            foreach ($brandInfo['getArticleByBrand'] as $value) {
                $data['ps']['infos'][] = Helpers::formatArticle($value, false, false, false);
            }

            $brandInfo = array();
        } while (false);

        if (array() === $data) {
            $this->error();
        } else {
            $this->_view->display('detail', $data);
        }
    }

}