brands-api.js 3.42 KB
/**
 * 品牌一览 api
 * @author: ghw<hongwei.gao@yoho.cn>
 * @date: 2016/9/29
 */
'use strict';

module.exports = class extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }

    /**
     * 分开取数,品牌一览 顶部的轮翻广告及热门品牌数据-PC
     * 顶部的轮翻广告及热门品牌数据
     *  @param string $contentCode 获取广告资源需要的位置码
     */
    getBrandTopData(contentCode) {
        return this.get({
            url: 'operations/api/v5/resource/get',
            data: {
                content_code: contentCode
            },
            param: {
                cache: true
            },
            api: global.yoho.ServiceAPI
        });
    }

    /**
     * 分开取数,获取品牌一览 "按字母'A-Z'分组的品牌列表数据"
     * @param int $channel 频道标识 1:男,2:女,3:潮童,4:创意生活
     */
    getBrandListData(channel) {

        let data = {
            method: 'app.brand.allBrandList'
        };

        if (!isNaN(channel)) {
            data.yh_channel = channel;
        }

        return this.get({
            data: data,
            param: {
                code: 200,
                cache: true
            }
        });
    }

    /**
     * 获取品牌简介
     *
     * @param  integer $brandId 品牌ID
     * @param  int 用户ID
     * @return array  品牌介绍信息
     */
    getBrandIntro(brandId, uid) {

        let data = {
            method: 'app.brand.getBrandIntro',
            brand_id: brandId,
            uid: uid
        };

        if (!uid) {
            data.cache = 3600;
        }

        return this.get({
            data: data,
            param: {
                code: 200,
                cache: true
            }
        });
    }

    /**
     * 获取品牌中产品图片
     * @param  int 品牌ID
     * @return array  品牌产品信息
     */
    getProductByBrand(brandId, limit) {

        let data = {
            method: 'web.search.search',
            brand: brandId,
            limit: limit
        };

        return this.get({
            data: data,
            param: {
                code: 200,
                cache: true
            }
        });
    }

    /**
     * 获取品牌信息
     *
     * @param array $ids
     * @return array
     */
    getBrandInfoByIds(ids) {

        let data = {
            method: 'web.brand.info',
            ids: ids instanceof Array ? ids.join(',') : parseInt(ids, 10)
        };

        return this.get({
            data: data,
            param: {
                code: 200,
                cache: true
            }
        });
    }

    /**
     * 获取品牌列表
     *
     * @param int $brandType
     * @param string $gender
     * @param string $type
     * @return array
     */
    getPlusstarList(brandType, gender) {
        return this.get({
            url: 'guang/api/v3/plustar/getlist',
            data: {
                gender: gender,
                brand_type: brandType
            },
            param: {
                cache: true
            },
            api: global.yoho.ServiceAPI
        });
    }

    getPlusstarBrandListItem(code) {
        return this.get({
            url: 'operations/api/v5/resource/get',
            data: {
                content_code: code
            },
            param: {
                cache: 3600
            },
            api: global.yoho.ServiceAPI
        });
    }

};