Authored by 邱骏

详情查询

@@ -7,9 +7,11 @@ const ArticleModel = require('../models/article'); @@ -7,9 +7,11 @@ const ArticleModel = require('../models/article');
7 7
8 const ADD_ARTICLE_SUCCESS = '文章发表成功'; 8 const ADD_ARTICLE_SUCCESS = '文章发表成功';
9 const GET_ARTICLES_SUCCESS = '获取文章列表成功'; 9 const GET_ARTICLES_SUCCESS = '获取文章列表成功';
  10 +const GET_ARTICLE_SUCCESS = '获取文章详情成功';
10 const INVALID_ACTIVITY_ID = '活动ID[actId]不能为空'; 11 const INVALID_ACTIVITY_ID = '活动ID[actId]不能为空';
11 const INVALID_IMG = '图片[imgUrl]不能为空'; 12 const INVALID_IMG = '图片[imgUrl]不能为空';
12 const INVALID_CONTENT = '内容[content]都不能为空'; 13 const INVALID_CONTENT = '内容[content]都不能为空';
  14 +const MISS_PARAMS = '缺少参数';
13 15
14 const article = { 16 const article = {
15 /** 17 /**
@@ -74,6 +76,36 @@ const article = { @@ -74,6 +76,36 @@ const article = {
74 }); 76 });
75 }); 77 });
76 }); 78 });
  79 + },
  80 +
  81 + /**
  82 + * 查询单个article详情
  83 + * @param req
  84 + * @param res
  85 + */
  86 + querySingle(req, res) {
  87 + let errorMsg = '';
  88 + const actId = req.query.actId;
  89 + const articleId = req.query.articleId;
  90 +
  91 + !actId && (errorMsg = MISS_PARAMS);
  92 + !articleId && (errorMsg = MISS_PARAMS);
  93 +
  94 + if (errorMsg) {
  95 + return res.json({
  96 + code: 400,
  97 + message: errorMsg
  98 + });
  99 + }
  100 +
  101 + req.ctx(ArticleModel).getSingleArticle(actId, articleId)
  102 + .then(ret => {
  103 + res.json({
  104 + code: 200,
  105 + data: ret,
  106 + message: GET_ARTICLE_SUCCESS
  107 + });
  108 + });
77 } 109 }
78 }; 110 };
79 111
@@ -9,6 +9,7 @@ const mysqlCli = global.yoho.utils.mysqlCli; @@ -9,6 +9,7 @@ const mysqlCli = global.yoho.utils.mysqlCli;
9 9
10 const TABLE_ACT_ARTICLE = 'act_article'; 10 const TABLE_ACT_ARTICLE = 'act_article';
11 const TABLE_ACT_ARTICLE_IMG = 'act_article_img'; 11 const TABLE_ACT_ARTICLE_IMG = 'act_article_img';
  12 +const TABLE_ACT_ARTICLE_GOOD = 'act_article_good';
12 13
13 class ArticleModel extends global.yoho.BaseModel { 14 class ArticleModel extends global.yoho.BaseModel {
14 constructor(ctx) { 15 constructor(ctx) {
@@ -60,6 +61,25 @@ class ArticleModel extends global.yoho.BaseModel { @@ -60,6 +61,25 @@ class ArticleModel extends global.yoho.BaseModel {
60 } 61 }
61 ); 62 );
62 } 63 }
  64 +
  65 + /**
  66 + * 获取单个文章详情
  67 + * @param articleId
  68 + * @returns {*}
  69 + */
  70 + getSingleArticle(articleId, actId) {
  71 + return mysqlCli.query(`select act_article.id,content,good_count,
  72 + act_article_img.img_url from ${TABLE_ACT_ARTICLE}
  73 + join ${TABLE_ACT_ARTICLE_IMG}
  74 + where act_article_img.article_id = act_article.id
  75 + and act_article.act_id = :actId
  76 + and act_article.id = :articleId;`,
  77 + {
  78 + actId,
  79 + articleId
  80 + }
  81 + );
  82 + }
63 } 83 }
64 84
65 module.exports = ArticleModel; 85 module.exports = ArticleModel;
@@ -10,5 +10,6 @@ const article = require('./controllers/article'); @@ -10,5 +10,6 @@ const article = require('./controllers/article');
10 10
11 router.get('/list', article.list); 11 router.get('/list', article.list);
12 router.post('/publish', auth, article.publish); 12 router.post('/publish', auth, article.publish);
  13 +router.get('/querySingle', article.querySingle);
13 14
14 module.exports = router; 15 module.exports = router;