outlets.js
5.29 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
/*
* @Author: Targaryen
* @Date: 2016-05-30 16:20:03
* @Last Modified by: Targaryen
* @Last Modified time: 2016-06-03 18:04:43
*/
'use strict';
const library = '../../../library';
const utils = '../../../utils';
const API = require(`${library}/api`).API;
const api = new API();
const list = require('./list');
const saleApi = require('./sale-api');
const outletsProcess = require('./outlets-handler');
const outletsApi = require('./outlets-api');
const productProcess = require(`${utils}/product-process`);
const headerModel = require('../../../doraemon/models/header');
const publicHandler = require('./public-handler');
// 奥莱频道资源码
const channelCode = {
index: 'e0565dad65fb8da1f39bc1ac83fc8346',
boys: '2af513637dc5feeec7f6f8b52989b24b',
girls: 'd1b56b56c3a12dc1f2f83958680a0911',
kids: '0fd7ad594940f9ec5a03697317cf6521',
lifestyle: 'b3d3f55a26f130ac2b516b9fb3823711'
};
/**
* 获取奥莱首页数据
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
exports.getOutletsIndexData = (params) => {
return api.all([
headerModel.requestHeaderData('outlets'),
outletsApi.getChannelResouceData({ content_code: channelCode.index }),
outletsApi.getOutletsActivityOrigin(params), // 获取限时活动列表
outletsApi.getOutletsActivityOrigin(params), // 获取即将结束列表
outletsApi.getOutletsTrendData(params), // 获取潮流速递商品数据
saleApi.getSaleGoodsList(params) // 获取底部商品数据
]).then(result => {
let finalResult = result[0];
// 处理资源位数据
if (result[1].code === 200) {
finalResult = Object.assign(finalResult,
outletsProcess.handleOutletsBannersData(result[1].data));
}
// 处理限时嗨购列表数据
if (result[2].code === 200) {
finalResult.limitedBuy = Object.assign(finalResult.limitedBuy,
outletsProcess.handleOutletsActivityData(result[2].data, '限时嗨购'));
}
// 处理即将结束列表数据
if (result[3].code === 200) {
finalResult.nearOver = outletsProcess.handleOutletsActivityData(result[3].data, '即将结束');
}
// 处理潮品推荐数据
if (result[4].code === 200) {
finalResult.limitedBuy.extra.trendGood = outletsProcess.handleOutletstrendGoodData(result[4].data);
}
// 处理底部商品数据
if (result[5].code === 200) {
finalResult.goodsBoard.list = productProcess.processProductList(result[5].data.product_list);
finalResult.pager = publicHandler.handleSalePagerData(result[5].data.total, params);
}
return finalResult;
});
};
/**
* 获取奥莱频道页面数据
* @param {[object]} gender
* @return {[type]}
*/
exports.getOutletsChannelData = (params) => {
let channelData = {};
let apiArr = [
headerModel.requestHeaderData('outlets')
];
if (channelCode[params]) {
apiArr.push(outletsApi.getChannelResouceData({
content_code: channelCode[params.channel]
}));
apiArr.push(outletsApi.getOutletsActivityOrigin({
platform: 2,
size: 0,
type: 1
}));
apiArr.push(saleApi.getSaleGoodsList(params));
} else {
// 错误页面
channelData.pageErr = true;
}
return api.all(apiArr).then(result => {
Object.assign(channelData, result[0]);
if (!channelData.pageErr) {
// 资源楼层
if (result[1].code === 200) {
Object.assign(channelData, outletsProcess.processFloor(result[1].data.list));
}
// 限时嗨购
if (result[2].code === 200) {
channelData.nearOver = outletsProcess.handleOutletsActivityData(result[2].data);
channelData.nearOver.name = '限时嗨购';
}
// 商品列表
if (result[3].code === 200) {
channelData.goodsBoard = {};
channelData.goodsBoard.list = productProcess.processProductList(result[3].data.product_list);
channelData.pager = publicHandler.handleSalePagerData(result[3].data.total, params);
}
}
return channelData;
});
};
/**
* 获取奥莱活动页面数据
* @param {[object]}
* @return {[type]}
*/
exports.getOutletsSpecialData = (params) => {
return api.all([
headerModel.requestHeaderData('outlets'),
outletsApi.getOutletsActivityOrigin({
id: params.id
})
]).then(result => {
let specialData = result[0];
specialData.pageErr = true;
if (result[1].code === 200) {
delete specialData.pageErr;
Object.assign(specialData,
outletsProcess.handleOutletsSpecilData(result[1].data[0]));
return api.all([
list.getSaleOthersData({
productPool: result[1].data[0].productPoolId,
saleType: 4
})
]).then(data => {
specialData.specialHead.count = data[0].totalCount;
Object.assign(specialData, data[0]);
return specialData;
});
}
return specialData;
});
};