sale.js
4.04 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
/*
* @Author: Targaryen
* @Date: 2016-05-19 10:20:08
* @Last Modified by: Targaryen
* @Last Modified time: 2016-05-26 11:11:37
*/
'use strict';
const library = '../../../library';
const API = require(`${library}/api`).API;
const api = new API();
const _ = require('lodash');
const saleApi = require('./sale-api');
const saleHandler = require('./sale-handler');
/**
* 获取Sale首页商品列表数据 仅 Ajax 调用 Controller 调用
* @return {[type]} [description]
*/
exports.getSaleGoodsData = (params) => {
return saleApi.getSaleGoodsList(params).then(result => {
let finalResult = {};
if (result.code === 200) {
finalResult.goods = saleHandler.handleSaleGoodsListData(result.data.product_list);
}
return finalResult;
});
};
/**
* 获取 Sale 首页数据 Controller 调用
* @return {[type]} [description]
*/
exports.getSaleIndexData = () => {
return api.all([saleApi.getSaleActivityList(), saleApi.getSaleBannerList()]).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);
}
return finalResult;
});
};
/**
* 获取 VIP 会员专享和新降价专区数据 Controller 调用
* @return {[type]} [description]
*/
exports.getSaleOthersData = (params) => {
return api.all([saleApi.getSaleGoodsList(params)]).then(result => {
let finalResult = {};
if (result[0].code === 200) {
if (!_.isEmpty(result[0].data.product_list)) { // 处理商品列表数据
finalResult.goods = saleHandler.handleSaleGoodsListData(result[0].data.product_list);
}
if (!_.isEmpty(result[0].data.filter)) {
finalResult.filters = saleHandler.handleSaleFilterData(result[0].data.filter, params);
}
if (!_.isEmpty(result[0].data.filter.group_sort)) {
finalResult.leftContent = saleHandler.handleSaleSortData(result[0].data.filter.group_sort, params);
}
}
finalResult.opts = saleHandler.handleSaleOptsData();
return finalResult;
});
};
/**
* 获取折扣专场数据 Controller 调用
* @return {[type]} [description]
*/
exports.getSaleDiscountData = (params) => {
return api.all([saleApi.getSaleGoodsList(params)]).then(result => {
let finalResult = {};
if (result[0].code === 200) {
finalResult.saleList = {};
finalResult.saleList.goods = saleHandler.handleSaleGoodsListData(result[0].data.product_list);
finalResult.leftContent = saleHandler.handleSaleSortData(result[0].data.filter.group_sort, params);
}
return finalResult;
});
};
/**
* 获取断码区数据 Controller 调用
* @param {[type]} params [description]
* @return {[type]} [description]
*/
exports.getSalebreakingYardsData = (params) => {
return api.all([saleApi.getSalebreakingYardsSortList(), saleApi.getSaleGoodsList(params)]).then(result => {
let finalResult = {};
if (result[0].code === 200) {
finalResult.size = saleHandler.handleSalebreakingYardsSortData(result[0].data); // 待处理
}
if (result[1].code === 200) {
if (!_.isEmpty(result[1].data.product_list)) { // 处理商品列表数据
finalResult.goods = saleHandler.handleSaleGoodsListData(result[1].data.product_list);
}
if (!_.isEmpty(result[1].data.filter)) {
finalResult.filters = saleHandler.handleSaleFilterData(result[1].data.filter);
finalResult.leftContent = saleHandler.handleSaleSortData(result[1].data.filter.group_sort, params);
}
}
finalResult.opts = saleHandler.handleSaleOptsData(params);
return finalResult;
});
};