brand.js
9.56 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
/**
* 品牌页
* @param params
* @returns {function()}
*/
'use strict';
var api = global.yoho.API;
const service = global.yoho.ServiceAPI;
const helpers = global.yoho.helpers;
// const utils = '../../../utils';
// const floorProcess = require(`${utils}/floor-process`);
/* 男生频道取品牌广告及热门品牌数据的位置码 */
let CODE_TOPPOS_BOYS = 'ce6ac059493ec26241a8cbe0bfa1b17a';
/* 女生频道取品牌广告及热门品牌数据的位置码 */
let CODE_TOPPOS_GIRLS = 'dac99cdedc1f948e84c145aca561f7d2';
/* 潮童频道取品牌广告及热门品牌数据的位置码 */
let CODE_TOPPOS_KIDS = '713784f93f52bb1a7b93916b2bb15510';
/* 创意生活频道取品牌广告及热门品牌数据的位置码 */
let CODE_TOPPOS_LIFESTYLE = 'f1aa914fd23cbcda71a87de6f5416c75';
/**
* 获取频道接口
*/
const _packageAd = (params) => {
return service.get('/operations/api/v5/resource/get', {
content_code: params.contentCode,
gender: 1,
limit: 1000,
page: 1
}).then(result => {
return result;
});
};
const _packageList = (params) => {
return api.get('', {
method: 'app.brand.newBrandList',
yh_channel: params.channel
}, { code: 200 }).then(result => {
return result;
});
};
const getBrandByChannel = (channel) => {
let params = {};
/* 根据频道调用接口 */
switch (channel) {
case '1': // 男生
params = {
contentCode: CODE_TOPPOS_BOYS,
channel: 1
};
break;
case '2': // 女生
params = {
contentCode: CODE_TOPPOS_GIRLS,
channel: 2
};
break;
case '3': // 潮童
params = {
contentCode: CODE_TOPPOS_KIDS,
channel: 3
};
break;
case '4': // 创意生活
params = {
contentCode: CODE_TOPPOS_LIFESTYLE,
channel: 4
};
break;
default:
}
return api.all([
_packageAd(params),
_packageList(params)
]).then(result => {
let resu = {
channel: {
channels: [{
name: 'Boy'
}, {
name: 'Girl'
}, {
name: 'Kid'
}, {
name: 'Lifestyle'
}],
topData: {
bannerTop: {},
hotBrandsScroll: {}
},
searchUrl: helpers.urlFormat('/brands/search', null),
brandPage: true,
// pageFooter: true,
showDownloadApp: true,
brandType: '全部品牌',
secondBrandType: '新入驻品牌',
thirdBrandType: '热门品牌',
brandList: [],
newBrandWall: [],
recommandBrandWall: []
}
};
resu.channel.channels[channel - 1].active = true;
if (result && result[0] && result[0].data) {
if (result[0].data[0] && result[0].data[0].data) {
// 轮播图资源位
let adList = result[0].data[0].data;
let build = [];
adList.forEach(ad => {
build.push({
img: helpers.image(ad.src, 640, 240),
url: ad.url
});
});
resu.channel.topData.bannerTop.list = build;
}
if (result[0].data[1] && result[0].data[1].data) {
// 推荐品牌资源位
let brandList = result[0].data[1].data.list;
let brand = [];
brandList.forEach(ad => {
brand.push({
img: helpers.image(ad.src, 140, 140),
url: ad.url,
textCn: ad.title
});
});
resu.channel.topData.hotBrandsScroll.name = result[0].data[1].data.title.title;
resu.channel.topData.hotBrandsScroll.list = brand;
}
}
/* 按字母'A-Z'分组的品牌列表 */
if (result && result[1] && result[1].data) {
let allList = result[1].data.all_list;
for (let key in allList) {
let obj = {};
obj = Object.assign(obj, {title: key});
let list = [];
allList[key].forEach(row => {
list.push({
name: row.brand_name,
isHot: row.is_hot === 'Y' ? true : false,
isNew: row.is_show_new === 'Y' ? true : false,
url: helpers.urlFormat('', null, row.brand_domain)
});
});
obj = Object.assign(obj, {list});
resu.channel.brandList.push(obj);
}
}
// 新入驻品牌
if (result && result[1] && result[1].data) {
let newList = result[1].data.new_list;
for (let key in newList) {
let obj = {};
let list = [];
list.push({
brandName: newList[key].brand_name,
url: helpers.urlFormat('', null, newList[key].brand_domain),
img: helpers.image(newList[key].brand_ico, 186, 115),
});
obj = Object.assign(obj, {list});
resu.channel.newBrandWall.push(obj);
}
}
// 推荐品牌
if (result && result[1] && result[1].data) {
let hotList = result[1].data.hot_list;
for (let key in hotList) {
let obj = {};
let list = [];
list.push({
brandName: hotList[key].brand_name,
url: helpers.urlFormat('', null, hotList[key].brand_domain),
img: helpers.image(hotList[key].brand_ico, 186, 115),
});
obj = Object.assign(obj, {list});
resu.channel.recommandBrandWall.push(obj);
}
}
return resu;
});
};
/**
* 获取搜索的品牌列表
*
* @param int $channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
* @return array
*/
const getBrandForSearch = (channel) => {
return api.get('', {
method: 'app.brand.brandlist',
yh_channel: channel || 1
}, { code: 200 }).then(result => {
return result;
});
};
/**
* 品牌搜索历史
* @param int $uid
* @author sefon 2016-5-17 12:12:28
* @return array
*/
const branchSearchHistory = (params) => {
return api.get('', {
method: 'app.search.hotBrandRecords',
uid: params.uid,
records: params.uid || ''
}, { code: 200 }).then(result => {
let resu = {
data: {
list: [
{
name: '111',
searchTime: '111'
},
{
name: '22',
searchTime: '22'
}
]
}
};
// console.log(resu);
return resu;
});
};
/**
* 热搜品牌
* @author sefon 2016-5-17 12:20:26
* @return array
*/
const branchSearchHot = () => {
return api.get('', {
method: 'app.search.hotBrands'
}, { code: 200 }).then(result => {
return result;
});
};
/**
* 获取搜索的品牌列表
*
* @param int $channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
* @return array
*/
const branchSearch = (params) => {
return api.all([
getBrandForSearch(params.channel),
branchSearchHistory(params),
branchSearchHot(),
]).then(result => {
let resu = {
brandPage: true,
showDownloadApp: true,
pageFooter: true,
hot: [],
history: [],
brandList: []
};
if (result && result[0] && result[0].data) {
let brandList = result[0].data.brands;
let obj = {};
for (let key in brandList) {
let build = [];
brandList[key].forEach(row => {
build.push({
name: row.brand_name,
isHot: row.is_hot === 'Y' ? true : false,
isNew: row.is_show_new === 'Y' ? true : false,
url: helpers.urlFormat('', null, row.brand_domain),
brandId: row.id,
brandDomain: row.brand_domain,
searchName: row.brand_name_en + row.brand_name_cn
});
obj[key] = build;
});
}
resu.brandList = JSON.stringify(obj);
}
if (result && result[2] && result[2].data) {
let hotList = result[2].data;
for (let key in hotList) {
let obj = {};
obj = Object.assign(obj, {name: hotList[key].brandName});
resu.hot.push(obj);
}
}
if (result && result[1] && result[1].data) {
let hisList = result[1].data;
resu.history.push(hisList);
}
return resu;
});
};
module.exports = {
getBrandByChannel,
branchSearch
};