detail.js
1.65 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
/**
* 商品详情controller
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/5/6
*/
'use strict';
const mRoot = '../models';
// 商品详情model
const detailHandle = require(`${mRoot}/detail-handle`);
const moment = require('moment');
/* COOKIE标识访问的是男生频道 */
const COOKIE_NAME_BOYS = 'boys';
const COOKIE_DOMAIN = '.yohobuy.com';
function setSwitchToCookie(res) {
res.cookie('_Channel', COOKIE_NAME_BOYS, {
domain: COOKIE_DOMAIN,
maxAge: moment.duration(300, 'days').seconds()
});
}
function getGenderByCookie(req) {
let gender = null;
let channel = req.cookies._Channel || 'boys';
switch (channel) {
case 'boys':
{
gender = '1,3';
break;
}
case 'girls':
{
gender = '2,3';
break;
}
default:
{
gender = '1,2,3';
}
}
return gender;
}
exports.index = (req, res, next) => {
// var uid = null, // 需要修改为正式取 UID 的方式
// vipLevel = 0; // 用户等级
let pid = 204503;
let channel = COOKIE_NAME_BOYS;
if (req.cookies._Channel) {
channel = req.cookies._Channel;
} else {
setSwitchToCookie(res);
}
let gender = getGenderByCookie(req);
detailHandle({
id: pid,
ua: req.get('user-agent') || '',
channel: channel,
gender: gender,
uid: 0,
vipLevel: 0
}).then((result) => {
res.render('detail', Object.assign({
module: 'product',
page: 'detail'
}, result));
}).catch(next);
};