detail.js
3.04 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
/**
* 商品详情-controller
* @author: Tao.Huang
* @date: 2016/6/5
*/
'use strict';
const helpers = global.yoho.helpers;
const mRoot = '../models';
const service = require(`${mRoot}/detail-service`);
const detailHelper = require('../models/detail-helper');
/**
* 单个商品详情
*/
const showMain = (req, res, next) => {
let vipLevel = 0;
let pid = req.params[0];
let gid = req.params[1];
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({
pid: pid,
gid: gid,
channel: channel,
gender: gender,
uid: uid,
vipLevel: vipLevel
})
.then(result => {
res.render('product/detail', Object.assign({
module: 'product',
page: 'detail'
}, result));
})
.catch(next);
};
/**
* 获取热区图
*/
const 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
*/
const 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
*/
const 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
*/
const 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 => {
console.log(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')
}
});
} else {
res.json({
code: 400,
message: '请输入咨询内容',
});
}
};
module.exports = {
showMain,
indexHotArea,
indexComment,
indexConsult,
createConsult
};