shop.js
6.49 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/**
* 店铺
*/
'use strict';
const _ = require('lodash');
const helpers = global.yoho.helpers;
const stringProcess = require(`${global.utils}/string-process`);
/**
* 频道
* @type {{}}
*/
const yhChannel = {
boys: 1,
girls: 2,
kids: 3,
lifestyle: 4
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 店铺品牌列表
*/
getShopBrands(shopId) {
return this.get({
data: {
method: 'app.shops.getShopsBrands',
shop_id: shopId
},
param: {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
*/
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 this.get({
data: finalParams
});
}
/**
* 根据品牌域名获取品牌LOGO
* @param {string} domain 品牌域名
* @return array | false
*/
getBrandLogoByDomain(domain) {
return this.get({
data: {
method: 'web.brand.byDomain',
domain: domain
},
param: {cache: true}
}).then(result => {
if (result && result.data) {
let formatData = result.data;
return {
id: formatData.id,
url: helpers.urlFormat('', null, formatData.brand_domain),
thumb: helpers.image(formatData.brand_ico, 75, 40),
name: formatData.brand_name,
shopId: formatData.shop_id ? formatData.shop_id : 0, // 店铺id
type: formatData.type ? formatData.type : 0,
brandDomain: formatData.brand_domain
};
} else {
return false;
}
});
}
/**
* 获取品牌信息数据
* @param {int} brandId 品牌ID
* @return array banner数据
*/
getBrandIntro(brandId, uid) {
let param = {
uid: uid
};
if (!brandId || brandId === '' || brandId === 'undefined') {
return Promise.resolve({});
}
return this.get({
data: _.assign({
method: 'app.brand.getBrandIntro',
brand_id: brandId
}, param),
param: {code: 200}
}).then(result => {
if (result && result.data) {
let list = result.data;
return {
id: list.brand_id,
intro: list.brand_intro,
collected: list.is_favorite && list.is_favorite === 'Y',
title: list.brand_name ? list.brand_name : ''
};
} else {
return false;
}
});
}
/**
* 获取品牌banner数据
* @param {int} brandId 品牌ID
* @return array banner数据
*/
getBrandBanner(brandId) {
return this.get({
data: {
method: 'app.brand.banner',
brand_id: brandId
},
param: {cache: true}
}).then((result) => {
if (result && result.code === 200 && result.data) {
if (result.data.banner) {
return helpers.image(result.data.banner, 640, 150);
} else {
return '';
}
} else {
return {};
}
});
}
/**
* 获取红人店铺 banner
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/商品列表/店铺装修.md
* @param int shopId 店铺id
*/
getBanner(shopId) {
let params = {
method: 'app.popular.shop.banner',
shop_id: shopId
};
return this.get({
data: params,
param: {cache: true, code: 200}
});
}
/**
* 查询红人店铺对应的装修元素
*
* @param int shopId 店铺id
*/
getShopsdecorator(shopId) {
let params = {
method: 'app.popular.shopsdecorator',
shop_id: shopId
};
return this.get({
data: params,
param: {cache: true, code: 200}
});
}
/**
* 获取店铺下面的所有分类
* @param {int} shopId 店铺id
* @param {string} channel 频道
* @return array
*/
getShopCategory(shopId, channel) {
return this.get({
data: {
method: 'app.shop.getSortInfo',
yh_channel: yhChannel[channel],
shop_id: shopId
}
});
}
/**
* 店铺收藏数量
*/
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 this.get({
data: finalParams
});
}
/**
* 获取非红人店铺的店铺装修数据
* @param {int} shopId 店铺id
* @return array
*/
getShopDecorator(shopId) {
return this.get({
data: {
method: 'app.shopsdecorator.getList',
shop_id: shopId
},
param: {
cache: true,
code: 200
}
}).then((result) => {
return (result && result.data) || {};
});
}
};