Showing
11 changed files
with
642 additions
and
461 deletions
apps/admin/controllers/activity.js
0 → 100644
1 | +/** | ||
2 | + * 文章controller | ||
3 | + * @author: leo <qi.li@yoho.cn> | ||
4 | + * @date: 23/06/2017 | ||
5 | + */ | ||
6 | +const _ = require('lodash'); | ||
7 | +const moment = require('moment'); | ||
8 | +const excelExport = require('excel-export'); | ||
9 | +const ActivityModel = require('../models/activity'); | ||
10 | + | ||
11 | +const POST_SUCCESS = '操作成功'; | ||
12 | +const INVALID_PARAMS = '参数错误'; | ||
13 | + | ||
14 | +const timeFormat = (time) => { | ||
15 | + if (_.isNumber(time)) { | ||
16 | + time = moment.unix(time); | ||
17 | + } | ||
18 | + | ||
19 | + return moment(time).format('YYYY-MM-DD HH:mm:ss'); | ||
20 | +}; | ||
21 | + | ||
22 | +const activity = { | ||
23 | + /** | ||
24 | + * 活动列表 | ||
25 | + * @param req | ||
26 | + * @param res | ||
27 | + * @param next | ||
28 | + */ | ||
29 | + activityList(req, res, next) { | ||
30 | + const title = req.body.title; | ||
31 | + const startTime = req.body.startTime; | ||
32 | + const endTime = req.body.endTime; | ||
33 | + | ||
34 | + if (!title || !startTime || !endTime) { | ||
35 | + return res.json({ | ||
36 | + code: 400, | ||
37 | + message: INVALID_PARAMS | ||
38 | + }); | ||
39 | + } | ||
40 | + | ||
41 | + const params = { | ||
42 | + title, | ||
43 | + startTime, | ||
44 | + endTime | ||
45 | + }; | ||
46 | + | ||
47 | + req.ctx(ActivityModel).createActivity(params) | ||
48 | + .then(() => { | ||
49 | + return res.json({ | ||
50 | + code: 200, | ||
51 | + message: POST_SUCCESS | ||
52 | + }); | ||
53 | + }) | ||
54 | + .catch(next); | ||
55 | + }, | ||
56 | + | ||
57 | + /** | ||
58 | + * 活动列表页 | ||
59 | + * @param req | ||
60 | + * @param res | ||
61 | + * @param next | ||
62 | + */ | ||
63 | + activityListPage(req, res, next) { | ||
64 | + | ||
65 | + | ||
66 | + req.ctx(ActivityModel).activityList() | ||
67 | + .then(result => { | ||
68 | + _.each(result, item => { | ||
69 | + item.endTime = timeFormat(item.endTime); | ||
70 | + item.startTime = timeFormat(item.startTime); | ||
71 | + item.createTime = timeFormat(item.createTime); | ||
72 | + }); | ||
73 | + | ||
74 | + res.render('activity/list', { | ||
75 | + bodyClass: 'nav-md', | ||
76 | + activityList: result, | ||
77 | + module: 'admin', | ||
78 | + page: 'activity' | ||
79 | + }); | ||
80 | + }) | ||
81 | + .catch(next); | ||
82 | + }, | ||
83 | + | ||
84 | + /** | ||
85 | + * 新建活动 | ||
86 | + * @param req | ||
87 | + * @param res | ||
88 | + * @param next | ||
89 | + */ | ||
90 | + createActivity(req, res, next) { | ||
91 | + const title = req.body.title; | ||
92 | + const startTime = req.body.startTime; | ||
93 | + const endTime = req.body.endTime; | ||
94 | + | ||
95 | + if (!title || !startTime || !endTime) { | ||
96 | + return res.json({ | ||
97 | + code: 400, | ||
98 | + message: INVALID_PARAMS | ||
99 | + }); | ||
100 | + } | ||
101 | + | ||
102 | + const params = { | ||
103 | + title, | ||
104 | + startTime, | ||
105 | + endTime | ||
106 | + }; | ||
107 | + | ||
108 | + req.ctx(ActivityModel).createActivity(params) | ||
109 | + .then(() => { | ||
110 | + return res.json({ | ||
111 | + code: 200, | ||
112 | + message: POST_SUCCESS | ||
113 | + }); | ||
114 | + }) | ||
115 | + .catch(next); | ||
116 | + }, | ||
117 | + | ||
118 | + /** | ||
119 | + * 新建活动页 | ||
120 | + * @param req | ||
121 | + * @param res | ||
122 | + */ | ||
123 | + createActivityPage(req, res) { | ||
124 | + res.render('activity/create', { | ||
125 | + bodyClass: 'nav-md', | ||
126 | + module: 'admin', | ||
127 | + page: 'activity' | ||
128 | + }); | ||
129 | + }, | ||
130 | + | ||
131 | + /** | ||
132 | + * 活动删除 | ||
133 | + * @param req | ||
134 | + * @param res | ||
135 | + * @param next | ||
136 | + */ | ||
137 | + deleteActivity(req, res, next) { | ||
138 | + const id = req.body.id; | ||
139 | + | ||
140 | + if (!id) { | ||
141 | + return res.json({ | ||
142 | + code: 400, | ||
143 | + message: INVALID_PARAMS | ||
144 | + }); | ||
145 | + } | ||
146 | + | ||
147 | + req.ctx(ActivityModel).deleteActivity(id) | ||
148 | + .then(() => { | ||
149 | + return res.json({ | ||
150 | + code: 200, | ||
151 | + message: POST_SUCCESS | ||
152 | + }); | ||
153 | + }) | ||
154 | + .catch(next); | ||
155 | + }, | ||
156 | + | ||
157 | + /** | ||
158 | + * 活动文章列表 | ||
159 | + * @param req | ||
160 | + * @param res | ||
161 | + * @param next | ||
162 | + */ | ||
163 | + actArticleListPage(req, res, next) { | ||
164 | + const actId = req.query.actId; | ||
165 | + | ||
166 | + req.ctx(ActivityModel).actArticleList(actId) | ||
167 | + .then(result => { | ||
168 | + _.each(result, item => { | ||
169 | + item.createTime = timeFormat(item.createTime); | ||
170 | + }); | ||
171 | + res.render('activity/article-list', { | ||
172 | + actId, | ||
173 | + bodyClass: 'nav-md', | ||
174 | + articleList: result, | ||
175 | + module: 'admin', | ||
176 | + page: 'activity' | ||
177 | + }); | ||
178 | + }) | ||
179 | + .catch(next); | ||
180 | + }, | ||
181 | + | ||
182 | + /** | ||
183 | + * 删除文章 | ||
184 | + * @param req | ||
185 | + * @param res | ||
186 | + * @param next | ||
187 | + */ | ||
188 | + deleteArticle(req, res, next) { | ||
189 | + const id = req.body.id; | ||
190 | + | ||
191 | + if (!id) { | ||
192 | + return res.json({ | ||
193 | + code: 400, | ||
194 | + message: INVALID_PARAMS | ||
195 | + }); | ||
196 | + } | ||
197 | + | ||
198 | + req.ctx(ActivityModel).deleteArticle(id) | ||
199 | + .then(() => { | ||
200 | + return res.json({ | ||
201 | + code: 200, | ||
202 | + message: POST_SUCCESS | ||
203 | + }); | ||
204 | + }) | ||
205 | + .catch(next); | ||
206 | + }, | ||
207 | + | ||
208 | + /** | ||
209 | + * 文章列表导出 | ||
210 | + * @param req | ||
211 | + * @param res | ||
212 | + * @param next | ||
213 | + */ | ||
214 | + exportArticleList(req, res, next) { | ||
215 | + const actId = req.query.actId; | ||
216 | + | ||
217 | + if (!actId) { | ||
218 | + return res.json({ | ||
219 | + code: 400, | ||
220 | + message: INVALID_PARAMS | ||
221 | + }); | ||
222 | + } | ||
223 | + | ||
224 | + let conf = { | ||
225 | + name: 'mysheet', | ||
226 | + cols: [ | ||
227 | + { | ||
228 | + caption: '文章ID', | ||
229 | + type: 'string' | ||
230 | + }, | ||
231 | + { | ||
232 | + caption: '赞数', | ||
233 | + type: 'number' | ||
234 | + }, | ||
235 | + { | ||
236 | + caption: '发布者', | ||
237 | + type: 'string' | ||
238 | + }, | ||
239 | + { | ||
240 | + caption: '手机号', | ||
241 | + type: 'string' | ||
242 | + }, | ||
243 | + { | ||
244 | + caption: '创建时间', | ||
245 | + type: 'string' | ||
246 | + } | ||
247 | + ], | ||
248 | + rows: [] | ||
249 | + }; | ||
250 | + | ||
251 | + req.ctx(ActivityModel).actArticleList(actId) | ||
252 | + .then(result => { | ||
253 | + let temp = []; | ||
254 | + | ||
255 | + _.each(result, item => { | ||
256 | + temp = []; | ||
257 | + temp.push(item.id); | ||
258 | + temp.push(item.goodCount); | ||
259 | + temp.push(item.userName); | ||
260 | + temp.push(item.phone); | ||
261 | + temp.push(timeFormat(item.createTime)); | ||
262 | + conf.rows.push(temp); | ||
263 | + }); | ||
264 | + | ||
265 | + let exportFile = excelExport.execute(conf); | ||
266 | + | ||
267 | + res.setHeader('Content-Type', 'application/vnd.openxmlformats'); | ||
268 | + res.setHeader('Content-Disposition', 'attachment; filename=articleList.xlsx'); | ||
269 | + res.end(exportFile, 'binary'); | ||
270 | + }) | ||
271 | + .catch(next); | ||
272 | + | ||
273 | + }, | ||
274 | + | ||
275 | + /** | ||
276 | + * 活动参与用户列表 | ||
277 | + * @param req | ||
278 | + * @param res | ||
279 | + * @param next | ||
280 | + */ | ||
281 | + activityUserListPage(req, res, next) { | ||
282 | + req.ctx(ActivityModel).activityList() | ||
283 | + .then(result => { | ||
284 | + res.render('activity/user-list', { | ||
285 | + bodyClass: 'nav-md', | ||
286 | + activityList: result, | ||
287 | + module: 'admin', | ||
288 | + page: 'activity' | ||
289 | + }); | ||
290 | + }) | ||
291 | + .catch(next); | ||
292 | + } | ||
293 | +}; | ||
294 | + | ||
295 | + | ||
296 | +module.exports = activity; |
@@ -4,22 +4,8 @@ | @@ -4,22 +4,8 @@ | ||
4 | * @date: 23/06/2017 | 4 | * @date: 23/06/2017 |
5 | */ | 5 | */ |
6 | const _ = require('lodash'); | 6 | const _ = require('lodash'); |
7 | -const moment = require('moment'); | ||
8 | -const excelExport = require('excel-export'); | ||
9 | -const AdminModel = require('../models/admin'); | ||
10 | 7 | ||
11 | -const POST_SUCCESS = '操作成功'; | ||
12 | -const INVALID_PARAMS = '参数错误'; | ||
13 | - | ||
14 | -const timeFormat = (time) => { | ||
15 | - if (_.isNumber(time)) { | ||
16 | - time = moment.unix(time); | ||
17 | - } | ||
18 | - | ||
19 | - return moment(time).format('YYYY-MM-DD HH:mm:ss'); | ||
20 | -}; | ||
21 | - | ||
22 | -const article = { | 8 | +const adminController = { |
23 | /** | 9 | /** |
24 | * 首页 | 10 | * 首页 |
25 | * @param req | 11 | * @param req |
@@ -90,279 +76,8 @@ const article = { | @@ -90,279 +76,8 @@ const article = { | ||
90 | code: 200, | 76 | code: 200, |
91 | message: '登出成功' | 77 | message: '登出成功' |
92 | }); | 78 | }); |
93 | - }, | ||
94 | - | ||
95 | - /** | ||
96 | - * 活动列表 | ||
97 | - * @param req | ||
98 | - * @param res | ||
99 | - * @param next | ||
100 | - */ | ||
101 | - activityList(req, res, next) { | ||
102 | - const title = req.body.title; | ||
103 | - const startTime = req.body.startTime; | ||
104 | - const endTime = req.body.endTime; | ||
105 | - | ||
106 | - if (!title || !startTime || !endTime) { | ||
107 | - return res.json({ | ||
108 | - code: 400, | ||
109 | - message: INVALID_PARAMS | ||
110 | - }); | ||
111 | - } | ||
112 | - | ||
113 | - const params = { | ||
114 | - title, | ||
115 | - startTime, | ||
116 | - endTime | ||
117 | - }; | ||
118 | - | ||
119 | - req.ctx(AdminModel).createActivity(params) | ||
120 | - .then(() => { | ||
121 | - return res.json({ | ||
122 | - code: 200, | ||
123 | - message: POST_SUCCESS | ||
124 | - }); | ||
125 | - }) | ||
126 | - .catch(next); | ||
127 | - }, | ||
128 | - | ||
129 | - /** | ||
130 | - * 活动列表页 | ||
131 | - * @param req | ||
132 | - * @param res | ||
133 | - * @param next | ||
134 | - */ | ||
135 | - activityListPage(req, res, next) { | ||
136 | - | ||
137 | - | ||
138 | - req.ctx(AdminModel).activityList() | ||
139 | - .then(result => { | ||
140 | - _.each(result, item => { | ||
141 | - item.endTime = timeFormat(item.endTime); | ||
142 | - item.startTime = timeFormat(item.startTime); | ||
143 | - item.createTime = timeFormat(item.createTime); | ||
144 | - }); | ||
145 | - | ||
146 | - res.render('activity/list', { | ||
147 | - bodyClass: 'nav-md', | ||
148 | - activityList: result, | ||
149 | - module: 'admin', | ||
150 | - page: 'activity' | ||
151 | - }); | ||
152 | - }) | ||
153 | - .catch(next); | ||
154 | - }, | ||
155 | - | ||
156 | - /** | ||
157 | - * 新建活动 | ||
158 | - * @param req | ||
159 | - * @param res | ||
160 | - * @param next | ||
161 | - */ | ||
162 | - createActivity(req, res, next) { | ||
163 | - const title = req.body.title; | ||
164 | - const startTime = req.body.startTime; | ||
165 | - const endTime = req.body.endTime; | ||
166 | - | ||
167 | - if (!title || !startTime || !endTime) { | ||
168 | - return res.json({ | ||
169 | - code: 400, | ||
170 | - message: INVALID_PARAMS | ||
171 | - }); | ||
172 | - } | ||
173 | - | ||
174 | - const params = { | ||
175 | - title, | ||
176 | - startTime, | ||
177 | - endTime | ||
178 | - }; | ||
179 | - | ||
180 | - req.ctx(AdminModel).createActivity(params) | ||
181 | - .then(() => { | ||
182 | - return res.json({ | ||
183 | - code: 200, | ||
184 | - message: POST_SUCCESS | ||
185 | - }); | ||
186 | - }) | ||
187 | - .catch(next); | ||
188 | - }, | ||
189 | - | ||
190 | - /** | ||
191 | - * 新建活动页 | ||
192 | - * @param req | ||
193 | - * @param res | ||
194 | - */ | ||
195 | - createActivityPage(req, res) { | ||
196 | - res.render('activity/create', { | ||
197 | - bodyClass: 'nav-md', | ||
198 | - module: 'admin', | ||
199 | - page: 'activity' | ||
200 | - }); | ||
201 | - }, | ||
202 | - | ||
203 | - /** | ||
204 | - * 活动删除 | ||
205 | - * @param req | ||
206 | - * @param res | ||
207 | - * @param next | ||
208 | - */ | ||
209 | - deleteActivity(req, res, next) { | ||
210 | - const id = req.body.id; | ||
211 | - | ||
212 | - if (!id) { | ||
213 | - return res.json({ | ||
214 | - code: 400, | ||
215 | - message: INVALID_PARAMS | ||
216 | - }); | ||
217 | - } | ||
218 | - | ||
219 | - req.ctx(AdminModel).deleteActivity(id) | ||
220 | - .then(() => { | ||
221 | - return res.json({ | ||
222 | - code: 200, | ||
223 | - message: POST_SUCCESS | ||
224 | - }); | ||
225 | - }) | ||
226 | - .catch(next); | ||
227 | - }, | ||
228 | - | ||
229 | - /** | ||
230 | - * 活动文章列表 | ||
231 | - * @param req | ||
232 | - * @param res | ||
233 | - * @param next | ||
234 | - */ | ||
235 | - actArticleListPage(req, res, next) { | ||
236 | - const actId = req.query.actId; | ||
237 | - | ||
238 | - req.ctx(AdminModel).actArticleList(actId) | ||
239 | - .then(result => { | ||
240 | - _.each(result, item => { | ||
241 | - item.createTime = timeFormat(item.createTime); | ||
242 | - }); | ||
243 | - res.render('activity/article-list', { | ||
244 | - actId, | ||
245 | - bodyClass: 'nav-md', | ||
246 | - articleList: result, | ||
247 | - module: 'admin', | ||
248 | - page: 'activity' | ||
249 | - }); | ||
250 | - }) | ||
251 | - .catch(next); | ||
252 | - }, | ||
253 | - | ||
254 | - /** | ||
255 | - * 删除文章 | ||
256 | - * @param req | ||
257 | - * @param res | ||
258 | - * @param next | ||
259 | - */ | ||
260 | - deleteArticle(req, res, next) { | ||
261 | - const id = req.body.id; | ||
262 | - | ||
263 | - if (!id) { | ||
264 | - return res.json({ | ||
265 | - code: 400, | ||
266 | - message: INVALID_PARAMS | ||
267 | - }); | ||
268 | - } | ||
269 | - | ||
270 | - req.ctx(AdminModel).deleteArticle(id) | ||
271 | - .then(() => { | ||
272 | - return res.json({ | ||
273 | - code: 200, | ||
274 | - message: POST_SUCCESS | ||
275 | - }); | ||
276 | - }) | ||
277 | - .catch(next); | ||
278 | - }, | ||
279 | - | ||
280 | - /** | ||
281 | - * 文章列表导出 | ||
282 | - * @param req | ||
283 | - * @param res | ||
284 | - * @param next | ||
285 | - */ | ||
286 | - exportArticleList(req, res, next) { | ||
287 | - const actId = req.query.actId; | ||
288 | - | ||
289 | - if (!actId) { | ||
290 | - return res.json({ | ||
291 | - code: 400, | ||
292 | - message: INVALID_PARAMS | ||
293 | - }); | ||
294 | - } | ||
295 | - | ||
296 | - let conf = { | ||
297 | - name: 'mysheet', | ||
298 | - cols: [ | ||
299 | - { | ||
300 | - caption: '文章ID', | ||
301 | - type: 'string' | ||
302 | - }, | ||
303 | - { | ||
304 | - caption: '赞数', | ||
305 | - type: 'number' | ||
306 | - }, | ||
307 | - { | ||
308 | - caption: '发布者', | ||
309 | - type: 'string' | ||
310 | - }, | ||
311 | - { | ||
312 | - caption: '手机号', | ||
313 | - type: 'string' | ||
314 | - }, | ||
315 | - { | ||
316 | - caption: '创建时间', | ||
317 | - type: 'string' | ||
318 | - } | ||
319 | - ], | ||
320 | - rows: [] | ||
321 | - }; | ||
322 | - | ||
323 | - req.ctx(AdminModel).actArticleList(actId) | ||
324 | - .then(result => { | ||
325 | - let temp = []; | ||
326 | - | ||
327 | - _.each(result, item => { | ||
328 | - temp = []; | ||
329 | - temp.push(item.id); | ||
330 | - temp.push(item.goodCount); | ||
331 | - temp.push(item.userName); | ||
332 | - temp.push(item.phone); | ||
333 | - temp.push(timeFormat(item.createTime)); | ||
334 | - conf.rows.push(temp); | ||
335 | - }); | ||
336 | - | ||
337 | - let exportFile = excelExport.execute(conf); | ||
338 | - | ||
339 | - res.setHeader('Content-Type', 'application/vnd.openxmlformats'); | ||
340 | - res.setHeader('Content-Disposition', 'attachment; filename=articleList.xlsx'); | ||
341 | - res.end(exportFile, 'binary'); | ||
342 | - }) | ||
343 | - .catch(next); | ||
344 | - | ||
345 | - }, | ||
346 | - | ||
347 | - /** | ||
348 | - * 活动参与用户列表 | ||
349 | - * @param req | ||
350 | - * @param res | ||
351 | - * @param next | ||
352 | - */ | ||
353 | - activityUserListPage(req, res, next) { | ||
354 | - req.ctx(AdminModel).activityList() | ||
355 | - .then(result => { | ||
356 | - res.render('activity/user-list', { | ||
357 | - bodyClass: 'nav-md', | ||
358 | - activityList: result, | ||
359 | - module: 'admin', | ||
360 | - page: 'activity' | ||
361 | - }); | ||
362 | - }) | ||
363 | - .catch(next); | ||
364 | } | 79 | } |
365 | }; | 80 | }; |
366 | 81 | ||
367 | 82 | ||
368 | -module.exports = article; | 83 | +module.exports = adminController; |
apps/admin/controllers/user.js
0 → 100644
1 | +/** | ||
2 | + * 用户管理controller | ||
3 | + * @author: leo <qi.li@yoho.cn> | ||
4 | + * @date: 23/06/2017 | ||
5 | + */ | ||
6 | +const _ = require('lodash'); | ||
7 | +const moment = require('moment'); | ||
8 | +const excelExport = require('excel-export'); | ||
9 | +const UserModel = require('../models/user'); | ||
10 | + | ||
11 | +const DO_SUCCESS = '操作成功'; | ||
12 | + | ||
13 | +const timeFmt = (time) => { | ||
14 | + if (_.isNumber(time)) { | ||
15 | + time = moment.unix(time); | ||
16 | + } | ||
17 | + | ||
18 | + return moment(time).format('YYYY-MM-DD HH:mm:ss'); | ||
19 | +}; | ||
20 | + | ||
21 | +const userController = { | ||
22 | + /** | ||
23 | + * 用户列表页 | ||
24 | + * @param req | ||
25 | + * @param res | ||
26 | + * @param next | ||
27 | + */ | ||
28 | + userListPage(req, res, next) { | ||
29 | + req.ctx(UserModel).userList() | ||
30 | + .then(result => { | ||
31 | + | ||
32 | + _.map(result, item => { | ||
33 | + item.createTime = timeFmt( | ||
34 | + item.createTime | ||
35 | + ); | ||
36 | + }); | ||
37 | + | ||
38 | + res.render('user/list', { | ||
39 | + bodyClass: 'nav-md', | ||
40 | + userList: result, | ||
41 | + module: 'admin', | ||
42 | + page: 'user' | ||
43 | + }); | ||
44 | + }) | ||
45 | + .catch(next); | ||
46 | + }, | ||
47 | + | ||
48 | + /** | ||
49 | + * 用户删除 | ||
50 | + * @param req | ||
51 | + * @param res | ||
52 | + * @param next | ||
53 | + */ | ||
54 | + deleteUser(req, res, next) { | ||
55 | + const userId = req.body.userId; | ||
56 | + | ||
57 | + req.ctx(UserModel).deleteUser(userId) | ||
58 | + .then(() => { | ||
59 | + res.json({ | ||
60 | + code: 200, | ||
61 | + message: DO_SUCCESS | ||
62 | + }); | ||
63 | + }) | ||
64 | + .catch(next); | ||
65 | + }, | ||
66 | + | ||
67 | + /** | ||
68 | + * 用户列表导出 | ||
69 | + * @param req | ||
70 | + * @param res | ||
71 | + * @param next | ||
72 | + */ | ||
73 | + exportUserList(req, res, next) { | ||
74 | + let conf = { | ||
75 | + name: 'mysheet', | ||
76 | + cols: [ | ||
77 | + { | ||
78 | + caption: '用户ID', | ||
79 | + type: 'number' | ||
80 | + }, | ||
81 | + { | ||
82 | + caption: '昵称', | ||
83 | + type: 'string' | ||
84 | + }, | ||
85 | + { | ||
86 | + caption: '手机号', | ||
87 | + type: 'string' | ||
88 | + }, | ||
89 | + { | ||
90 | + caption: '创建时间', | ||
91 | + type: 'string' | ||
92 | + } | ||
93 | + ], | ||
94 | + rows: [] | ||
95 | + }; | ||
96 | + | ||
97 | + req.ctx(UserModel).userList() | ||
98 | + .then(result => { | ||
99 | + let temp = []; | ||
100 | + | ||
101 | + _.each(result, item => { | ||
102 | + temp = []; | ||
103 | + temp.push(item.id); | ||
104 | + temp.push(item.userName); | ||
105 | + temp.push(item.userPhone); | ||
106 | + temp.push(timeFmt(item.createTime)); | ||
107 | + conf.rows.push(temp); | ||
108 | + }); | ||
109 | + | ||
110 | + let exportFile = excelExport.execute(conf); | ||
111 | + | ||
112 | + res.setHeader('Content-Type', 'application/vnd.openxmlformats'); | ||
113 | + res.setHeader('Content-Disposition', 'attachment; filename=articleList.xlsx'); | ||
114 | + res.end(exportFile, 'binary'); | ||
115 | + }) | ||
116 | + .catch(next); | ||
117 | + } | ||
118 | +}; | ||
119 | + | ||
120 | + | ||
121 | +module.exports = userController; |
apps/admin/models/activity.js
0 → 100644
1 | +/** | ||
2 | + * 管理model | ||
3 | + * @author: leo <qi.li@yoho.cn> | ||
4 | + * @date: 28/06/2017 | ||
5 | + */ | ||
6 | + | ||
7 | +const mysqlCli = global.yoho.utils.mysqlCli; | ||
8 | + | ||
9 | +const TABLE_ACTIVITY = 'activity'; | ||
10 | +const TABLE_ACT_ARTICLE = 'act_article'; | ||
11 | +const TABLE_USER = 'user'; | ||
12 | + | ||
13 | +class AdminModel extends global.yoho.BaseModel { | ||
14 | + constructor(ctx) { | ||
15 | + super(ctx); | ||
16 | + } | ||
17 | + | ||
18 | + /** | ||
19 | + * 创建活动 | ||
20 | + * @param title 活动标题 | ||
21 | + * @param startTime 活动开始时间 | ||
22 | + * @param endTime 活动结束时间 | ||
23 | + * @returns {*} | ||
24 | + */ | ||
25 | + createActivity({title, startTime, endTime}) { | ||
26 | + return mysqlCli.insert( | ||
27 | + `insert into ${TABLE_ACTIVITY} (title, start_time, end_time) values (:title, :startTime, :endTime);`, | ||
28 | + { | ||
29 | + title, | ||
30 | + startTime, | ||
31 | + endTime | ||
32 | + } | ||
33 | + ); | ||
34 | + } | ||
35 | + | ||
36 | + /** | ||
37 | + * 活动列表 | ||
38 | + * @returns {*} | ||
39 | + */ | ||
40 | + activityList() { | ||
41 | + return mysqlCli.query( | ||
42 | + `select id, title, start_time startTime, end_time endTime, create_time createTime from ${TABLE_ACTIVITY};` | ||
43 | + ); | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * 删除活动 | ||
48 | + * @param actId 活动ID | ||
49 | + * @returns {*} | ||
50 | + */ | ||
51 | + deleteActivity(actId) { | ||
52 | + return mysqlCli.delete( | ||
53 | + `delete from ${TABLE_ACTIVITY} where id = :actId;`, | ||
54 | + { | ||
55 | + actId | ||
56 | + } | ||
57 | + ); | ||
58 | + } | ||
59 | + | ||
60 | + /** | ||
61 | + * 活动文章列表 | ||
62 | + * @returns {*} | ||
63 | + */ | ||
64 | + actArticleList(actId) { | ||
65 | + return mysqlCli.query( | ||
66 | + `select taa.id, taa.create_time createTime, taa.good_count goodCount, | ||
67 | + tu.user_name userName, tu.user_phone phone | ||
68 | + from ${TABLE_ACT_ARTICLE} taa | ||
69 | + left join ${TABLE_USER} tu | ||
70 | + on taa.user_id = tu.id | ||
71 | + where act_id = :actId;`, { | ||
72 | + actId | ||
73 | + } | ||
74 | + ); | ||
75 | + } | ||
76 | + | ||
77 | + /** | ||
78 | + * 删除文章 | ||
79 | + * @param id 文章ID | ||
80 | + * @returns {*} | ||
81 | + */ | ||
82 | + deleteArticle(id) { | ||
83 | + return mysqlCli.delete( | ||
84 | + `delete from ${TABLE_ACT_ARTICLE} where id = :id;`, | ||
85 | + { | ||
86 | + id | ||
87 | + } | ||
88 | + ); | ||
89 | + } | ||
90 | + | ||
91 | + /** | ||
92 | + * 参与活动用户列表 | ||
93 | + * @returns {*} | ||
94 | + */ | ||
95 | + activityUserList(actId) { | ||
96 | + return mysqlCli.query( | ||
97 | + `select tu.user_phone phone | ||
98 | + from ${TABLE_ACTIVITY} ta | ||
99 | + inner join act_article taa | ||
100 | + on ta.id = taa.act_id | ||
101 | + inner join user tu | ||
102 | + on taa.user_id = tu.id | ||
103 | + where ta.id = :actId;`, { | ||
104 | + actId | ||
105 | + } | ||
106 | + ); | ||
107 | + } | ||
108 | +} | ||
109 | + | ||
110 | +module.exports = AdminModel; | ||
111 | + | ||
112 | + | ||
113 | + |
1 | /** | 1 | /** |
2 | - * 管理model | 2 | + * 管理员model |
3 | * @author: leo <qi.li@yoho.cn> | 3 | * @author: leo <qi.li@yoho.cn> |
4 | * @date: 28/06/2017 | 4 | * @date: 28/06/2017 |
5 | */ | 5 | */ |
6 | - | ||
7 | -const mysqlCli = global.yoho.utils.mysqlCli; | ||
8 | - | ||
9 | -const TABLE_ACTIVITY = 'activity'; | ||
10 | -const TABLE_ACT_ARTICLE = 'act_article'; | ||
11 | -const TABLE_USER = 'user'; | ||
12 | - | ||
13 | class AdminModel extends global.yoho.BaseModel { | 6 | class AdminModel extends global.yoho.BaseModel { |
14 | constructor(ctx) { | 7 | constructor(ctx) { |
15 | super(ctx); | 8 | super(ctx); |
16 | } | 9 | } |
17 | - | ||
18 | - /** | ||
19 | - * 创建活动 | ||
20 | - * @param title 活动标题 | ||
21 | - * @param startTime 活动开始时间 | ||
22 | - * @param endTime 活动结束时间 | ||
23 | - * @returns {*} | ||
24 | - */ | ||
25 | - createActivity({title, startTime, endTime}) { | ||
26 | - return mysqlCli.insert( | ||
27 | - `insert into ${TABLE_ACTIVITY} (title, start_time, end_time) values (:title, :startTime, :endTime);`, | ||
28 | - { | ||
29 | - title, | ||
30 | - startTime, | ||
31 | - endTime | ||
32 | - } | ||
33 | - ); | ||
34 | - } | ||
35 | - | ||
36 | - /** | ||
37 | - * 活动列表 | ||
38 | - * @returns {*} | ||
39 | - */ | ||
40 | - activityList() { | ||
41 | - return mysqlCli.query( | ||
42 | - `select id, title, start_time startTime, end_time endTime, create_time createTime from ${TABLE_ACTIVITY};` | ||
43 | - ); | ||
44 | - } | ||
45 | - | ||
46 | - /** | ||
47 | - * 删除活动 | ||
48 | - * @param actId 活动ID | ||
49 | - * @returns {*} | ||
50 | - */ | ||
51 | - deleteActivity(actId) { | ||
52 | - return mysqlCli.delete( | ||
53 | - `delete from ${TABLE_ACTIVITY} where id = :actId;`, | ||
54 | - { | ||
55 | - actId | ||
56 | - } | ||
57 | - ); | ||
58 | - } | ||
59 | - | ||
60 | - /** | ||
61 | - * 活动文章列表 | ||
62 | - * @returns {*} | ||
63 | - */ | ||
64 | - actArticleList(actId) { | ||
65 | - return mysqlCli.query( | ||
66 | - `select taa.id, taa.create_time createTime, taa.good_count goodCount, | ||
67 | - tu.user_name userName, tu.user_phone phone | ||
68 | - from ${TABLE_ACT_ARTICLE} taa | ||
69 | - inner join ${TABLE_USER} tu | ||
70 | - on taa.user_id = tu.id | ||
71 | - where act_id = :actId;`, { | ||
72 | - actId | ||
73 | - } | ||
74 | - ); | ||
75 | - } | ||
76 | - | ||
77 | - /** | ||
78 | - * 删除文章 | ||
79 | - * @param id 文章ID | ||
80 | - * @returns {*} | ||
81 | - */ | ||
82 | - deleteArticle(id) { | ||
83 | - return mysqlCli.delete( | ||
84 | - `delete from ${TABLE_ACT_ARTICLE} where id = :id;`, | ||
85 | - { | ||
86 | - id | ||
87 | - } | ||
88 | - ); | ||
89 | - } | ||
90 | - | ||
91 | - /** | ||
92 | - * 参与活动用户列表 | ||
93 | - * @returns {*} | ||
94 | - */ | ||
95 | - activityUserList(actId) { | ||
96 | - return mysqlCli.query( | ||
97 | - `select tu.user_phone phone | ||
98 | - from ${TABLE_ACTIVITY} ta | ||
99 | - inner join act_article taa | ||
100 | - on ta.id = taa.act_id | ||
101 | - inner join user tu | ||
102 | - on taa.user_id = tu.id | ||
103 | - where ta.id = :actId;`, { | ||
104 | - actId | ||
105 | - } | ||
106 | - ); | ||
107 | - } | ||
108 | } | 10 | } |
109 | 11 | ||
110 | module.exports = AdminModel; | 12 | module.exports = AdminModel; |
apps/admin/models/user.js
0 → 100644
1 | +/** | ||
2 | + * 用户管理model | ||
3 | + * @author: leo <qi.li@yoho.cn> | ||
4 | + * @date: 28/06/2017 | ||
5 | + */ | ||
6 | + | ||
7 | +const mysqlCli = global.yoho.utils.mysqlCli; | ||
8 | + | ||
9 | +const TABLE_USER = 'user'; | ||
10 | + | ||
11 | +class UserModel extends global.yoho.BaseModel { | ||
12 | + constructor(ctx) { | ||
13 | + super(ctx); | ||
14 | + } | ||
15 | + | ||
16 | + /** | ||
17 | + * 用户列表 | ||
18 | + * @returns {*} | ||
19 | + */ | ||
20 | + userList() { | ||
21 | + return mysqlCli.query( | ||
22 | + `select id, user_phone userPhone, user_name userName, create_time createTime from ${TABLE_USER};` | ||
23 | + ); | ||
24 | + } | ||
25 | + | ||
26 | + /** | ||
27 | + * 用户删除 | ||
28 | + * @returns {*} | ||
29 | + */ | ||
30 | + deleteUser(userId) { | ||
31 | + return mysqlCli.delete( | ||
32 | + `delete from ${TABLE_USER} where id = :userId;`, { | ||
33 | + userId | ||
34 | + } | ||
35 | + ); | ||
36 | + } | ||
37 | + | ||
38 | +} | ||
39 | + | ||
40 | +module.exports = UserModel; | ||
41 | + | ||
42 | + | ||
43 | + |
@@ -6,23 +6,36 @@ | @@ -6,23 +6,36 @@ | ||
6 | const express = require('express'); | 6 | const express = require('express'); |
7 | const router = express.Router(); // eslint-disable-line | 7 | const router = express.Router(); // eslint-disable-line |
8 | const admin = require('./controllers/admin'); | 8 | const admin = require('./controllers/admin'); |
9 | +const activity = require('./controllers/activity'); | ||
10 | +const user = require('./controllers/user'); | ||
9 | 11 | ||
10 | router.get('/login', admin.loginPage); | 12 | router.get('/login', admin.loginPage); |
11 | router.get('/home', admin.homePage); | 13 | router.get('/home', admin.homePage); |
12 | 14 | ||
13 | -// 活动管理 | ||
14 | -router.get('/activity/list', admin.activityListPage); | ||
15 | -router.get('/activity/create', admin.createActivityPage); | ||
16 | -router.get('/activity/user', admin.activityUserListPage); | ||
17 | -router.get('/activity/article', admin.actArticleListPage); | 15 | + |
16 | + | ||
17 | +// 活动管理[menu] | ||
18 | +router.get('/activity/list', activity.activityListPage); | ||
19 | +router.get('/activity/create', activity.createActivityPage); | ||
20 | +router.get('/activity/article', activity.actArticleListPage); | ||
21 | + | ||
22 | +// 用户管理[menu] | ||
23 | +router.get('/user/list', user.userListPage); | ||
18 | 24 | ||
19 | // ajax | 25 | // ajax |
20 | router.post('/api/login', admin.login); | 26 | router.post('/api/login', admin.login); |
21 | router.post('/api/logout', admin.logout); | 27 | router.post('/api/logout', admin.logout); |
22 | -router.post('/api/activity/list', admin.activityList); | ||
23 | -router.post('/api/activity/create', admin.createActivity); | ||
24 | -router.post('/api/activity/delete', admin.deleteActivity); | ||
25 | -router.post('/api/activity/deleteArticle', admin.deleteArticle); | ||
26 | -router.get('/api/activity/exportArticleList', admin.exportArticleList); | 28 | + |
29 | +// 活动管理[ajax] | ||
30 | +router.post('/api/activity/list', activity.activityList); | ||
31 | +router.post('/api/activity/create', activity.createActivity); | ||
32 | +router.post('/api/activity/delete', activity.deleteActivity); | ||
33 | +router.post('/api/activity/deleteArticle', activity.deleteArticle); | ||
34 | +router.get('/api/activity/exportArticleList', activity.exportArticleList); | ||
35 | + | ||
36 | + | ||
37 | +// 用户管理[ajax] | ||
38 | +router.post('/api/user/delete', user.deleteUser); | ||
39 | +router.get('/api/user/exportUserList', user.exportUserList); | ||
27 | 40 | ||
28 | module.exports = router; | 41 | module.exports = router; |
@@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
8 | <h2>文章列表</h2> | 8 | <h2>文章列表</h2> |
9 | <div class="clearfix"></div> | 9 | <div class="clearfix"></div> |
10 | </div> | 10 | </div> |
11 | - <button class="btn btn-primary btn-export-article" data-id="{{actId}}">列表导出</button> | 11 | + <button class="btn btn-primary btn-export-article" data-id="{{actId}}">导出列表</button> |
12 | <div class="x_content"> | 12 | <div class="x_content"> |
13 | <div class="table-responsive"> | 13 | <div class="table-responsive"> |
14 | <table class="table table-striped jambo_table bulk_action"> | 14 | <table class="table table-striped jambo_table bulk_action"> |
1 | -<!-- page content --> | ||
2 | -<div class="right_col" role="main"> | ||
3 | - <div class=""> | ||
4 | - <div class="row"> | ||
5 | - <div class="col-md-12 col-sm-12 col-xs-12"> | ||
6 | - <div class="x_panel"> | ||
7 | - <div class="x_title"> | ||
8 | - <h2>活动列表</h2> | ||
9 | - <div class="clearfix"></div> | ||
10 | - </div> | ||
11 | - | ||
12 | - <div class="x_content"> | ||
13 | - <div class="table-responsive"> | ||
14 | - <table class="table table-striped jambo_table bulk_action"> | ||
15 | - <thead> | ||
16 | - <tr class="headings"> | ||
17 | - <th class="column-title">活动名称</th> | ||
18 | - <th class="column-title">开始时间</th> | ||
19 | - <th class="column-title">结束时间</th> | ||
20 | - <th class="column-title">创建时间</th> | ||
21 | - <th class="column-title">活动状态</th> | ||
22 | - <th class="column-title">操作</th> | ||
23 | - </tr> | ||
24 | - </thead> | ||
25 | - | ||
26 | - <tbody> | ||
27 | - {{#each activityList}} | ||
28 | - <tr class="even pointer"> | ||
29 | - <td class=" ">{{title}}</td> | ||
30 | - <td class=" ">{{startTime}}</td> | ||
31 | - <td class=" ">{{endTime}}</td> | ||
32 | - <td class=" ">{{createTime}}</td> | ||
33 | - <td class=" ">未开始</td> | ||
34 | - <td class=" "> | ||
35 | - <button class="btn btn-info">活动文章</button> | ||
36 | - <button class="btn btn-success">用户统计</button> | ||
37 | - <button class="btn btn-primary">编辑</button> | ||
38 | - <button class="btn btn-danger btn-delete" data-id="{{id}}">删除</button> | ||
39 | - </td> | ||
40 | - </tr> | ||
41 | - {{/each}} | ||
42 | - </tbody> | ||
43 | - </table> | ||
44 | - </div> | ||
45 | - | ||
46 | - | ||
47 | - </div> | ||
48 | - </div> | ||
49 | - </div> | ||
50 | - </div> | ||
51 | - </div> | ||
52 | -</div> | ||
53 | -<!-- /page content --> |
@@ -8,32 +8,30 @@ | @@ -8,32 +8,30 @@ | ||
8 | <h2>用户列表</h2> | 8 | <h2>用户列表</h2> |
9 | <div class="clearfix"></div> | 9 | <div class="clearfix"></div> |
10 | </div> | 10 | </div> |
11 | - | 11 | + <button class="btn btn-primary btn-export-user-list" data-id="{{id}}">导出列表</button> |
12 | <div class="x_content"> | 12 | <div class="x_content"> |
13 | <div class="table-responsive"> | 13 | <div class="table-responsive"> |
14 | <table class="table table-striped jambo_table bulk_action"> | 14 | <table class="table table-striped jambo_table bulk_action"> |
15 | <thead> | 15 | <thead> |
16 | <tr class="headings"> | 16 | <tr class="headings"> |
17 | - <th class="column-title">活动ID</th> | ||
18 | - <th class="column-title">活动名称</th> | ||
19 | - <th class="column-title">开始时间</th> | ||
20 | - <th class="column-title">结束时间</th> | 17 | + <th class="column-title">ID</th> |
18 | + <th class="column-title">昵称</th> | ||
19 | + <th class="column-title">手机号</th> | ||
21 | <th class="column-title">创建时间</th> | 20 | <th class="column-title">创建时间</th> |
22 | <th class="column-title">操作</th> | 21 | <th class="column-title">操作</th> |
23 | </tr> | 22 | </tr> |
24 | </thead> | 23 | </thead> |
25 | 24 | ||
26 | <tbody> | 25 | <tbody> |
27 | - {{#each activityList}} | 26 | + {{#each userList}} |
28 | <tr class="even pointer"> | 27 | <tr class="even pointer"> |
29 | <td class="">{{id}}</td> | 28 | <td class="">{{id}}</td> |
30 | - <td class="">{{title}}</td> | ||
31 | - <td class="">{{startTime}}</td> | ||
32 | - <td class="">{{endTime}}</td> | 29 | + <td class="">{{userName}}</td> |
30 | + <td class="">{{userPhone}}</td> | ||
33 | <td class="">{{createTime}}</td> | 31 | <td class="">{{createTime}}</td> |
34 | <td class=""> | 32 | <td class=""> |
35 | - <a class="btn btn-info" href="/admin/activity/article?actId={{id}}">活动文章</a> | ||
36 | - <button class="btn btn-danger btn-delete" data-id="{{id}}">删除活动</button> | 33 | + <button class="btn btn-danger btn-delete-user" data-id="{{id}}">删除用户 |
34 | + </button> | ||
37 | </td> | 35 | </td> |
38 | </tr> | 36 | </tr> |
39 | {{/each}} | 37 | {{/each}} |
public/js/admin/user.page.js
0 → 100644
1 | +function bind_delete_user() { | ||
2 | + const deleteFn = function() { | ||
3 | + const userId = $(this).data('id'); | ||
4 | + | ||
5 | + $.ajax({ | ||
6 | + method: 'post', | ||
7 | + url: '/admin/api/user/delete', | ||
8 | + data: { | ||
9 | + userId | ||
10 | + } | ||
11 | + }) | ||
12 | + .then(() => { | ||
13 | + location.reload(); | ||
14 | + }); | ||
15 | + }; | ||
16 | + | ||
17 | + $('.btn-delete-user').on('click', deleteFn); | ||
18 | +} | ||
19 | + | ||
20 | +function bind_export_user_list() { | ||
21 | + const exportFn = function() { | ||
22 | + window.open('/admin/api/user/exportUserList', '_blank'); | ||
23 | + }; | ||
24 | + | ||
25 | + $('.btn-export-user-list').on('click', exportFn); | ||
26 | +} | ||
27 | + | ||
28 | +(function() { | ||
29 | + bind_delete_user(); | ||
30 | + bind_export_user_list(); | ||
31 | +}()); | ||
32 | + | ||
33 | + |
-
Please register or login to post a comment