new-detail.js
3.16 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
/**
* 新版商品详情页面
*/
'use strict';
const _ = require('lodash');
const detailModel = require('../models/detail');
const newDetailModel = require('../models/new-detail');
const headerModel = require('../../../doraemon/models/header'); // 头部model
const newDetail = {
index(req, res, next) {
let id;
let goodsId;
let productSkn;
if (req.params[0] && req.params[1]) {
id = req.params[0];
goodsId = req.params[1];
} else if (req.params[0]) {
productSkn = req.params[0];
} else {
return next();
}
let headerData = headerModel.setNav({
navTitle: '商品详情'
});
newDetailModel.getProductData({
id: id,
goodsId: goodsId,
productSkn: productSkn,
ua: req.get('user-agent') || ''
}).then((result) => {
if (_.isEmpty(result)) {
return next();
}
// result.id = id;
// result.goodsId = goodsId;
let appParams = {product_skn: result.productSkn};
let appPath = 'yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.productDetail","params":' +
JSON.stringify(appParams) +
'}';
res.render('detail/new/detail', {
pageHeader: headerData,
result: result,
page: 'new-detail',
title: result.goodsName,
pageFooter: true,
localCss: true,
appPath: appPath
});
}).catch(next);
},
/*
* 商品基本信息 SKN 进入 pagecache重构
*/
sknData(req, res, next) {
let brandId = req.query.brandId;
let productId = req.query.productId;
let skn = req.query.skn;
if ([brandId, productId].some(val => !val)) {
return next();
}
newDetailModel.querySknData({
skn,
brandId,
productId
}).then(result => {
if (_.isEmpty(result)) {
return next();
}
res.json(result);
});
},
indexData(req, res, next) {
if (!req.xhr) {
return next();
}
if (!req.body.id) {
return next();
}
let uid = req.user.uid || 0;
let shoppingKey = req.cookies._SPK || '';
detailModel.getNewProductAsyncData(Object.assign({
id: req.body.id,
goodsId: req.body.goodsId,
productSkn: req.body.productSkn,
uid: uid,
shoppingKey: shoppingKey,
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);
}
};
module.exports = newDetail;