BrandData.php 5.01 KB
<?php

namespace LibModels\Wap\Category;

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';

    /**
     * 封装获取品牌一览页面的数据
     * 
     * @param string $contentCode 获取广告资源需要的位置码
     * @param int $channel 频道标识 1:男,2:女,3:潮童,4:创意生活
     * @return array(
     *     "brandTop": "顶部的轮翻广告及热门品牌数据",
     *     "brandList": "按字母'A-Z'分组的品牌列表数据"
     * )
     * @author fei.hong <fei.hong@yoho.cn>
     */
    public static function package($contentCode, $channel)
    {
        $urlList = array();
        
        /* 顶部的轮翻广告及热门品牌数据 */
        $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);
    }
    
    /**
     * 获取品牌数据
     * 
     * @param integer $channel 是否,默认1表示是,传值为空是app中用于品牌搜索的数据
     * @return array 品牌数据
     */
    public static function getBrandsData($channel = 1)
    {
        // 构建必传参数
        $param = Yohobuy::param();
        $param['method'] = 'app.brand.brandlist';
        $param['yh_channel'] = $channel;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 获取品牌页顶部楼层数据
     * 
     * @param string $contentCode 位置码
     * @return array 品牌也顶部楼层数据
     */
    public static function getBrandTopData($contentCode)
    {
        // 构建必传参数
        $param = Yohobuy::param();
        $param['content_code'] = $contentCode;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::SERVICE_URL . self::URI_BRAND_TOPPOS, $param);
    }

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

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 获取品牌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);
    }

    /**
     * 查询品牌数据
     * 
     * @param  string $gender     "1,3"表示男, "2,3"表示女, "1,2,3"表示全部
     * @param  integer $brand    品牌Id
     * @param  integer $sort     品类Id
     * @param  integer $color    颜色Id
     * @param  integer $size     尺码Id
     * @param  string $price     价格
     * @param  string $p_d       折扣
     * @param  string $order     排序方式,默认s_t_desc
     * @param  integer $limit    限制查询的数目,默认为60
     * @param  integer $page     查询第几页,默认为第1页
     * @param  integer $channel  表示频道号,1位男生,2为女生
     * @return array             品牌数据
     */
    public static function selectBrandDetail($gender, $brand, $sort, $color, $size, $price, $p_d, $channel = 1, $order = 's_t_desc', $limit = 60, $page = 1)
    {
        $selectItems = array(
            'gender' => $gender,
            'brand' => $brand,
            'sort' => $sort,
            'color' => $color,
            'size' => $size,
            'price' => $price,
            'p_d' => $p_d
        );
        // 拉取筛选参数
        $queriedParams = array_filter($selectItems, function($v) {
            return $v !== null;
        });

        // 构建必传参数
        $param = Yohobuy::param();

        $param['method'] = 'app.search.brand';
        $param['page'] = $page;
        $param['limit'] = $limit;
        $param['yh_channel'] = $channel;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

}