detail.js
3.67 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
/**
* 商品详情controller
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/5/6
*/
'use strict';
const mRoot = '../models';
const headerModel = require('../../../doraemon/models/header'); // 头部model
const detail = require(`${mRoot}/detail`); // 商品详情 model
const intro = require(`${mRoot}/intro`); // 商品尺码信息 model
const preference = require(`${mRoot}/preference`); // 商品偏好 model
const detailRelated = require(`${mRoot}/consult-comment`); // 商品评论咨询 model
const _ = require('lodash');
/**
* 商品基本信息
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.index = (req, res, next) => {
let vipLevel = 0; // 用户等级 待处理
let uid = _.isEmpty(req.user.uid) ? null : req.user.uid;
let headerData = headerModel.setNav({
navTitle: '商品详情'
});
detail({
id: req.params[0],
goodsId: req.params[1],
uid: uid,
vipLevel: vipLevel,
ua: req.get('user-agent') || ''
}).then((result) => {
res.render('detail/detail', {
pageHeader: headerData,
result: result,
page: 'detail',
title: result.goodsName,
pageFooter: true
});
}).catch(next);
};
/**
* 商品尺码信息详情
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.intro = (req, res) => {
intro({
productskn: req.params.productskn
}).then((result) => {
res.render('detail/intro', {
result: result,
layout: false
});
});
};
/**
* 为你优选
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.preference = (req, res) => {
preference({
productskn: req.query.productSkn,
yhchannel: 1,
brandId: req.query.brandId
}).then((result) => {
res.render('detail/preference', Object.assign({
layout: false
}, result));
});
};
/**
* 购买评价页
*/
exports.comments = (req, res, next) => {
let headerData = headerModel.setNav({
navTitle: '购买评价'
});
detailRelated.comments(req.query).then((result) => {
res.render('detail/comments', Object.assign({
pageHeader: headerData,
pageFooter: true
}, result));
}).catch(next);
};
/**
* 购买咨询
*/
exports.consults = (req, res, next) => {
let headerData = headerModel.setNav({
navTitle: '购买咨询'
});
detailRelated.consults(req.query).then((result) => {
res.render('detail/consults', Object.assign({
pageHeader: headerData,
pageFooter: true
}, result));
}).catch(next);
};
/**
* 咨询表单页
*/
exports.consultform = (req, res) => {
let headerData = headerModel.setNav({
navTitle: '我要咨询'
});
res.render('detail/consult-form', {
pageHeader: headerData,
productId: req.query.product_id,
formUrl: '/product/detail/consultsubmit',
pageFooter: true
});
};
/**
* 咨询提交接口
*/
exports.consultsubmit = (req, res, next) => {
let data = {
code: 400,
message: '请输入咨询内容',
data: ''
};
// 判断参数是否存在
if (!req.body.product_id || !req.body.content) {
return res.json(data);
}
detailRelated.addConsult(req.user.uid, req.body.product_id, req.body.content).then((result) => {
if (result) {
Object.assign(data, result);
}
return res.json(data);
}).catch(next);
};