brand.js
2.28 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
'use strict';
const api = global.yoho.API;
const camelCase = global.yoho.camelCase;
const _ = require('lodash');
const logger = global.yoho.logger;
const serviceAPI = global.yoho.ServiceAPI;
const config = global.yoho.config;
const _processListData = (list) => {
let listData = [];
list = list || [];
list = camelCase(list);
_.forEach(list.data.allList, function(value, index) {
_.forEach(value, function(data) {
data.brandDomain = `${config.siteUrl}/product/shop/${data.brandDomain}`;
});
if (index === '0~9') {
index = '0-9';
}
listData.push(
{
key: index,
brands: value
}
);
});
return listData;
};
const _processTabData = (list) => {
let tabData = [];
list = list || [];
list = camelCase(list);
_.forEach(list, function(value, index) {
if (index === 0) {
_.forEach(value.data, function(data) {
tabData.push(
{
url: data.url,
name: data.title,
src: data.src
}
);
});
}
});
return tabData;
};
const _getResources = (contentCode) => {
return serviceAPI.get('operations/api/v5/resource/get', {content_code: contentCode}).then((result) => {
if (result && result.code === 200) {
return _processTabData(result.data);
} else {
logger.error('品牌资源数据返回 code 不是 200');
return {};
}
});
};
const _getBreakingSort = (channel) => {
return api.get('', {
yo_channel: channel,
method: 'app.brand.newBrandList'
}).then((result) => {
if (result && result.code === 200) {
return _processListData(result);
} else {
logger.error('品牌页数据返回 code 不是 200');
return {};
}
});
};
const getListData = (contentCode, channel) => {
return Promise.all([_getResources(contentCode), _getBreakingSort(channel)])
.then((result) => {
return {
tabs: result[0],
category: result[1]
};
});
};
module.exports = {
getListData: getListData
};