brand.js
2.58 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
'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;
/**
* 品牌一览列表数据处理
* @returns {*}
*/
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;
};
/**
* 品牌一览banner数据处理
* @returns {*}
*/
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;
};
/**
* 获取品牌banner
* @param channel
* @returns {*}
*/
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 {};
}
});
};
/**
* 获取品牌列表数据
* @param channel
* @returns {*}
*/
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 {};
}
});
};
/**
* 获取品牌一览相关数据
* @returns {*}
*/
const getListData = (contentCode, channel) => {
return Promise.all([_getResources(contentCode), _getBreakingSort(channel)])
.then((result) => {
return {
tabs: result[0],
category: result[1]
};
});
};
module.exports = {
getListData: getListData
};