detail.js
2.84 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
/**
* 商品详情-controller
* @author: Tao.Huang
* @date: 2016/6/5
*/
'use strict';
const library = '../../../library';
const helpers = require(`${library}/helpers`);
const mRoot = '../models';
const service = require(`${mRoot}/detail-service`);
const detailHelper = require('../models/detail-helper');
/**
* 单个商品详情
*/
module.exports.showMain = (req, res, next) => {
// TODO: vipLevel = 0; // 用户等级
let pid = 204503;
let uid = req.user.uid || '';
let channel = detailHelper.COOKIE_NAME_BOYS;
if (req.cookies._Channel) {
channel = req.cookies._Channel;
} else {
detailHelper.setSwitchToCookie(res);
}
let gender = detailHelper.getGenderByCookie(req);
service.showMainAsync({
id: pid,
ua: req.get('user-agent') || '',
channel: channel,
gender: gender,
uid: uid,
vipLevel: 0
}).then((result) => {
res.render('product/detail', Object.assign({
module: 'product',
page: 'detail'
}, result));
}).catch(next);
};
/**
* 获取热区图
*/
module.exports.indexHotArea = (req, res, next) => {
let pid = req.query.productId || 0;
service.indexHotAreaAsync(pid).then(result => {
res.render('product/hotarea', {
hotArea: result,
layout: false
});
}).catch(next);
};
/**
* 获得评论列表
* json
*/
module.exports.indexComment = (req, res, next) => {
let pid = req.query.productId || 0;
let page = req.query.page || 1;
let size = req.query.size || 10;
service.indexCommentAsync(pid, page, size).then(result => {
res.json(result);
}).catch(next);
};
/**
* 获得咨询列表
* json
*/
module.exports.indexConsult = (req, res, next) => {
let uid = req.user.uid || '';
let pid = req.query.productId || 0;
let page = req.query.page || 1;
let size = req.query.size || 10;
service.indexConsultAsync(uid, pid, page, size).then(result => {
res.json(result);
}).catch(next);
};
/**
* 新建咨询
* json
*/
module.exports.createConsult = (req, res, next) => {
let uid = req.user.uid || '';
let pid = req.body.productId || 0;
let content = req.body.content;
if (content && uid) {
service.createConsultAsync(uid, pid, content).then(result => {
res.json(result);
}).catch(next);
} else if (!content) {
res.json({
code: 400,
message: '请输入咨询内容'
});
} else if (!uid) {
res.json({
code: 403,
message: '用户没有登录',
data: {
url: helpers.urlFormat('signin.html')
}
});
} else {
res.json({
code: 400,
message: '请输入咨询内容',
data: ''
});
}
};