Authored by 李奇

文章列表添加

@@ -208,6 +208,72 @@ const article = { @@ -208,6 +208,72 @@ const article = {
208 }); 208 });
209 }) 209 })
210 .catch(next); 210 .catch(next);
  211 + },
  212 +
  213 + /**
  214 + * 活动文章列表
  215 + * @param req
  216 + * @param res
  217 + * @param next
  218 + */
  219 + actArticleListPage(req, res, next) {
  220 + const actId = req.query.actId;
  221 +
  222 + req.ctx(AdminModel).actArticleList(actId)
  223 + .then(result => {
  224 + res.render('activity/article-list', {
  225 + bodyClass: 'nav-md',
  226 + articleList: result,
  227 + module: 'admin',
  228 + page: 'activity'
  229 + });
  230 + })
  231 + .catch(next);
  232 + },
  233 +
  234 + /**
  235 + * 删除文章
  236 + * @param req
  237 + * @param res
  238 + * @param next
  239 + */
  240 + deleteArticle(req, res, next) {
  241 + const id = req.body.id;
  242 +
  243 + if (!id) {
  244 + return res.json({
  245 + code: 400,
  246 + message: INVALID_PARAMS
  247 + });
  248 + }
  249 +
  250 + req.ctx(AdminModel).deleteArticle(id)
  251 + .then(() => {
  252 + return res.json({
  253 + code: 200,
  254 + message: POST_SUCCESS
  255 + });
  256 + })
  257 + .catch(next);
  258 + },
  259 +
  260 + /**
  261 + * 活动参与用户列表
  262 + * @param req
  263 + * @param res
  264 + * @param next
  265 + */
  266 + activityUserListPage(req, res, next) {
  267 + req.ctx(AdminModel).activityList()
  268 + .then(result => {
  269 + res.render('activity/user-list', {
  270 + bodyClass: 'nav-md',
  271 + activityList: result,
  272 + module: 'admin',
  273 + page: 'activity'
  274 + });
  275 + })
  276 + .catch(next);
211 } 277 }
212 }; 278 };
213 279
@@ -7,6 +7,8 @@ @@ -7,6 +7,8 @@
7 const mysqlCli = global.yoho.utils.mysqlCli; 7 const mysqlCli = global.yoho.utils.mysqlCli;
8 8
9 const TABLE_ACTIVITY = 'activity'; 9 const TABLE_ACTIVITY = 'activity';
  10 +const TABLE_ACT_ARTICLE = 'act_article';
  11 +const TABLE_USER = 'user';
10 12
11 class AdminModel extends global.yoho.BaseModel { 13 class AdminModel extends global.yoho.BaseModel {
12 constructor(ctx) { 14 constructor(ctx) {
@@ -54,6 +56,54 @@ class AdminModel extends global.yoho.BaseModel { @@ -54,6 +56,54 @@ class AdminModel extends global.yoho.BaseModel {
54 } 56 }
55 ); 57 );
56 } 58 }
  59 +
  60 + /**
  61 + * 活动文章列表
  62 + * @returns {*}
  63 + */
  64 + actArticleList(actId) {
  65 + return mysqlCli.query(
  66 + `select taa.id, taa.content, taa.good_count goodCount, tu.user_name userName
  67 + from ${TABLE_ACT_ARTICLE} taa
  68 + inner join ${TABLE_USER} tu
  69 + on taa.user_id = tu.id
  70 + where act_id = :actId;`, {
  71 + actId
  72 + }
  73 + );
  74 + }
  75 +
  76 + /**
  77 + * 删除文章
  78 + * @param id 文章ID
  79 + * @returns {*}
  80 + */
  81 + deleteArticle(id) {
  82 + return mysqlCli.delete(
  83 + `delete from ${TABLE_ACT_ARTICLE} where id = :id;`,
  84 + {
  85 + id
  86 + }
  87 + );
  88 + }
  89 +
  90 + /**
  91 + * 参与活动用户列表
  92 + * @returns {*}
  93 + */
  94 + activityUserList(actId) {
  95 + return mysqlCli.query(
  96 + `select tu.user_phone phone
  97 + from ${TABLE_ACTIVITY} ta
  98 + inner join act_article taa
  99 + on ta.id = taa.act_id
  100 + inner join user tu
  101 + on taa.user_id = tu.id
  102 + where ta.id = :actId;`, {
  103 + actId
  104 + }
  105 + );
  106 + }
57 } 107 }
58 108
59 module.exports = AdminModel; 109 module.exports = AdminModel;
@@ -13,6 +13,8 @@ router.get('/home', admin.homePage); @@ -13,6 +13,8 @@ router.get('/home', admin.homePage);
13 // 活动管理 13 // 活动管理
14 router.get('/activity/list', admin.activityListPage); 14 router.get('/activity/list', admin.activityListPage);
15 router.get('/activity/create', admin.createActivityPage); 15 router.get('/activity/create', admin.createActivityPage);
  16 +router.get('/activity/user', admin.activityUserListPage);
  17 +router.get('/activity/article', admin.actArticleListPage);
16 18
17 // ajax 19 // ajax
18 router.post('/api/login', admin.login); 20 router.post('/api/login', admin.login);
@@ -20,5 +22,6 @@ router.post('/api/logout', admin.logout); @@ -20,5 +22,6 @@ router.post('/api/logout', admin.logout);
20 router.post('/api/activity/list', admin.activityList); 22 router.post('/api/activity/list', admin.activityList);
21 router.post('/api/activity/create', admin.createActivity); 23 router.post('/api/activity/create', admin.createActivity);
22 router.post('/api/activity/delete', admin.deleteActivity); 24 router.post('/api/activity/delete', admin.deleteActivity);
  25 +router.post('/api/activity/deleteArticle', admin.deleteArticle);
23 26
24 module.exports = router; 27 module.exports = router;
  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">文章ID</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 + </tr>
  23 + </thead>
  24 +
  25 + <tbody>
  26 + {{#each articleList}}
  27 + <tr class="even pointer">
  28 + <td>{{id}}</td>
  29 + <td>{{content}}</td>
  30 + <td>{{goodCount}}</td>
  31 + <td>{{userName}}</td>
  32 + <td>
  33 + <button class="btn btn-danger btn-delete-article" data-id="{{id}}">删除文章
  34 + </button>
  35 + </td>
  36 + </tr>
  37 + {{/each}}
  38 + </tbody>
  39 + </table>
  40 + </div>
  41 +
  42 +
  43 + </div>
  44 + </div>
  45 + </div>
  46 + </div>
  47 + </div>
  48 +</div>
  49 +<!-- /page content -->
@@ -18,7 +18,6 @@ @@ -18,7 +18,6 @@
18 <th class="column-title">开始时间</th> 18 <th class="column-title">开始时间</th>
19 <th class="column-title">结束时间</th> 19 <th class="column-title">结束时间</th>
20 <th class="column-title">创建时间</th> 20 <th class="column-title">创建时间</th>
21 - <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>
@@ -26,15 +25,13 @@ @@ -26,15 +25,13 @@
26 <tbody> 25 <tbody>
27 {{#each activityList}} 26 {{#each activityList}}
28 <tr class="even pointer"> 27 <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-primary">编辑</button>  
37 - <button class="btn btn-danger btn-delete" data-id="{{id}}">删除</button> 28 + <td class="">{{title}}</td>
  29 + <td class="">{{startTime}}</td>
  30 + <td class="">{{endTime}}</td>
  31 + <td class="">{{createTime}}</td>
  32 + <td class="">
  33 + <a class="btn btn-info" href="/admin/activity/article?actId={{id}}">活动文章</a>
  34 + <button class="btn btn-danger btn-delete" data-id="{{id}}">删除活动</button>
38 </td> 35 </td>
39 </tr> 36 </tr>
40 {{/each}} 37 {{/each}}
  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 -->
@@ -62,17 +62,37 @@ function bind_delete_act() { @@ -62,17 +62,37 @@ function bind_delete_act() {
62 } 62 }
63 }) 63 })
64 .then(() => { 64 .then(() => {
65 - location.href = '/admin/activity/list'; 65 + location.reload();
66 }); 66 });
67 }; 67 };
68 68
69 $('.btn-delete').on('click', deleteFn); 69 $('.btn-delete').on('click', deleteFn);
70 } 70 }
71 71
  72 +function bind_delete_article() {
  73 + const deleteFn = function() {
  74 + const id = $(this).data('id');
  75 +
  76 + $.ajax({
  77 + method: 'post',
  78 + url: '/admin/api/activity/deleteArticle',
  79 + data: {
  80 + id
  81 + }
  82 + })
  83 + .then(() => {
  84 + location.reload();
  85 + });
  86 + };
  87 +
  88 + $('.btn-delete-article').on('click', deleteFn);
  89 +}
  90 +
72 (function() { 91 (function() {
73 bind_date_picker(); 92 bind_date_picker();
74 bind_create_act(); 93 bind_create_act();
75 bind_delete_act(); 94 bind_delete_act();
  95 + bind_delete_article();
76 }()); 96 }());
77 97
78 98