sale.js
5.9 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
/**
* sale controller
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/5/17
*/
'use strict';
const library = '../../../library';
const mRoot = '../models';
// const cookie = require(`${library}/cookie`);
const headerModel = require('../../../doraemon/models/header');
const log = require(`${library}/logger`);
const saleModel = require(`${mRoot}/sale`);
const saleLogger = (err, res) => {
log.error('sale页面渲染错误:' + JSON.stringify(err));
res.send('error');
};
const typeCont = {
price: ['s_p_desc', 's_p_asc'],
discount: ['p_d_desc', 'p_d_asc'],
sales: ['s_n_desc', 's_n_asc'],
newest: ['s_t_desc', 's_t_asc']
};
/**
* sale 首页
*/
exports.index = (req, res) => {
let headerData = headerModel.setNavHeader('SALE');
let renderData = {
module: 'product',
page: 'sale',
title: 'SALE',
pageHeader: headerData,
pageFooter: true
};
saleModel.getSaleResources().then((result) => {
res.render('sale', Object.assign(renderData, {
content: result
}));
}).catch((err) => {
saleLogger(err, res);
});
};
/**
* 折扣专场列表
*/
exports.special = (req, res) => {
let headerData = headerModel.setNavHeader('折扣专场');
let renderData = {
module: 'product',
page: 'special',
pageHeader: headerData,
pageFooter: true
};
saleModel.getSpecialData().then((result) => {
res.render('special', Object.assign(renderData, result));
}).catch((err) => {
saleLogger(err, res);
});
};
/**
* 折扣专场专题详情
*/
exports.specialDetail = (req, res) => {
let headerData = headerModel.setNavHeader('折扣专场');
let renderData = {
module: 'product',
page: 'special',
pageHeader: headerData,
pageFooter: true
};
saleModel.getSpecialDetailData().then((result) => {
result = {
src: 'http://img12.static.yhbimg.com/yhb-img01/2016/04/18/05/0239e814b8121913aa67b9ad509bd4e310.jpg?imageView2/2/w/{width}/h/{height}',
goods: {
url: 'http://m.yohobuy.com/product/pro_320421_412063/SYSTAGYuanLingWeiYiSYSA601HC09.html',
thumb: 'http://img10.static.yhbimg.com/goodsimg/2015/12/07/09/01ced0e2ed6a4f2a6d95be70cd0a6c5a56.jpg?imageView/2/w/235/h/314',
name: 'NEFF ONE OF US RAGLAN L/S 男款森林风连帽卫衣',
salePrice: '759.00',
price: '799.00',
tags: {
isNew: true,
isAdvance: false,
isDiscount: false,
isYohoood: false,
isLimited: false
},
isSoonSoldOut: true
}
};
res.render('special-detail', Object.assign(renderData, result));
}).catch((err) => {
saleLogger(err, res);
});
};
/**
* 断码区
*/
exports.breakCode = (req, res) => {
let headerData = headerModel.setNavHeader('断码区');
let renderData = {
module: 'product',
page: 'break-code',
pageHeader: headerData,
pageFooter: true
};
saleModel.getBreakCodeData().then((result) => {
result = {
src: 'http://img12.static.yhbimg.com/yhb-img01/2016/04/18/05/0239e814b8121913aa67b9ad509bd4e310.jpg?imageView2/2/w/{width}/h/{height}',
goods: {
url: 'http://m.yohobuy.com/product/pro_320421_412063/SYSTAGYuanLingWeiYiSYSA601HC09.html',
thumb: 'http://img10.static.yhbimg.com/goodsimg/2015/12/07/09/01ced0e2ed6a4f2a6d95be70cd0a6c5a56.jpg?imageView/2/w/235/h/314',
name: 'NEFF ONE OF US RAGLAN L/S 男款森林风连帽卫衣',
salePrice: '759.00',
price: '799.00',
tags: {
isNew: true,
isAdvance: false,
isDiscount: false,
isYohoood: false,
isLimited: false
},
isSoonSoldOut: true
}
};
res.render('break-code', Object.assign(renderData, result));
}).catch((err) => {
saleLogger(err, res);
});
};
/**
* vip
*/
exports.vip = (req, res) => {
let headerData = headerModel.setNavHeader('会员专享');
let renderData = {
module: 'product',
page: 'break-code',
pageHeader: headerData,
pageFooter: true
};
saleModel.getVipData().then((result) => {
result = {
src: 'http://img12.static.yhbimg.com/yhb-img01/2016/04/18/05/0239e814b8121913aa67b9ad509bd4e310.jpg?imageView2/2/w/{width}/h/{height}',
goods: {
url: 'http://m.yohobuy.com/product/pro_320421_412063/SYSTAGYuanLingWeiYiSYSA601HC09.html',
thumb: 'http://img10.static.yhbimg.com/goodsimg/2015/12/07/09/01ced0e2ed6a4f2a6d95be70cd0a6c5a56.jpg?imageView/2/w/235/h/314',
name: 'NEFF ONE OF US RAGLAN L/S 男款森林风连帽卫衣',
salePrice: '759.00',
price: '799.00',
tags: {
isNew: true,
isAdvance: false,
isDiscount: false,
isYohoood: false,
isLimited: false
},
isSoonSoldOut: true
}
};
res.render('vip', Object.assign(renderData, result));
}).catch((err) => {
saleLogger(err, res);
});
};
exports.search = (req, res) => {
let setting = {
limit: '5',
page: req.query.page,
yh_channel: '1',
productSize: '384x511'
};
let type = req.query.type;
let order = req.query.order;
if (typeCont[type]) {
setting.order = typeCont[type][order];
}
saleModel.getSearchData(setting).then((result) => {
result.goods = {};
result.layout = false;
res.render('product', result);
});
};