popular-shop.js 2 KB
/**
 *  desc: 店铺装修----红人店铺
 */
'use strict';

const api = global.yoho.API;
const singleAPI = global.yoho.SingleAPI;
const stringProcess = require(`${global.utils}/string-process`);

/**
 * 频道
 * @type {{}}
 */
const yhChannel = {
    boys: 1,
    girls: 2,
    kids: 3,
    lifestyle: 4
};

/**
 *  获取红人店铺 banner
 *  doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/商品列表/店铺装修.md
 *  @param int shopId 店铺id
 */
exports.getBanner = shopId => {
    let params = {
        method: 'app.popular.shop.banner',
        shop_id: shopId
    };

    return api.get('', params, {cache: true, code: 200});
};

/**
 * 获取店铺 介绍
 * @param int shopId 店铺id
 */
exports.getIntro = shopId => {
    let params = {
        method: 'app.shops.getIntro',
        shop_id: shopId
    };

    if (!shopId || !stringProcess.isNumeric(shopId)) {
        return Promise.resolve({});
    }

    return api.get('', params, {cache: true, code: 200});
};


/**
 *  查询红人店铺对应的装修元素
 *
 *  @param int shopId 店铺id
 */
exports.getShopsdecorator = shopId => {
    let params = {
        method: 'app.popular.shopsdecorator',
        shop_id: shopId
    };

    return api.get('', params, {cache: true, code: 200});
};

/**
 * 获取店铺下面的所有分类
 * @param {int} shopId 店铺id
 * @param {string} channel 频道
 * @return array
 */
exports.getShopCategory = (shopId, channel) => {
    return api.get('', {
        method: 'app.shop.getSortInfo',
        yh_channel: yhChannel[channel],
        shop_id: shopId
    });
};

/**
 * 店铺收藏数量
 */
exports.favCount = (shopId, uid, channel, udid) => {
    let finalParams = {
        method: 'app.favorite.queryFavoriteCountByShopIds',
        favIds: shopId,
        type: 'shop',
        udid: udid,
        physical_channel: yhChannel[channel],
    };

    if (uid) {
        Object.assign(finalParams, {
            uid: uid
        });
    }

    return singleAPI.get('favorite', finalParams);
};