sale.js
10 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
/*
* @Author: Targaryen
* @Date: 2016-05-19 10:20:08
* @Last Modified by: Targaryen
* @Last Modified time: 2016-06-01 18:28:12
*/
'use strict';
const library = '../../../library';
const utils = '../../../utils';
const API = require(`${library}/api`).API;
const api = new API();
const saleApi = require('./sale-api');
const saleHandler = require('./sale-handler');
const productProcess = require(`${utils}/product-process`);
const _ = require('lodash');
/**
* 获取Sale首页商品列表数据 仅 Ajax 调用 Controller 调用
* @return {[type]} [description]
*/
exports.getSaleGoodsData = (params) => {
return api.all([
saleApi.getSaleGoodsList(params),
saleApi.getUserProfile(params.uid)
]).then(result => {
let finalResult = {};
if (result[0].code === 200) {
finalResult.goods = productProcess.processProductList(result[0].data.product_list);
switch (params.saleType) {
case '1':
finalResult.goods.push({
thumb: 'http://img10.static.yhbimg.com/product/2014/01/15/11/01fa01614784f6239760f1b749663016f1.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/90',
url: 'http://localhost:6002/product/sale/breakingYards'
});
break;
case '2':
finalResult.goods.push({
thumb: 'http://img10.static.yhbimg.com/product/2014/01/15/11/01fa01614784f6239760f1b749663016f1.jpg?imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/background/d2hpdGU=/position/center/quality/90',
url: 'http://localhost:6002/product/sale/vip'
});
break;
default:
break;
}
}
// 处理 VIP 商品数据
if (result[1].code === 200 && parseInt(params.saleType, 10) === 2) {
_.forEach(finalResult.goods, (value, key) => {
switch (result[1].curLevel) {
case '1':
finalResult.goods[key].vipPrice = value.vip1_price;
finalResult.goods[key].vip1 = true;
break;
case '2':
finalResult.goods[key].vipPrice = value.vip2_price;
finalResult.goods[key].vip2 = true;
break;
case '3':
finalResult.goods[key].vipPrice = value.vip3_price;
finalResult.goods[key].vip3 = true;
break;
default:
finalResult.goods[key].vipPrice = value.vip_price;
finalResult.goods[key].vip = true;
break;
}
});
}
return finalResult;
});
};
/**
* 获取 Sale 首页数据 Controller 调用
* @return {[type]} [description]
*/
exports.getSaleIndexData = () => {
return api.all([
saleApi.getSaleActivityList(),
saleApi.getSaleBannerList('7c2b77093421efa8ae9302c91460db73')
]).then(result => {
var finalResult = {};
if (result[0].code === 200) {
finalResult.brandSale = saleHandler.handleSaleActivityData(result[0].data);
}
if (result[1].code === 200) {
finalResult.topBanner = saleHandler.handleSaleBannerData(result[1].data);
finalResult.activityEnter = saleHandler.handleSaleBannerSmallData(result[1].data);
}
finalResult.saleCategory = saleHandler.handleSaleCategoryData();
return finalResult;
});
};
/**
* 获取 VIP 会员专享和新降价专区数据 Controller 调用
* @return {[type]} [description]
*/
exports.getSaleOthersData = (params) => {
let promiseObject;
// cCode 是资源位代码,根据页面不同传不同的 CODE,目前一样,待处理
// saleType: 1表示断码区,2表示会员专区,3 折扣专区,4表示奥莱
let cCode;
if (!_.isEmpty(params) && params.saleType === 2) {
cCode = '7c2b77093421efa8ae9302c91460db73';
promiseObject = [
saleApi.getSaleGoodsList(params),
saleApi.getSaleBannerList(cCode),
saleApi.getLeftContentList(),
saleApi.getUserProfile(params.uid)
];
} else {
cCode = '7c2b77093421efa8ae9302c91460db73';
promiseObject = [
saleApi.getSaleGoodsList(params),
saleApi.getSaleBannerList(cCode),
saleApi.getLeftContentList()
];
}
return api.all(promiseObject).then(result => {
let finalResult = {};
// 获取商品数据和顶部筛选条件
if (result[0].code === 200) {
finalResult.goods = productProcess.processProductList(result[0].data.product_list);
if (!_.isEmpty(result[0].data.filter)) {
finalResult.filters = saleHandler.handleSaleFilterData(result[0].data.filter, params);
}
// 处理排序数据
finalResult.opts = saleHandler.handleSaleOptsData(params, result[0].data.total);
finalResult.totalCount = result[0].data.total;
finalResult.pager = saleHandler.handleSalePagerData(result[0].data.total, params);
if (!_.isEmpty(params) && params.saleType === 2) {
finalResult.saleTitle = {};
finalResult.saleTitle.name = '所有商品';
finalResult.saleTitle.count = finalResult.totalCount;
}
}
// 获取焦点图数据
if (result[1].code === 200) {
finalResult.topBanner = saleHandler.handleSaleBannerData(result[1].data);
}
// 获取左侧类目数据
if (result[2].code === 200) {
if (params.gender === '2,3') {
finalResult.leftContent = saleHandler.handleSaleSortData(result[2].data.girl, params);
} else {
finalResult.leftContent = saleHandler.handleSaleSortData(result[2].data.boy, params);
}
}
// 处理 VIP 商品数据
if (result[3].code === 200 && parseInt(params.saleType, 10) === 2) {
_.forEach(finalResult.goods, (value, key) => {
switch (result[3].curLevel) {
case '1':
finalResult.goods[key].vipPrice = value.vip1_price;
finalResult.goods[key].vip1 = true;
break;
case '2':
finalResult.goods[key].vipPrice = value.vip2_price;
finalResult.goods[key].vip2 = true;
break;
case '3':
finalResult.goods[key].vipPrice = value.vip3_price;
finalResult.goods[key].vip3 = true;
break;
default:
finalResult.goods[key].vipPrice = value.vip_price;
finalResult.goods[key].vip = true;
break;
}
});
}
return finalResult;
});
};
/**
* 获取折扣专场数据 Controller 调用
* @return {[type]} [description]
*/
exports.getSaleDiscountData = (params) => {
return api.all([
saleApi.getSaleGoodsList(params),
saleApi.getSaleBannerList('7c2b77093421efa8ae9302c91460db73'),
saleApi.getSaleActivityList(params)
]).then(result => {
let finalResult = {};
// 处理商品数据,顶部分类
if (result[0].code === 200) {
finalResult.saleList = {};
finalResult.saleList.goods = productProcess.processProductList(result[0].data.product_list);
finalResult.leftContent = saleHandler.handleSaleSortData(result[0].data.filter.group_sort, params);
finalResult.totalCount = result[0].data.total;
finalResult.pager = saleHandler.handleSalePagerData(result[0].data.total, params);
}
// 处理焦点图数据
if (result[1].code === 200) {
finalResult.topBanner = saleHandler.handleSaleBannerData(result[1].data);
}
// 处理折扣专场标题数据
if (result[2].code === 200) {
if (_.size(result[2].data) === 1) {
finalResult.saleTitle = saleHandler.handleDiscountTitleData(result[2].data[0]);
}
}
return finalResult;
});
};
/**
* 获取断码区数据 Controller 调用
* @param {[type]} params [description]
* @return {[type]} [description]
*/
exports.getSalebreakingYardsData = (params) => {
return api.all([
saleApi.getSaleGoodsList(params),
saleApi.getSalebreakingYardsSortList(),
saleApi.getSaleBannerList('7c2b77093421efa8ae9302c91460db73'),
saleApi.getLeftContentList()
]).then(result => {
let finalResult = {};
if (result[0].code === 200 && result[1].code === 200) {
finalResult.goods = productProcess.processProductList(result[0].data.product_list);
// 这边整合了尺码数据处理
finalResult.filters = saleHandler.handleSaleFilterData(
Object.assign(result[0].data.filter, { size: result[1].data }),
params);
finalResult.opts = saleHandler.handleSaleOptsData(params, result[0].data.total);
finalResult.totalCount = result[0].data.total;
finalResult.pager = saleHandler.handleSalePagerData(result[0].data.total, params);
}
if (result[2].code === 200) {
finalResult.topBanner = saleHandler.handleSaleBannerData(result[2].data);
}
if (result[3].code === 200) {
if (params.gender === '2,3') {
finalResult.leftContent = saleHandler.handleSaleSortData(result[3].data.girl, params);
} else {
finalResult.leftContent = saleHandler.handleSaleSortData(result[3].data.boy, params);
}
}
return finalResult;
});
};