outlets.js
11 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
/*
* @Author: Targaryen
* @Date: 2016-05-30 16:20:03
* @Last Modified by: Targaryen
* @Last Modified time: 2016-06-08 19:56:39
*/
'use strict';
const Promise = require('bluebird');
const utils = '../../../utils';
const List = require('./list');
const outletsProcess = require('./outlets-handler');
const OutletsApiModel = require('./outlets-api');
const productProcess = require(`${utils}/product-process`);
const HeaderModel = require('../../../doraemon/models/header');
const _ = require('lodash');
const publicHandler = require('./public-handler');
const log = global.yoho.logger;
// 奥莱频道资源码
const channelCode = {
index: 'e0565dad65fb8da1f39bc1ac83fc8346',
boys: '2af513637dc5feeec7f6f8b52989b24b',
girls: 'd1b56b56c3a12dc1f2f83958680a0911',
kids: '0fd7ad594940f9ec5a03697317cf6521',
lifestyle: 'b3d3f55a26f130ac2b516b9fb3823711'
};
/**
* 获取奥莱首页数据
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
function getOutletsIndexData(params, channel) {
return Promise.all([
this.headerModel.requestHeaderData('outlets'),
this.outletsApi.getChannelResouceData({content_code: channelCode.index}),
this.outletsApi.getOutletsActivityOrigin({type: '1', channel: channel}), // 获取限时活动列表
this.outletsApi.getOutletsActivityOrigin({type: '2', channel: channel}), // 获取即将结束列表
this.outletsApi.getOutletsTrendData({limit: '30', channel: channel}), // 获取潮流速递商品数据
this.outletsApi.getOutletsActivityOrigin({type: '3', channel: channel}) // tar add 16171552 即将上线数据
]).then(result => {
let finalResult = {
headerData: Object.assign(result[0].headerData, {
header: true,
headType: 'outlets'
})
};
// 处理资源位数据
if (result[1].code === 200 && !_.isEmpty(result[1].data)) {
finalResult = Object.assign(finalResult,
outletsProcess.handleOutletsBannersData(result[1].data, params));
}
// 处理限时嗨购列表数据
if (result[2].code === 200 && !_.isEmpty(result[2].data)) {
finalResult.limitedBuy = Object.assign(finalResult.limitedBuy,
outletsProcess.handleOutletsActivityData(result[2].data, '限时嗨购'));
}
// 处理即将结束列表数据
if (result[3].code === 200 && !_.isEmpty(result[3].data)) {
finalResult.nearOver = outletsProcess.handleOutletsActivityData(result[3].data, '即将结束');
}
// 处理潮品推荐数据
if (result[4].code === 200 && !_.isEmpty(result[4].data)) {
finalResult.limitedBuy.extra.trendGood = outletsProcess.handleOutletstrendGoodData(result[4].data);
}
// 处理即将上架品牌数据
if (result[5].code === 200 && !_.isEmpty(result[5].data)) {
finalResult.limitedBuy.extra.comeSoon = outletsProcess.handleComeSoonData(result[5].data);
}
// 如果后台没配分类,不显示商品列表
if (!finalResult.goodsBoard.goodsMenu.msort && !finalResult.goodsBoard.goodsMenu.msort) {
log.info('no config index sort');
return finalResult;
}
// 获取底部商品数据
if (!params.msort && !params.misort) {
Object.assign(
params,
{msort: _.uniq(finalResult.goodsBoard.goodsMenu.msort).join()}
);
}
return Promise.all([
this.outletsApi.getOutletsGoodsList(Object.assign(
params,
{limit: params.limit || '100', channel: channel, method: 'app.search.category'}
))
]).then(data => {
// 处理底部商品数据
if (data[0].code === 200 && !_.isEmpty(data[0].data)) {
Object.assign(finalResult.goodsBoard, {
sort: Object.assign(publicHandler.handleSaleOptsData(params, data[0].data.total), {newPage: true}),
list: productProcess.processProductList(data[0].data.product_list)
});
// 添加锚点
if (finalResult.goodsBoard.sort.sortType) {
_.forEach(finalResult.goodsBoard.sort.sortType, (value, key) => {
finalResult.goodsBoard.sort.sortType[key].href += '#otspool';
});
if (finalResult.goodsBoard.sort.preHref) {
finalResult.goodsBoard.sort.preHref += '#otspool';
}
if (finalResult.goodsBoard.sort.nextHref) {
finalResult.goodsBoard.sort.nextHref += '#otspool';
}
}
finalResult.goodsBoard.footPager = publicHandler.handlePagerData(data[0].data.total, params);
}
return finalResult;
});
});
}
/**
* 获取奥莱频道页面数据
* @param {[object]} gender
* @return {[type]}
*/
function getOutletsChannelData(params, channel) {
// 频道资源位不存在
if (!channelCode[channel]) {
return Promise.reject(`outlets channel-(${channel}) resource not found`);
}
let channelData = {};
let apiArr = [
// 获取头部数据
this.headerModel.requestHeaderData('outlets'),
// 获取频道资源位
this.outletsApi.getChannelResouceData({content_code: channelCode[channel]}),
// 获取奥莱活动
this.outletsApi.getOutletsActivityOrigin({
platform: 1,
size: 0,
channel: channel,
type: 1
})
];
return Promise.all(apiArr).then(result => {
// 返回页面的数据
let finalResult = {
headerData: Object.assign(result[0].headerData, {
header: true,
headType: 'outlets'
})
};
Object.assign(channelData, finalResult);
// 资源楼层
if (result[1].code === 200) {
Object.assign(channelData, outletsProcess.processFloor(result[1].data.list, params));
}
// 限时嗨购
if (result[2].code === 200 && !_.isEmpty(result[2].data)) {
channelData.nearOver = outletsProcess.handleOutletsActivityData(result[2].data, '限时嗨购');
}
// 如果后台没配分类,不显示商品列表
if (!channelData.goodsBoard || !channelData.goodsBoard.goodsMenu ||
(!channelData.goodsBoard.goodsMenu.msort && !channelData.goodsBoard.goodsMenu.msort)) {
log.info('no config ' + channel + 'channel sort');
return channelData;
}
// 获取底部商品数据
if (!params.msort || !params.misort) {
Object.assign(
params,
{msort: _.uniq(channelData.goodsBoard.goodsMenu.msort).join()}
);
}
return Promise.all([
this.outletsApi.getOutletsGoodsList(Object.assign(
params,
{limit: params.limit || '100', channel: channel, method: 'app.search.category'}
))
]).then(data => {
if (data[0].code === 200) {
if (!channelData.goodsBoard) {
channelData.goodsBoard = {};
}
channelData.goodsBoard.sort = publicHandler.handleSaleOptsData(params, data[0].data.total);
channelData.goodsBoard.sort.newPage = true;
channelData.goodsBoard.list = productProcess.processProductList(data[0].data.product_list);
channelData.goodsBoard.pager = publicHandler.handlePagerData(data[0].data.total, params);
// 添加锚点
if (channelData.goodsBoard.sort.sortType) {
_.forEach(channelData.goodsBoard.sort.sortType, (value, key) => {
channelData.goodsBoard.sort.sortType[key].href += '#otspool';
});
if (channelData.goodsBoard.sort.preHref) {
channelData.goodsBoard.sort.preHref += '#otspool';
}
if (channelData.goodsBoard.sort.nextHref) {
channelData.goodsBoard.sort.nextHref += '#otspool';
}
}
}
return channelData;
});
});
}
/**
* 获取奥莱活动页面数据
* @param {[object]}
* @return {[type]}
*/
function getOutletsSpecialData(params, channel) {
return Promise.all([
this.headerModel.requestHeaderData('outlets'),
this.outletsApi.getOutletsActivityOrigin({ // 获取活动信息
id: params.id
})
]).then(result => {
let specialData = {};
Object.assign(specialData, result[0]);
specialData.headerData.headType = 'outlets';
// 活动信息获取异常
if (result[1].code !== 200) {
return Promise.reject(`outlets special info not found-(ID:${params.id})`);
}
Object.assign(specialData,
outletsProcess.handleOutletsSpecilData(result[1].data[0]));
return Promise.all([
this.list.getListData(Object.assign({
productPool: result[1].data[0].productPoolId,
saleType: 4
}, params), channel)
]).then(data => {
specialData.specialHead.count = data[0].totalCount;
Object.assign(specialData, data[0]);
return specialData;
});
});
}
/**
* 获取奥莱分类页面数据
* @param {[type]} params [description]
* @param {[type]} channel [description]
* @return {[type]} [description]
*/
function getOutletsCategoryData(params, channel) {
return Promise.all([
this.headerModel.requestHeaderData('outlets')
]).then(result => {
let finalResult = {
headerData: Object.assign(result[0].headerData, {
header: true,
headType: 'outlets'
})
};
return Promise.all([
this.list.getListData(params, channel)
]).then(listResult => {
finalResult.saleList = listResult[0];
if (!_.isEmpty(params.bannerImage)) {
finalResult.saleList.topBanner = {
list: [
{
img: params.bannerImage
}
]
};
}
return finalResult;
});
});
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.list = new List(ctx);
this.outletsApi = new OutletsApiModel(ctx);
this.headerModel = new HeaderModel(ctx);
this.getOutletsIndexData = getOutletsIndexData.bind(this);
this.getOutletsChannelData = getOutletsChannelData.bind(this);
this.getOutletsSpecialData = getOutletsSpecialData.bind(this);
this.getOutletsCategoryData = getOutletsCategoryData.bind(this);
}
};