Plusstar.php 6.38 KB
<?php

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

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

    /**
     * 品牌列表页
     * 
     * @param int gender "1,3"表示男, "2,3"表示女
     */
    public function listAction()
    {
        $data = array('psList' => true, 'ps' => array('star' => array(), 'plus' => array()));

        $brandList = array();
        $build = array();
        $imgs = array();

        $gender = $this->get('gender', '1,3');
        // 女
        if ($gender === '2,3') {
            $brandList = PlusstarData::brandList('2,3', 2);
        }
        // 男
        else {
            $brandList = PlusstarData::brandList('1,3', 1);
        }

        // 明星品牌列表
        if (!empty($brandList['star']['data']['list'][0]['data'])) {
            foreach ($brandList['star']['data']['list'][0]['data'] as $star) {
                $imgs = array();
                $build = array();

                // 情况1: 多张图
                if (isset($star['data'][1])) {
                    foreach ($star['data'] as $value) {
                        $build['url'] = $value['url'];
                        $build['img'] = Helpers::getImageUrl($value['src'], 640, 310);
                        $imgs[] = $build;
                    }
                    $data['ps']['star'][] = array('imgs' => $imgs);
                }
                // 情况2: 单张图
                elseif (isset($star['data'][0])) {
                    $build['url'] = $star['data'][0]['url'];
                    $build['img'] = Helpers::getImageUrl($star['data'][0]['src'], 640, 310);
                    $data['ps']['star'][] = $build;
                }
            }
        }

        // 原创品牌列表
        if (!empty($brandList['original']['data']['list'][0]['data'])) {
            foreach ($brandList['original']['data']['list'][0]['data'] as $original) {
                $imgs = array();
                $build = array();

                // 情况1: 多张图
                if (isset($original['data'][1])) {
                    foreach ($original['data'] as $value) {
                        $build['url'] = $value['url'];
                        $build['img'] = Helpers::getImageUrl($value['src'], 640, 310);
                        $build['deps'] = $original['brand_title'];
                        $imgs[] = $build;
                    }
                    $data['ps']['plus'][] = array('imgs' => $imgs);
                }
                // 情况2: 单张图
                elseif (isset($original['data'][0])) {
                    $build['url'] = $original['data'][0]['url'];
                    $build['img'] = Helpers::getImageUrl($original['data'][0]['src'], 640, 310);
                    $build['deps'] = $original['brand_title'];
                    $data['ps']['plus'][] = $build;
                }
            }
        }
        
        $this->_view->display('list', $data);

        $brandList = array();
        $data = array();
    }

    /**
     * 品牌介绍页
     */
    public function detailAction()
    {
        $data = array();
        
        $id = $this->get('id');
        $gender = $this->get('gender', '1,3');
        $uid = 0; // @todo
        $udid = null; // @todo
        
        do {
            /* 判断参数是否有效 */
            if (!is_numeric($id) || ($gender !== '1,3' && $gender !== '2,3')) {
                break;
            }
            
            /* 判断品牌信息是否为空 */
            $brandInfo = PlusstarData::brandInfo($id, $gender, $uid, $udid); 
            if (empty($brandInfo['getBrandInfo']['brand_id'])) {
                break;
            }
            
            $data['psDetail'] = true;
            $data['ps']['id'] = $brandInfo['getBrandInfo']['brand_id'];
            $data['ps']['banner'] = Helpers::getImageUrl($brandInfo['getBrandInfo']['cover_img'], 640, 309);
            $data['ps']['logo'] = Helpers::getImageUrl($brandInfo['getBrandInfo']['brand_ico'], 160, 160);
            $data['ps']['name'] = $brandInfo['getBrandInfo']['brand_name'];
            $data['ps']['isLike'] = $brandInfo['getUidBrandFav'];
            $data['ps']['likeUrl'] = "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']['brand_intro']) ? '' : strtr(strip_tags($brandInfo['getBrandInfo']['brand_intro']), 'nbsp;', ' ');
            $data['ps']['newArrival'] = array();
            $data['ps']['newArrival']['moreUrl'] = ''; // @todo
            $data['ps']['newArrival']['naList'] = $brandInfo['getNewProduct'];
            $data['ps']['infos'] = array();
            
            if (empty($brandInfo['getArticleByBrand'])) {
                break;
            }

            // 相关文章
            $build = array();
            foreach ($brandInfo['getArticleByBrand'] as $value) {
                $build = array();
                $build['id'] = $value['id'];
                $build['showTags'] = false; // 不显示标签
                $build['img'] = Helpers::getImageUrl($value['src'], 640, 640, $value['cover_image_type']);
                $build['url'] = $value['url']; // @todo
                $build['title'] = $value['title'];
                $build['text'] = $value['intro'];
                $build['publishTime'] = $value['publish_time'];
                $build['pageView'] = $value['views_num'];
                $build['like'] = array();
                $build['like']['isLiked'] = $value['like']['isLiked'];
                $build['like']['count'] = $value['like']['count'];
                $build['share'] = ''; //分享链接
                $build['author'] = false; // 作者信息(接口暂未上线)
                
                $data['ps']['infos'][] = $build;
            }
            
            $brandInfo = array();
            
        } while (false);
        
        if (array() === $data) {
            $this->error();
        } else {
            $this->_view->display('detail', $data);
        }
    }

}