message.js
2.44 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
// 消息 by acgpiano
'use strict';
const headerModel = require('../../../doraemon/models/header'), // 头部model
model = require('../models/message');
const _getList = (req, res, next) => {
req.ctx(model).getList({
page: req.body.page,
size: 20,
uid: req.user.uid,
}).then(result => {
let options = {
module: 'home',
page: 'message',
pageHeader: headerModel.setNav({
navTitle: '我的消息'
}),
title: '我的消息',
pageFooter: true,
list: result,
};
req.body.page && req.body.page !== '1' && (options.layout = false);
res.render('message', options);
}).catch(next);
};
const _msgDetail = (req, res, next) => {
req.ctx(model).getList({
page: req.body.page,
size: 1000,
msgid: req.query.id,
uid: req.user.uid,
}).then(result => {
let options = {
module: 'home',
page: 'message',
pageHeader: headerModel.setNav({
navTitle: '我的消息'
}),
title: '我的消息',
pageFooter: true,
info: result,
};
if (result && result.isCollar && result.isCollar === true) {
res.redirect('/home/message');
} else {
res.render('message-detail', options);
}
}).catch(next);
};
exports.index = (req, res, next) => {
if (!req.query.id) {
_getList(req, res, next);
} else {
_msgDetail(req, res, next);
}
};
exports.ajaxDelMes = (req, res, next) => {
req.ctx(model).delMsg({
uid: req.user.uid,
msgid: req.body.id,
}).then(result => {
res.send(result);
res.end();
}).catch(next);
};
exports.pickCoupon = (req, res, next) => {
req.ctx(model).pickCoupon({
uid: req.user.uid,
couponId: req.body.id,
}).then(result => {
res.send(result);
res.end();
}).catch(next);
};
// 生日卷
exports.birthCoupon = (req, res, next) => {
let responseData = {
module: 'home',
page: 'message',
pageHeader: headerModel.setNav({
navTitle: '生日卷'
}),
title: '生日卷',
pageFooter: true
};
req.ctx(model)._getBirthCouponById(req.user.uid).then(result => {
res.render('birth-coupon', Object.assign(responseData, result));
}).catch(next);
};