outlet.js
3.61 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
/**
* 频道页面 model
* @author: Bi Kai<kai.bi@yoho.cn>
* @date: 2016/05/09
*/
'use strict';
const library = '../../../library';
const utils = '../../../utils';
const _ = require('lodash');
const ServiceAPI = require(`${library}/api`).ServiceAPI;
const API = require(`${library}/api`).API;
const sign = require(`${library}/sign`);
const productProcess = require(`${utils}/product-process`);
const camelCase = require(`${library}/camel-case`);
const resourcesProcess = require(`${utils}/resources-process`);
const log = require(`${library}/logger`);
const serviceApi = new ServiceAPI();
const api = new API();
const getOutletResource = () => {
const params = {
content_code: 'c19ffa03f053f4cac3690b22c8da26b7',
limit: 25,
debug: 'XYZ'
};
return serviceApi.get('operations/api/v5/resource/home', sign.apiSign(params)).then(result => {
if (result && result.code === 200) {
return resourcesProcess(result.data.list);
} else {
log.error('奥莱资源位接口返回状态码 不是 200');
return result;
}
});
};
const convertNavData = (list) => {
const formatData = [];
list = list || [];
list = camelCase(list);
_.forEach(list, (item) => {
formatData.push({
id: item.id,
name: item.sortName,
url: encodeURI(item.sortUrl)
});
});
return {data: formatData};
};
const getNavData = () => {
const params = {
client_type: 'iphone',
os_version: 8.4,
screen_size: '320x568',
v: 7,
parent_id: 1107,
debug: 'XYZ'
};
return api.get('operations/api/v6/category/getCategory', sign.apiSign(params)).then(result => {
if (result && result.code === 200) {
return convertNavData(result.data);
} else {
log.error('奥莱资源位接口返回状态码 不是 200');
return result;
}
});
};
const getGoodsList = () => {
var params = {
method: 'app.search.category',
limit: 50,
page: 1,
outlets: 1
};
var data = {};
return api.get('', sign.apiSign(params)).then(res => {
if (res && res.code === 200) {
data = productProcess.processProductList(res.data.product_list);
}
return data;
});
};
const getActivityDetail = () => {
var params = {
method: 'app.outlets.activityGet',
sort: 2,
platform: 2,
yh_channel: 1,
id: 170,
type: 0
};
return api.get('', sign.apiSign(params)).then(res => {
if (res.code === 200) {
return res.data;
} else {
log.error('获取奥莱活动详情页接口返回状态码 不是 200', res);
return {};
}
});
};
const getHomeActivity = () => {
var params = {
method: 'app.outlets.activityGet',
platform: 2,
size: 0,
yh_channel: 1,
type: 0,
sort: 2,
client_type: 'h5'
};
return api.get('', sign.apiSign(params)).then(res => {
return res;
});
};
exports.getContent = () => {
let floorsData = {};
return Promise.all([getNavData(), getOutletResource(), getHomeActivity(), getGoodsList()]).then(data => {
floorsData.nav = data[0] || [];
floorsData.content = data[1] || [];
floorsData.activity = data[2] || [];
floorsData.goods = data[3];
return floorsData;
});
};
exports.getActivity = () => {
return getActivityDetail().then(res => {
var data = {};
data.outletActivity = res;
return data;
});
};