sale.js
4.42 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
/**
* sale controller
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/5/17
*/
'use strict';
const mRoot = '../models';
// const cookie = require(`${library}/cookie`);
const headerModel = require('../../../doraemon/models/header');
const saleModel = require(`${mRoot}/sale`);
const queryParam = {
brand: '0',
gender: '1,2,3',
sort: '0',
size: '0',
price: '0',
pD: '0.1,0.9'
};
/**
* 公共数据处理
* @param {[object]} req
* @param {[string]} title 标题
* @param {[string]} page js文件page名称
* @return {[type]}
*/
const processPublicData = (req, title, page) => {
let data = {};
let headerData = headerModel.setNav({
navTitle: title
});
data = {
channel: req.yoho.channel,
renderData: {
module: 'product',
page: page,
title: title,
pageHeader: headerData,
pageFooter: true
}
};
return data;
};
/**
* sale 首页 资源位获取
* @param {[object]} req
* @param {[object]} res
* @return {[type]}
*/
exports.index = (req, res, next) => {
let params = processPublicData(req, 'SALE', 'sale');
saleModel.getSaleData(params.channel).then((result) => {
res.render('sale/index', Object.assign(params.renderData, queryParam, {
content: result,
floorHeader: {
title: {
title: '最新降价'
}
}
}));
}).catch(next);
};
/**
* 断码区
* @param {[object]} req
* @param {[object]} res
* @return {[type]}
*/
exports.breakingYards = (req, res, next) => {
let params = processPublicData(req, '断码区', 'break-code');
saleModel.getBreakCodeData({
yhChannel: params.channel
}).then((result) => {
res.render('sale/break-code', Object.assign(params.renderData, result));
}).catch(next);
};
/**
* 折扣专场列表
* @param {[object]} req
* @param {[object]} res
* @return {[type]}
*/
exports.discount = (req, res, next) => {
let params = processPublicData(req, '折扣专场', 'discount');
saleModel.getDiscountData(params.channel).then((result) => {
res.render('sale/discount', Object.assign(params.renderData, result));
}).catch(next);
};
/**
* 折扣专场专题详情
* @param {[object]} req
* @param {[object]} res
* @return {[type]}
*/
exports.discountDetail = (req, res, next) => {
let id = req.query.id;
let params = processPublicData(req, '', 'discount-detail');
saleModel.getDiscountDetailData(id).then((result) => {
params.renderData.pageHeader.navTitle = result.title;
res.render('sale/discount-detail', Object.assign(params.renderData, result));
}).catch(next);
};
/**
* vip 会员专享
* @param {[object]} req
* @param {[object]} res
* @return {[type]}
*/
exports.vip = (req, res, next) => {
let params = processPublicData(req, '会员专享', 'vip');
saleModel.getVipData(params.channel).then((result) => {
res.render('sale/vip', Object.assign(params.renderData, {
content: result
}));
}).catch(next);
};
/**
* 筛选
* @param {[object]} req
* @param {[object]} res
* @return {[type]}
*/
exports.filter = (req, res, next) => {
let params = Object.assign({}, req.query);
saleModel.getFilterData(params).then((result) => {
res.render('sale/filter', {
layout: false,
params: params,
filter: result
});
}).catch(next);
};
/**
* 商品搜索
* @param {[object]} req
* @param {[object]} res
* @return {[type]}
*/
exports.search = (req, res, next) => {
let params = Object.assign({}, req.query);
// uid = 9239279
let uid = req.user.uid || 0;
saleModel.getSearchData(params, uid).then((result) => {
let vipLevel = result[1].curLevel;
let vipObj = {};
if (req.query.saleType === '2') {
vipObj = Object.assign({
saleVip: (req.query.saleType === '2' && (!uid || vipLevel === '0')),
vipLevel: vipLevel,
saleViplogin: vipLevel >= 1 ? true : false,
vipPrice1: vipLevel === '1',
vipPrice2: vipLevel === '2',
vipPrice3: vipLevel === '3'
}, vipObj);
}
res.render('sale/product', Object.assign({
layout: false,
params: params,
goods: result[0]
}, vipObj));
}).catch(next);
};