BrandData.php 4.05 KB
<?php

namespace LibModels\Web\Product;

use Api\Yohobuy;
use Api\Sign;

/**
 * 品牌数据接口操作类
 * 
 * @name BrandData
 * @package Library/LibModels/wap/Category
 * @copyright yoho.inc
 * @version 1.0 (2015-10-10)
 * @author gtskk <rocky.zhang@yoho.cn>
 */
class BrandData
{

    const URI_BRAND_TOPPOS = 'operations/api/v5/resource/get';
    const URL_BRAND_LOGO = '/cmsproduct/service/v1/brands';
    const URL_BRAND_FOLDER = '/cmsproduct/service/v1/brands';
    const URL_BRAND_NODECONTENT = '/operations/service/v6/htmlcontent';

    /**
     * 获取品牌简介
     * 
     * @param  integer $brandId 品牌ID
     * @param  int 用户ID
     * @return array  品牌介绍信息
     */
    public static function getBrandIntro($brandId, $uid)
    {
        // 构建必传参数
        $param = Yohobuy::param();
        $param['brand_id'] = $brandId;
        $param['uid'] = $uid;
        $param['method'] = 'app.brand.getBrandIntro';
        $param['client_secret'] = Sign::getSign($param);

        $cache = empty($uid) ? 3600 : false;

        return Yohobuy::get(Yohobuy::API_URL, $param, $cache); // 有缓存1小时
    }

    /**
     * 获取品牌banner图
     * @param  integer $brandId 品牌ID
     * @return array          banner图
     */
    public static function getBrandBanner($brandId)
    {
        // 构建必传参数
        $param = Yohobuy::param();
        $param['brand_id'] = $brandId;
        $param['method'] = 'app.brand.banner';
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param, 3600); // 有缓存1小时
    }

    /**
     * 获取品牌介绍详情
     * 
     * @param int $id 品牌id
     * @return array
     */
    public static function getBrandLogo($brandId)
    {
        return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_BRAND_LOGO, 'getBrandByids', array($brandId));
    }

    /**
     * 通过域名获取品牌LOGO信息
     * 
     * @param int $domain 品牌domain
     * @return array
     */
    public static function getBrandLogoByDomain($domain, $fields = 'less')
    {
        return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_BRAND_LOGO, 'getBrandByDomain', array($domain, $fields));
    }

    /**
     * 通过品牌id获取品牌Folder
     * 
     * @param int $brand_id 品牌id
     * @param int $status 状态
     * @return array
     */
    public static function getFolderByBrand($brand_id, $status = 1)
    {
        return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_BRAND_FOLDER, 'getFolderByBrand', array($brand_id, $status));
    }

    /**
     * 根据节点和运行模式选择静态内容
     * @param $node 20141219-100447
     * @param string $mode
     * @return mixed
     */
    public static function getByNodeContent($node, $mode = 'release')
    {
        return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_BRAND_NODECONTENT, 'getByNodeContent', array($node, $mode));
    }

    /*
     * 品牌一览资源位banner
     * @param string $contentCode 获取广告资源需要的位置码
     * @param int $channel 频道标识 1:男,2:女,3:潮童,4:创意生活
     * @return array(
     *     "brandTop": "顶部的轮翻广告及热门品牌数据",
     *     "brandList": "按字母'A-Z'分组的品牌列表数据"
     * )
     */

    public static function getTopBanner($contentCode,$channel)
    {
        /* 顶部的轮翻广告及热门品牌数据 */
        $param = Yohobuy::param();
        $param['content_code'] = $contentCode;
        $param['client_secret'] = Sign::getSign($param);
        $urlList['brandTop'] = Yohobuy::httpBuildQuery(Yohobuy::SERVICE_URL . self::URI_BRAND_TOPPOS, $param);

        /* 按字母"A-Z"分组的品牌列表数据 */
        $param = Yohobuy::param();
        $param['method'] = 'app.brand.brandlist';
        $param['yh_channel'] = $channel;
        $param['client_secret'] = Sign::getSign($param);
        $urlList['brandList'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL, $param);

        return Yohobuy::getMulti($urlList, array(), 3600); // 有缓存1小时
    }
    

}