Plusstar.php 7.58 KB
<?php

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

/**
 * 明星品牌和原创品牌
 */
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使用
            $data['ps']['sName'] = '明星潮品';
            $data['ps']['pName'] = '原创潮牌';
            $data['pageFooter'] = true;

            $this->_view->display('list', $data);
        } else {
            $this->setTitle('国际优选');
            $this->setNavHeader('国际优选', true, SITE_MAIN);

            $data = Guang\PlusstarModel::getFirstBrands($gender);
            $data['psList'] = true; // 控制模板中的JS使用
            $data['ps']['sName'] = '设计师';
            $data['ps']['pName'] = '经典潮牌';
            $data['pageFooter'] = true;

            $this->_view->display('list', $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使用
        $data['ps']['sName'] = '明星潮品';
        $data['ps']['pName'] = '原创潮牌';

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

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

        do {
            /* 判断参数是否有效 */
            $id = $this->get('id');
            if (!is_numeric($id)) {
                break;
            }

            $channel = $this->get('yh_channel');
            // 标识是不是APP客户端
            $isApp = is_numeric($channel);
            // 标识是否是微信访问
            $isWeixin = stripos($this->server('HTTP_USER_AGENT', ''), 'MicroMessenger') !== false;
            // APP访问时通过频道参数判断性别
            if ($isApp) {
                switch (intval($channel)) {
                    case 1: // 男
                        $gender = '1,3';
                        break;
                    case 2: // 女
                        $gender = '2,3';
                        break;
                    default: // 所有
                        $gender = '1,2,3';
                }
                $uid = $this->get('uid');
                $udid = $this->get('udid');

                $this->setSession('uid', $uid);
            }
            // 从Cookie获取
            else {
                $gender = Helpers::getGenderByCookie();

                $uid = $this->getUid();
                $udid = $this->getUdid();
            }

            /* 判断品牌信息是否为空 */
            $brandInfo = array();
            try {
                $brandInfo = PlusstarData::brandInfo($id, $gender, $uid, $udid, $isApp);
            } catch (\Exception $e) {
                // do nothing
            }
            if (empty($brandInfo['getBrandInfo']['data']['brand_id'])) {
                break;
            }
            $brandId = $brandInfo['getBrandInfo']['data']['brand_id'];
            $brandDomain = $brandInfo['getBrandInfo']['data']['brand_domain'];
            $isDifferent = $brandInfo['getBrandInfo']['data']['is_different'];

            /* 获取更多品牌的链接 */
            // 构建成 品牌域名.xxx.com
            $url = Helpers::url('', null, $brandDomain);
            // 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护
            if ($isApp) {
                $url .= '?openby:yohobuy={"action":"go.brand","params":{"brand_id":"' . $brandId . '","is_different":"' . $isDifferent . '"}}';
            }

            $data['psDetail'] = true;
            $data['ps']['id'] = $brandId;
            $data['ps']['banner'] = Helpers::getImageUrl($brandInfo['getBrandInfo']['data']['cover_img'], 640, 309);
            $data['ps']['logo'] = Images::getSourceUrl($brandInfo['getBrandInfo']['data']['brand_ico'], 'brandLogo');
            $data['ps']['name'] = $brandInfo['getBrandInfo']['data']['brand_name'];
            $data['ps']['isLike'] = $brandInfo['getUidBrandFav'];
            $data['ps']['intro'] = empty($brandInfo['getBrandInfo']['data']['brand_intro']) ? false : 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();

            // 拼收藏的URL, 一个坑!
            // 备注:此处是根据原来逛的代码硬扒过来的
            $defaultUrl = Helpers::url('/plustar/brandinfo', array('id' => $id), 'guang');
            if ($isApp) {
                $url = $defaultUrl;
                $url .= '&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"http:\/\/guang.m.yohobuy.com\/plustar\/brandinfo","param":{"id":'
                    . $id . '}},"requesturl":{"url":"\/guang\/api\/v1\/favorite\/togglebrand","param":{"brand_id":"' . $brandId . '"}},"priority":"Y"}}';
            } else {
                $url = Helpers::url('/signin.html', array('refer' => $defaultUrl));
            }
            $data['ps']['likeUrl'] = $url;

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

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

            //jumpToApp = 1表示APP未登录的情况,此时不发送ajax请求而由a链接直接跳转APP
            if ($isApp && !$this->getSession('uid')) {
                $data['ps']['jumpToApp'] = 1;
            }

            // 设置头部信息
            if (!$isApp && !$isWeixin) {
                $this->setNavHeader($data['ps']['name'], true, SITE_MAIN);
            }

            // 标识有微信分享
            $data['hasWxShare'] = true;

            $data['shareLink'] = $defaultUrl;
            $data['shareTitle'] = $data['ps']['name'];
            $data['shareDesc'] = (mb_strlen($data['ps']['intro'], 'utf-8') > 120) ? trim(strip_tags(mb_substr($data['ps']['intro'], 0, 120, 'utf-8'))) . '...' : $data['ps']['intro'];
            $data['shareImg'] = $data['ps']['logo'];

            $this->setTitle($data['shareTitle'], false, '');
            $this->setDescription($data['shareDesc']);

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

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

}