shop.js 1.41 KB
/**
 * 店铺
 */
'use strict';
const _ = require('lodash');
const helpers = global.yoho.helpers;
const api = global.yoho.API;
const stringProcess = require(`${global.utils}/string-process`);

/**
 * 店铺品牌列表
 */
const getShopBrands = (shopId) => {
    return api.get('', {
        method: 'app.shops.getShopsBrands',
        shop_id: shopId
    }, {code: 200}).then(result => {
        if (result && result.data) {
            _.forEach(result.data, value => {
                value.url = helpers.urlFormat('', {
                    shop_id: shopId,
                    brand: value.brand_id,
                    title: value.brand_name
                }, 'list');
            });

            return result.data;
        } else {
            return [];
        }
    });
};

/**
 * 获取店铺信息
 * @param {int} shopId 店铺id
 * @param {int} uid 用户id 判断用户是否收藏店铺
 * @return array
 */
const getShopInfo = (shopId, uid) => {
    let finalParams = {
        method: 'app.shops.getIntro',
        shop_id: shopId,
    };

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

    if (uid && uid !== 'undefined') {
        Object.assign(finalParams, {
            uid: uid
        });
    }

    return api.get('', finalParams, {code: 200}).then((result) => {
        return result && result.data;
    });
};

module.exports = {
    getShopBrands,
    getShopInfo
};