seckill-detail.js
4.88 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
/**
* 新版商品详情页面
*/
'use strict';
const _ = require('lodash');
const detailModel = require('../models/detail');
const seckillDetailModel = require('../models/seckill-detail');
const newDetailModel = require('../models/new-detail');
const listModel = require('../models/list');
const headerModel = require('../../../doraemon/models/header'); // 头部model
const helpers = global.yoho.helpers;
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: 'seckill-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;
let bundleType = req.query.bundleType;
let gid = req.query.gid;
if ([brandId, productId].some(val => !val)) {
return next();
}
newDetailModel.querySknData({
skn,
brandId,
productId,
bundleType,
gid
}).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,
bundleType: req.body.bundleType,
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);
},
/**
* 商品收藏/取消收藏
*/
favoriteProduct(req, res, next) {
let allowOrigin = _.get(req, 'headers.origin', null) ?
req.headers.origin : req.protocol + '://' + req.headers.host;
res.setHeader('Access-Control-Allow-Origin', allowOrigin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
let uid = req.user.uid;
if (!uid) {
return res.json({
code: 400,
data: helpers.urlFormat('/signin.html', {
refer: req.headers.referer
})});
}
if (req.body.opt === 'ok') {
listModel.setFavorite(req.body.id, uid, 'product').then(result => {
return res.json(result);
}).catch(next);
} else {
listModel.setFavoriteCancel(req.body.id, uid, 'product').then(result => {
return res.json(result);
}).catch(next);
}
},
/**
* 限购商品说明页面
*/
limitHelp(req, res) {
res.render('detail/limit-help', {
module: 'product',
page: 'limit-help'
});
},
// 获取秒杀信息
getSeckillData(req, res) {
seckillDetailModel.getSeckillData({
productskn: req.params.productskn
}, req).then(result => {
return res.json(result);
});
}
};
module.exports = newDetail;