detail.js
11.1 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/**
* 商品详情controller
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/5/6
*/
'use strict';
const mRoot = '../models';
const headerModel = require('../../../doraemon/models/header'); // 头部model
const detailModel = require(`${mRoot}/detail`); // 商品详情 model
const introModel = require(`${mRoot}/intro`); // 商品尺码信息 model
const preferenceModel = require(`${mRoot}/preference`); // 商品偏好 model
const detailRelated = require(`${mRoot}/consult-comment`); // 商品评论咨询 model
const couponModel = require(`${mRoot}/coupon`); // 商品 优惠券 modal
const _ = require('lodash');
const helpers = global.yoho.helpers;
exports.getUser = (req, res, next) => {
let uid = req.user.uid,
result = {
isStudent: false
};
detailModel.getUserProfile(uid).then((data) => {
result.isStudent = data.data && data.data.vip_info && data.data.vip_info.is_student ? true : false;
result.vipLevel = (data.data && data.data.vip_info && data.data.vip_info.cur_level) || '0';
req.__User__ = result;
next();
}).catch(next);
};
// /**
// * 商品基本信息
// * @param {[type]} req [description]
// * @param {[type]} res [description]
// * @return {[type]} [description]
// */
// exports.index = (req, res, next) => {
// if (!req.params[0] || !req.params[1]) {
// return next();
// }
// let uid = req.user.uid || 0;
// let headerData = headerModel.setNav({
// navTitle: '商品详情'
// });
// detailModel.getProductData({
// id: req.params[0],
// goodsId: req.params[1],
// uid: uid,
// ua: req.get('user-agent') || ''
// }).then((result) => {
// if (_.isEmpty(result)) {
// return next();
// }
// result.studentPrice = req.__User__.isStudent && result && result.goodsPrice && result.goodsPrice.studentPrice ? result.goodsPrice.studentPrice : false;
// res.render('detail/detail', {
// pageHeader: headerData,
// result: result,
// page: 'detail',
// title: result.goodsName,
// pageFooter: true
// });
// }).catch(next);
// };
// /**
// * 商品基本信息 SKN 进入
// * @param {[type]} req [description]
// * @param {[type]} res [description]
// * @return {[type]} [description]
// */
// exports.indexSkn = (req, res, next) => {
// if (!req.params[0]) {
// return next();
// }
// let uid = req.user.uid || 0;
// let headerData = headerModel.setNav({
// navTitle: '商品详情'
// });
// detailModel.getProductData({
// productSkn: req.params[0],
// uid: uid,
// ua: req.get('user-agent') || ''
// }).then((result) => {
// if (_.isEmpty(result)) {
// return next();
// }
// result.studentPrice = req.__User__.isStudent && result && result.goodsPrice && result.goodsPrice.studentPrice ? result.goodsPrice.studentPrice : false;
// res.render('detail/detail', {
// pageHeader: headerData,
// result: result,
// page: 'detail',
// title: result.goodsName,
// pageFooter: true
// });
// }).catch(next);
// };
/**
* 商品尺码信息详情
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.intro = (req, res, next) => {
if (!req.params.productskn) {
return next();
}
introModel.getintroIntro({
productskn: req.params.productskn
}, req).then(html => {
res.send(html);
});
// introModel.getintroData({
// productskn: req.params.productskn
// }, req).then((result) => {
// res.render('detail/intro', {
// result: result,
// layout: false
// });
// }).catch(next);
};
/**
* 为你优选
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.preference = (req, res, next) => {
preferenceModel({
productskn: req.query.productSkn,
limit: '20' // 后期值需要修改的话得手动改
}).then((result) => {
res.send(result);
}).catch(next);
};
/**
* 购买评价页
*/
exports.comments = (req, res, next) => {
if (!req.query.product_id) {
return next();
}
let headerData = headerModel.setNav({
navTitle: '购买评价'
});
detailRelated.comments(req.query).then((result) => {
if (result.navTitle) {
headerData.navTitle = result.navTitle;
}
res.render('detail/comments', Object.assign({
title: '购买评价',
pageHeader: headerData,
pageFooter: true,
localCss: true
}, result));
}).catch(next);
};
/**
* 购买咨询
*/
exports.consults = (req, res, next) => {
if (!req.query.product_id) {
return next();
}
let uid = req.user.uid || 0;
let headerData = headerModel.setNav({
navTitle: '购买咨询'
});
detailRelated.consults(req.query, uid).then((result) => {
if (result.navTitle) {
headerData.navTitle = result.navTitle;
}
res.render('detail/consults', Object.assign({
title: '购买咨询',
pageHeader: headerData,
pageFooter: true,
localCss: true
}, result));
}).catch(next);
};
/**
* 咨询点赞
*/
exports.consultUpvoteOrUseful = (req, res, next) => {
let uid = req.user.uid || 0;
if (!uid) {
return res.json({
code: 401,
message: '用户id为空',
data: helpers.urlFormat('/signin.html', {
refer: helpers.urlFormat('/product/detail/consults', {
product_id: req.body.productId,
total: req.body.total
})
})
});
}
req.body.isUpvote = /upvote/.test(req.path);
req.body.uid = uid;
detailRelated.upvoteConsult(req.body).then((result) => {
res.json(result);
}).catch(next);
};
/**
* 咨询表单页
*/
exports.consultform = (req, res, next) => {
if (!req.query.product_id) {
return next();
}
let headerData = headerModel.setNav({
navTitle: '我要咨询'
});
res.render('detail/consult-form', {
title: '我要咨询',
pageHeader: headerData,
productId: req.query.product_id,
formUrl: '/product/detail/consultsubmit',
pageFooter: true,
localCss: true
});
};
/**
* 咨询提交接口
*/
exports.consultsubmit = (req, res, next) => {
let data = {
code: 400,
message: '请输入咨询内容',
data: ''
};
// 判断参数是否存在
if (!req.body.product_id || !req.body.content) {
return res.json(data);
}
return detailRelated.addConsult(req.user.uid, req.body.product_id, req.body.content).then((result) => {
if (result) {
Object.assign(data, result);
}
return res.json(data);
}).catch(next);
};
/**
* 商品基本信息 SKN 进入 pagecache重构
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.indexSkn = (req, res, next) => {
if (!req.params[0]) {
return next();
}
// let uid = req.user.uid || 0;// pagecache重构
let headerData = headerModel.setNav({
navTitle: '商品详情'
});
detailModel.getProductData({
productSkn: req.params[0],
// uid: uid,
ua: req.get('user-agent') || ''
}).then((result) => {
if (_.isEmpty(result)) {
return next();
}
// pagecache重构
// result.studentPrice = req.__User__.isStudent && result && result.goodsPrice && result.goodsPrice.studentPrice ? result.goodsPrice.studentPrice : false;
res.render('detail/detail', {
pageHeader: headerData,
result: result,
page: 'detail',
title: result.goodsName,
pageFooter: true,
localCss: true
});
}).catch(next);
};
/**
* 商品基本信息 pagecache重构
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.index = (req, res, next) => {
if (!req.params[0] || !req.params[1]) {
return next();
}
// let uid = req.user.uid || 0; // pagecache重构
let headerData = headerModel.setNav({
navTitle: '商品详情'
});
detailModel.getProductData({
id: req.params[0],
goodsId: req.params[1],
// uid: uid,
ua: req.get('user-agent') || ''
}).then((result) => {
if (_.isEmpty(result)) {
return next();
}
// pagecache重构
// result.studentPrice = req.__User__.isStudent && result && result.goodsPrice && result.goodsPrice.studentPrice ? result.goodsPrice.studentPrice : false;
res.render('detail/detail', {
pageHeader: headerData,
result: result,
page: 'detail',
title: result.goodsName,
pageFooter: true,
localCss: true
});
}).catch(next);
};
/**
* 商品信息异步数据
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.indexData = (req, res, next) => {
if (!req.xhr) {
return next();
}
if (!req.body.id) {
return next();
}
let uid = req.user.uid || 0;
detailModel.getProductAsyncData(Object.assign({
id: req.body.id,
goodsId: req.body.goodsId,
productSkn: req.body.productSkn,
uid: uid,
ua: req.get('user-agent') || ''
}, req.__User__)).then((result) => {
if (_.isEmpty(result)) {
return res.json({
code: 400,
message: '数据错误'
});
}
result.studentPrice = req.__User__.isStudent && result && result.goodsPrice && result.goodsPrice.studentPrice ? result.goodsPrice.studentPrice : false;
return res.json(result);
}).catch(next);
};
/**
* [查询商品 品牌券]
*/
exports.brandCoupon = (req, res) => {
const uid = req.user.uid;
const skn = +req.query.skn;
const brandId = +req.query.brandId;
if (!(skn && brandId)) {
return res.json([]);
}
couponModel.queryProdPageCoupons(uid, skn, brandId)
.then(
result => {
return result.data || [];
}, () => {
return [];
})
.then(coupons => {
return res.json(coupons);
});
};
/**
* [获取商品 品牌券]
*/
exports.getCoupon = (req, res, next) => {
const uid = req.user.uid;
const couponId = +req.body.couponId;
if (!couponId) {
return res.json({
code: 400,
message: '优惠券不存在'
});
}
return couponModel.getCoupon(uid, couponId)
.then(data => {
return res.json(data);
})
.catch(next);
};