wheel-surf.js
7.25 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
236
237
238
239
240
241
242
/**
* 大转盘活动controller
* @author: leo <qi.li@yoho.cn>
* @date: 26/09/2018
*/
const wheelSurfModel = require('../models/wheel-surf');
const valid = require('../../../utils/validator');
const whSurfController = {
entry(req, res) {
if (req.xhr) {
return res.json({
code: 404,
message: 'invalid url'
});
}
res.render('activity/wheel-surf', {
bodyClass: 'nav-md',
module: 'admin',
page: 'wheel-surf'
});
},
async actCreate(req, res) {
const title = req.body.title;
const startTime = req.body.startTime;
const endTime = req.body.endTime;
const type = req.body.type || 0;
if (!title || !startTime || !endTime) {
return res.json({
code: 400,
message: '参数缺失'
});
}
const params = {
title,
startTime,
endTime,
type
};
try {
const result = await req.ctx(wheelSurfModel).create(params);
return res.json({ code: 200, data: result});
} catch (err) {
res.json(err);
}
},
async actDelete(req, res) {
const id = req.body.id;
try {
const result = await req.ctx(wheelSurfModel).actDelete(id);
return res.json({ code: 200, data: result});
} catch (err) {
res.json(err);
}
},
async actList(req, res) {
try {
const result = await req.ctx(wheelSurfModel).list();
return res.json({
code: 200,
data: result
});
} catch (err) {
res.json(err);
}
},
getConfigList: async function(req, res) {
let result = await req.ctx(wheelSurfModel).configList();
return res.json(result);
},
configModify: async function(req, res) {
try {
let data = valid(req.body, {
id: {type: 'number', empty: true},
act_id: {type: 'number', empty: false},
rule_btn_bg: {type: 'string', empty: true},
rule: {type: 'string', empty: true},
share_btn_bg: {type: 'string', empty: true},
share_url: {type: 'string', empty: true},
main_bg: {type: 'string', empty: true},
wheel_bg: {type: 'string', empty: true},
prize_btn_bg: {type: 'string', empty: true},
day_limit_times: {type: 'number', empty: true},
act_total_times: {type: 'number', empty: true},
day_over_limit_bg: {type: 'string', empty: true},
btm_tip_one: {type: 'string', empty: true},
btm_tip_two: {type: 'string', empty: true},
my_prize_btn: {type: 'string', empty: true},
jump_url: {type: 'string', empty: true},
win_prize_bg: {type: 'string', empty: true},
try_again_bg: {type: 'string', empty: true},
status: {type: 'number', empty: true}
});
let result = await req.ctx(wheelSurfModel).configModify(data);
return res.json({
code: 200,
data: result
});
} catch (e) {
return res.json({
code: 203,
result: false,
msg: e
});
}
},
configFindOne: async function(req, res) {
let actId = req.query.act_id;
if (!actId) {
return res.json({
code: 202,
result: false,
msg: '参数为空'
});
}
let result = await req.ctx(wheelSurfModel).configFindOne(actId);
return res.json({
code: 200,
data: result
});
},
prizeCreate: async function(req, res) {
let param = req.body;
try {
if (param instanceof Array) {
let arr = param.map((value) => {
return valid(value, {
act_id: {type: 'number', empty: false},
name: {type: 'string', empty: true},
type: {type: 'number', empty: true},
value: {type: 'string', empty: true},
img: {type: 'string', empty: true},
total: {type: 'number', empty: true},
total_left: {type: 'number', empty: true},
chance: {type: 'number', empty: true},
prize_bg: {type: 'string', empty: true},
prize_idx: {type: 'number', empty: true},
});
});
let result = await req.ctx(wheelSurfModel).prizeCreate(arr);
return res.json({
code: 200,
data: result
});
} else {
return res.json({
code: 202,
result: false,
msg: '参数格式错误'
});
}
} catch (e) {
return res.json({
code: 203,
result: false,
msg: e
});
}
},
prizeUpdate: async function(req, res) {
let param = req.body;
try {
if (param instanceof Array) {
let arr = param.map((value) => {
return valid(value, {
id: {type: 'number', empty: false},
act_id: {type: 'number', empty: false},
name: {type: 'string', empty: true},
type: {type: 'number', empty: true},
value: {type: 'string', empty: true},
img: {type: 'string', empty: true},
total: {type: 'number', empty: true},
total_left: {type: 'number', empty: true},
chance: {type: 'number', empty: true},
prize_bg: {type: 'string', empty: true},
prize_idx: {type: 'number', empty: true},
});
});
let result = await req.ctx(wheelSurfModel).prizeUpdate(arr);
return res.json({
code: 200,
data: result
});
} else {
return res.json({
code: 202,
result: false,
msg: '参数格式错误'
});
}
} catch (e) {
return res.json({
code: 203,
result: false,
msg: e
});
}
},
prizeFindByActId: async function(req, res) {
let actId = req.query.act_id;
if (!actId) {
return res.json({
code: 202,
result: false,
msg: '参数为空'
});
}
let result = await req.ctx(wheelSurfModel).prizeFindByActId(actId);
return res.json({
code: 200,
data: result
});
}
};
module.exports = whSurfController;