Brands.php 4.32 KB
<?php

namespace Product;

use Plugin\Helpers;
use Plugin\HelperSearch;
use LibModels\Web\Product\BrandData;
use LibModels\Wap\Product\SearchData;
use LibModels\Web\Product\SearchData as WebProduct;

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

    const URL_BRAND_INDEX = '/product/index/brand';

    public static $shopName;
    public static $home;

    /**
     * 搜索品牌数据
     *
     * @param $condition array
     * 搜索数据的条件
     * @param $options array            
     * @return array
     */
    public static function getBrandSearchData($condition, $options, $domain, $uid, $brandId,$node) {
        // 调用商品搜索接口
        $data = SearchData::searchElasticByCondition($condition);
        
        //获取品牌banner数据
        $banner = self::getBannerByDomain($domain, $brandId, $uid = '');
        $brandName = self::$shopName;
        $options['brandName'] = $brandName;
        
        if (isset($data['code']) && $data['code'] === 200) {
            //获取分类列表数据
            $param = array();
            $param['brand'] = $condition['brand'];
            $classes = WebProduct::getClassesData($param);
            if (isset($classes['code']) && $classes['code'] === 200) {
                $data['data']['filter']['group_sort'] = $classes['data']['sort'];
            }
            
            //用户浏览记录
            
            
            // 组织模板数据
            $list = HelperSearch::getList($data, $options);
            
            //合并商品搜索数据与品牌banner数据
            $list = array_merge_recursive($list,$banner);
            
            $data = array(
                //初始化js
                'productListPage' => true,
                'list' => $list
            );
        } else {
            $data = array();
        }

        //获取品牌系列数据
        $adNav = self::getAdNav($condition['brand']);
        $data['list']['leftContent'][] = array('picLink' => $adNav);
        
        //获取静态内容(20141219-100447)
        if($node){
            $nodeContent = HelperSearch::formatNodeContent($node);
            $data['list']['leftContent'][]['picLink']['list'] = $nodeContent;
        }
        
        return $data;
    }
    

    /**
     * 获取品牌首页banner条
     * @string $domain 品牌域名
     * @int $brandId 品牌id
     * @int $uid 用户id
     * 
     * @return array 品牌banner条数据
     */
    public static function getBannerByDomain($domain, $brandId, $uid = '') {
        // 构造品牌主页url
        self::$home = Helpers::url('', '', $domain) . self::URL_BRAND_INDEX;
        // 根据品牌Id获取品牌banner图
        $bannerImg = BrandData::getBrandBanner($brandId);
        if (isset($bannerImg['data'])) {
            $bannerImg = Helpers::getImageUrl($bannerImg['data']['banner'], '', 150);
        }
        // 根据品牌Id获取品牌(简介)、收藏
        if (isset($uid)) {
            $intro = BrandData::getBrandIntro($brandId, $uid);
        }
        $is_favorite = false;
        $shopName = false;
        if(isset($intro['data'])){
            // 获取是否收藏
            if ($intro['data']['is_favorite'] == 'Y') {
                $is_favorite = true;
            } elseif ($intro['data']['is_favorite'] == 'N') {
                $is_favorite = false;
            }
            // 获取品牌名
            self::$shopName = $intro['data']['brand_name']; 
        }
        
        // 返回banner数据
        return array(
            'brandBanner' => array(
                'bannerHeight' => '150',
                'coled' => $is_favorite,
                'banner' => $bannerImg
            )
        );
    }

    //获取品牌系列数据
    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'] = self::$home . '?folder_id=' . $value['id'];
                $result['list'][$key]['src'] = $value['brand_sort_ico'];
            }
        }
        $result['picTitle'] = '经典系列';
        
        return $result;
    }

}