shop.js
1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* 店铺
*/
'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
};