brand.js
3.01 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
/**
* 品牌一览
* @author: zxr
* @date: 2016/07/13
*/
'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);
let listKey = [];
_.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';
} else {
listKey.push(index);
}
// listData.push({
// key: index,
// brands: value
// });
});
listKey.sort();
listKey.push('0-9');
_.forEach(listKey, function(key) {
listData.push({
key: key,
brands: list.data.allList[key]
});
});
// console.log(listData)
return listData;
};
/**
* 品牌一览banner数据处理
* @returns {*}
*/
const _processTabData = (list) => {
let tabData = [];
list = list || [];
list = camelCase(list);
_.forEach(list, function(value, index) {
if (index === 1) {
_.forEach(value.data, function(data) {
tabData.push(
{
url: `${config.siteUrl}/product/list`,
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('The data of brand resources return code is not 200');
return {};
}
});
};
/**
* 获取品牌列表数据
* @param channel
* @returns {*}
*/
const _getBreakingSort = (channel, appType) => {
return api.get('', {
yh_channel: channel,
app_type: appType,
method: 'app.brand.newBrandList'
}).then((result) => {
if (result && result.code === 200) {
return _processListData(result);
} else {
logger.error('The data of brand resources return code is not 200');
return {};
}
});
};
/**
* 获取品牌一览相关数据
* @returns {*}
*/
const getListData = (contentCode, channel, appType) => {
return Promise.all([_getResources(contentCode), _getBreakingSort(channel, appType)])
.then((result) => {
return {
tabs: result[0],
category: result[1]
};
});
};
module.exports = {
getListData: getListData
};