daily-check-in.js
2.59 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
/**
* 签到活动controller
* Created by qiujun on 2019/5/7.
*/
const moment = require('moment');
const dailyCheckInModel = require('../models/daily-check-in');
const dailyCheckInController = {
entry(req, res) {
if (req.xhr) {
return res.json({
code: 404,
message: 'invalid url'
});
}
res.render('activity/daily-check-in', {
bodyClass: 'nav-md',
module: 'admin',
page: 'daily-check-in'
});
},
/**
* 创建活动
* @param req
* @param res
* @returns {Promise.<void>}
*/
async actCreate(req, res) {
const title = req.body.title;
const startTime = req.body.startTime;
const endTime = req.body.endTime;
const normalWheelId = req.body.normalWheelId || '';
let prizeDayArr = req.body.prizeDayArr ? JSON.parse(req.body.prizeDayArr) : [];
if (!title || !startTime || !endTime || prizeDayArr.length === 0) {
return res.json({
code: 400,
message: '缺少参数'
});
}
const params = {
title,
startTime,
endTime,
normalWheelId,
prizeDayArr
};
try {
const result = await req.ctx(dailyCheckInModel).createActivity(params);
return res.json({
code: 200,
data: result
});
} catch (err) {
res.json(err);
}
},
/**
* 获取活动列表获取通过id获取单个活动信息
* @param req
* @param res
* @returns {Promise.<void>}
*/
async actList(req, res) {
try {
let result = await req.ctx(dailyCheckInModel).activityList();
return res.json({
code: 200,
data: result
});
} catch (err) {
return res.json(err);
}
},
/**
* 通过id获取单个活动信息
* @param req
* @param res
* @returns {Promise.<void>}
*/
async actInfo(req, res) {
let actId = req.query.id || 0;
if (!actId) {
return res.json({
code: 400,
message: '缺少参数'
});
}
let result = await req.ctx(dailyCheckInModel).actInfo(actId);
if (result.code !== 201) {
return res.json({
code: 200,
data: result
});
} else {
return res.json(result);
}
},
/**
* 通过id删除一个活动
* @param req
* @param res
* @returns {Promise.<void>}
*/
async actDelete(req, res) {
const id = req.body.id;
try {
const result = await req.ctx(dailyCheckInModel).actDelete(id);
return res.json({
code: 200,
data: result
});
} catch (err) {
return res.json(err);
}
}
};
module.exports = dailyCheckInController;