index.js
5.16 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/**
* 个人中心 controller
* @author: chengyao.guo<chengyao.guo@yoho.cn>
* @date: 2016/08/10
*/
'use strict';
const headerModel = require('../../../doraemon/models/header'); // 头部model
const footerModel = require('../../../doraemon/models/footer_tab'); // 底部tab
const indexModel = require('../models/index');
const _ = require('lodash');
/**
* 用户中心首页
* @param req
* @param res
* @param next
*/
exports.index = (req, res, next) => {
let params = {
uid: req.user.uid,
channel: req.query.channel || 1,
udid: require('yoho-md5')(req.ip),
contentCode: 'b2b5cde8144aff3073573c3b323344ab'
};
let studentSwitch = !_.get(req.app.locals.wap, 'user.removeStudentIdentification', true);
// 唤起 APP 的路径
res.locals.appPath = 'yohobuy://yohobuy.com/goapp?openby:yohobuy= {"action":"go.mine"}';
req.ctx(indexModel).index(params).then(result => {
if (result) {
res.render('home', Object.assign(result, {
isLogin: params.uid ? true : false,
module: 'home',
page: 'index',
title: '个人中心 | Yoho!Buy有货 | 潮流购物逛不停',
pageFooter: true,
pageChannel: {
boys: true
},
showFooterTab: footerModel.getUrlData('mine'),
localCss: true,
studentSwitch
}));
}
}).catch(next);
};
/**
* 个人基本资料页面
* @param req
* @param res
* @param next
*/
exports.myDetails = (req, res, next) => {
let headerData = headerModel.setNav({
navTitle: '基本资料'
});
let responseData = {
pageHeader: headerData,
module: 'home',
page: 'personal-details',
title: '基本资料',
pageFooter: true
};
let uid = req.user.uid;
req.ctx(indexModel).myDetails(uid).then(result => {
res.render('personal-details', Object.assign(responseData, result));
}).catch(next);
};
/**
* 浏览记录
* @param req
* @param res
* @param next
*/
exports.record = (req, res, next) => {
let uid = req.user.uid;
let udid = req.user.udid;
let page = req.query.page || 1;
let limit = 10;
let headerData = headerModel.setNav({
navTitle: '浏览记录'
});
let responseData = {
pageHeader: headerData,
module: 'home',
page: 'browse-record',
title: '浏览记录',
browseRecordPage: true,
pageFooter: true,
_noLazy: true,
localCss: true
};
req.ctx(indexModel).recordContent(uid, udid, page, limit).then((result) => {
if (result && result.browseRecord && result.browseRecord.length > 0) {
responseData.browseRecord = result.browseRecord;
} else {
responseData.noRecord = true;
}
res.render('browse-record', responseData);
}).catch(next);
};
/**
* 浏览记录列表
* @param req
* @param res
* @param next
*/
exports.recordContent = (req, res, next) => {
let uid = req.user.uid;
let udid = req.user.udid;
let page = req.query.page || 1;
let limit = 10;
req.ctx(indexModel).recordContent(uid, udid, page, limit).then((result) => {
if (result && result.browseRecord && result.browseRecord.length === 0) {
res.json(false);
} else {
res.render('browse-record-content', _.assign({
layout: false
}, result));
}
}).catch(next);
};
/**
* 删除浏览记录
* @param req
* @param res
* @param next
*/
exports.delRecord = (req, res, next) => {
let uid = req.user.uid;
let skn = req.query.skn || 0;
req.ctx(indexModel).delRecord(uid, skn).then((result) => {
res.json({
code: result.code,
message: result.message
});
}).catch(next);
};
/**
* 会员等级展示页
* @param req
* @param res
* @param next
*/
exports.grade = (req, res, next) => {
let headerData = headerModel.setNav({
navTitle: '会员等级'
});
let responseData = {
pageHeader: headerData,
module: 'home',
page: 'grade',
title: '会员等级',
pageFooter: true,
width750: true
};
let param = {
uid: req.user.uid,
channel: req.query.channel || 1
};
req.ctx(indexModel).getGrade(param).then((result) => {
res.render('vip-grade/vip-grade', Object.assign(result, responseData));
}).catch(next);
};
/**
* 会员特权列表页
* @param req
* @param res
* @param next
*/
exports.preferential = (req, res, next) => {
let headerData = headerModel.setNav({
navTitle: '会员特权详情'
});
let responseData = {
pageHeader: headerData,
module: 'home',
page: 'grade',
title: '会员特权详情',
pageFooter: true,
width750: true
};
let param = {
uid: req.user.uid,
channel: req.query.channel || 1
};
req.ctx(indexModel).getPreferential(param).then((result) => {
res.render('vip-grade/privilege', Object.assign(result, responseData));
}).catch(next);
};