Brands.php 8.21 KB
<?php

namespace Product;

use Api\Yohobuy;
use WebPlugin\HelperSearch;
use LibModels\Web\Product\BrandData;
use Index\HomeModel;
use Product\SearchModel;
use WebPlugin\Helpers;

/**
 * 品牌首页模板数据模型
 *
 * @author Administrator
 */
class BrandsModel
{

    //品牌一览资源位CODE码
    const BOYS_BRAND_CODE = '8b16b7baf9a66fbe553a6caa97d2ce2a';
    const GIRLS_BRAND_CODE = 'c95ae9e40f0add10549b819f821ad626';
    const KIDS_BRAND_CODE = '84b7926282fdef92f1039bdcf77c18ba';
    const LIFESTYLE_BRAND_CODE = 'c575c6bfdfa4125fae7d24bbec7119c8';

    /**
     * 搜索品牌数据
     * @param $condition array 搜索数据的条件
     * @param $options array            
     * @return array
     */
    public static function getBrandSearchData($condition, $options)
    {
        // 并行调用品牌相关接口并封装数据
        $data = self::getBrandData($condition, $options);

        //获取品牌系列数据
        $adNav = self::getAdNav($options['brandId']);
        $data['leftContent'][] = array('picLink' => $adNav);

        //获取静态内容
        if ($options['node']) {
            $nodeContent = HelperSearch::formatNodeContent($options['node']);
            $data['leftContent'][]['picLink']['list'] = $nodeContent;
        }

        return $data;
    }
    
    
    
    
    
    /**
     * 品牌介绍页
     * @param array $customCondition
     * @param array $customOptions
     * @return array
     */
    public static function getBrandIntro($customCondition = array(), $customOptions = array())
    {
        $urlList = array();
        //组合搜索品牌url
        $urlList['brand'] = HelperSearch::getBrandUrl($customOptions);
        
        //批量调接口
        $result = Yohobuy::getMulti($urlList, array(), true);
        
        if (isset($result['brand'])) {
            $banner = HelperSearch::getBannerFormat($result['brand'], $customOptions['brandBanner']);
        }
        
        return array(
            'brandBanner' => $banner,
            'brandAbout' => $customOptions['brandAbout']
        );
    }
    
    
    
    
    
    
    
    
    
    //获取品牌系列数据
    public static function getAdNav($brandId, $status = 1)
    {
        //调用接口获得数据
        $advNav = BrandData::getFolderByBrand($brandId, $status);
        $result = array();
        if (isset($advNav['data']) && $advNav['code'] === 200) {
            foreach ($advNav['data'] as $key => $value) {
                $result['list'][$key]['href'] = '?folder_id=' . $value['id'];
                $result['list'][$key]['src'] = $value['brand_sort_ico'];
            }
            $result['picTitle'] = '经典系列';
        }

        return $result;
    }

    /**
     * 根据条件获取搜索数据
     * @param array $customCondition
     * @param array $customOptions
     * @return array
     */
    public static function getBrandData($customCondition = array(), $customOptions = array())
    {
        $urlList = array();

        //获取$condition和$option 筛选条件和排序条件
        $searchCondition = SearchModel::searchCondition($customCondition, $customOptions);

        // 组合搜索商品url
        $urlList['product'] = HelperSearch::getProductUrl($searchCondition['condition']);

        // 组合搜索分类url
        $urlList['sort'] = HelperSearch::getClassesUrl($searchCondition['sortCondition']);

        //组合搜索品牌url
        $urlList['brand'] = HelperSearch::getBrandUrl($customOptions);


        //组合用户浏览记录url
        //$urlList['reviewUrl'] = HelperSearch::getReviewUrl($searchCondition['condition']);
        
        //批量调接口
        $result = Yohobuy::getMulti($urlList, array(), true);
        
        //组织模板数据格式
        $data = HelperSearch::getList($result, $searchCondition['options']);

        
        return $data;
    }

    /*
     * 获取品牌一览页面,品牌top & 列表
     */

    public static function getBrandView($channel)
    {
        $switchParams = self::switchBrandParams($channel);
        $brandTop = array();
        $brandAds = array();
        $brandList = array();
        $res = BrandData::getTopBanner($switchParams['brandCode'], $switchParams['channelType']);
        //头部10个品牌图块
        if (isset($res['brandTop'][1]['data']['list']) && $res['brandTop'][1]['data']['list']) {
            foreach ($res['brandTop'][1]['data']['list'] as $tbk => $tbv) {
                $imgUrlTmp = explode("?", $tbv['src']);
                $urlTmp = explode("?", $tbv['url']);
                $topBrandTmp = array(
                    'name' => $tbv['name'],
                    'src' => Helpers::getImageUrl($imgUrlTmp[0], 80, 50, 3),
                    'url' => str_replace('m.', '', $urlTmp[0]),
                );
                $brandAds[$tbk] = $topBrandTmp;
            }
        }
        //头部品牌图块
        if (isset($res['brandTop'][0]['data']) && $res['brandTop'][0]['data']) {
            foreach ($res['brandTop'][0]['data'] as $tk => $tv) {
                $imgUrlTmp = explode("?", $tv['src']);
                $urlTmp = explode("?", $tv['url']);
                $topTmp = array(
                    'name' => $tv['title'],
                    'src' => $imgUrlTmp[0],
                    'url' => $urlTmp[0],
                    'items' => $brandAds
                );
                $brandTop[$tk] = $topTmp;
            }
        }
        //品牌list
        if (isset($res['brandList']['brands']) && $res['brandList']['brands']) {
            foreach ($res['brandList']['brands'] as $lk => $lv) {
                $listTmp = array();
                if (isset($lv) && $lv) {
                    foreach ($lv as $ltk => $ltv) {
                        $listTmp[$ltk] = array(
                            'name' => $ltv['brand_name'],
                            'key' => $ltv['id']
                        );
                        if ($ltv['is_hot'] == 'Y') {
                            $listTmp[$ltk] += array('hot' => 'hot');
                        }
                    }
                }
                $brandList[$lk] = $listTmp;
            }
        }
        return array(
            'brandTop' => $brandTop,
            'brandList' => $brandList
        );
    }

    /*
     * 获取单个广告浮窗内容
     */
    public static function getBrandInfo($brandId, $uid)
    {
        $data = array();
        $res = BrandData::getBrandIntro($brandId, $uid);
        if (isset($res['data']) && $res['data']) {
            $icoUrlTmp = explode("?", $res['data']['brand_ico']) ;
            $data = array(
                'key' => $res['data']['brand_id'],
                'icon' => $icoUrlTmp[0],
                'title' =>  $res['data']['brand_name'],
                'content' =>$res['data']['brand_intro'],
                'subtitle' => 'FEATURED ITEMS',
                'imgs' => array(),
            );
        }
        return $data;
    }

    /*
     * 获取品牌一览资源位&channelType
     */

    public static function switchBrandParams($channelStr = 'boys')
    {
        $res = array('channelType' => 1, 'brandCode' => self::BOYS_BRAND_CODE);
        switch ($channelStr) {
            case HomeModel::COOKIE_NAME_BOYS:
                $res['channelType'] = 1;
                $res['brandCode'] = self::BOYS_BRAND_CODE;
                break;
            case HomeModel::COOKIE_NAME_GIRLS:
                $res['channelType'] = 2;
                $res['brandCode'] = self::GIRLS_BRAND_CODE;
                break;
            case HomeModel::COOKIE_NAME_KIDS:
                $res['channelType'] = 3;
                $res['brandCode'] = self::KIDS_BRAND_CODE;
                break;
            case HomeModel::COOKIE_NAME_LIFESTYLE:
                $res['channelType'] = 4;
                $res['brandCode'] = self::LIFESTYLE_BRAND_CODE;
                break;
            default:
                $res['channelType'] = 1;
                $res['brandCode'] = self::BOYS_BRAND_CODE;
                break;
        }
        return $res;
    }

}