shop-api.js 2.8 KB
/**
 * Created by PhpStorm.
 * User: Targaryen
 * Date: 2016/7/26
 * Time: 10:35
 */
'use strict';

const api = global.yoho.API;
const _ = require('lodash');

const yhChannel = {
    men: {
        channel: '1'
    },
    women: {
        channel: '2'
    },
    lifestyle: {
        channel: '4'
    }
};

module.exports = {
    /**
     * 通过品牌域名获取品牌信息
     * @param params
     */
    getBrandInfoByDomain(params) {
        return api.get('', {
            method: 'web.brand.byDomain',
            domain: params.domain
        }, {code: 200, cache: false});
    },

    /**
     * 从接口获取品牌店铺数据
     * @returns {*}
     */
    getShopInfoData(params) {
        let finalParams = {
            method: 'app.shops.getIntro',
            shop_id: params.shopId
        };

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

        return api.get('', finalParams, {code: 200, cache: false});
    },

    /**
     * 从接口获得店铺装修资源
     * @param params
     * @returns {*}
     */
    getShopsDecoratorList(params) {
        return api.get('', {
            method: 'app.shopsdecorator.getList',
            shop_id: params.shopId
        }, {code: 200, cache: false});
    },

    /**
     * 从接口获取品牌店铺商品数据
     * @returns {*}
     */
    getBrandShopGoodsOriginData(params) {
        let finalParams = {
            method: 'app.search.brand',
            yh_channel: params.channel ? yhChannel[params.channel].channel : '1',
            brand: params.brand,
            shop_id: params.shopId,
            order: params.order,
            limit: params.limit,
            page: params.page,
            gender: params.gender,
            color: params.color,
            price: params.price,
            size: params.size,
            p_d: params.pd,
            sort: params.sort,
            tags_filter: params.tagsFilter
        };

        /* 删除没有参数的条件 */
        _.forEach(finalParams, (value, key) => {
            if (!value) {
                delete finalParams[key];
            }
        });

        return api.get('', finalParams, {code: 200, cache: false});
    },

    /**
     * 收藏取消收藏店铺
     * @param params
     * @returns {*}
     */
    collectShopOriginData(params) {
        let finalParams = {
            id: params.id,
            fav_id: params.favId,
            uid: params.uid,
            type: params.type
        };

        if (params.isFav === 'true') {
            Object.assign(finalParams, {
                method: 'app.favorite.cancel'
            });
        } else {
            Object.assign(finalParams, {
                method: 'app.favorite.add'
            });
        }
        return api.get('', finalParams);
    }
};