Authored by 邱骏

Merge branch 'feature/platform-basic' of git.yoho.cn:fe/yoho-activity-platform i…

…nto feature/platform-basic
@@ -39,6 +39,8 @@ app.use(bodyParser.urlencoded({ @@ -39,6 +39,8 @@ app.use(bodyParser.urlencoded({
39 })); 39 }));
40 app.use(cookieParser()); 40 app.use(cookieParser());
41 app.use(global.yoho.httpCtx()); 41 app.use(global.yoho.httpCtx());
  42 +app.enable('trust proxy');
  43 +
42 44
43 app.use((req, res, next) => { 45 app.use((req, res, next) => {
44 req.user = {}; // 全局的用户数据 46 req.user = {}; // 全局的用户数据
@@ -20,12 +20,20 @@ const article = { @@ -20,12 +20,20 @@ const article = {
20 * @param res 20 * @param res
21 */ 21 */
22 list(req, res) { 22 list(req, res) {
23 - // const query = req.query;  
24 - // const pageNo = query.pageNo;  
25 - // const popular = query.popular || false;  
26 - // const pageSize = query.pageSize;  
27 -  
28 - req.ctx(ArticleModel).articleList() 23 + const query = req.query;
  24 + const pageNo = query.pageNo || 1;
  25 + const pageSize = query.pageSize || 10;
  26 + const isPopular = query.isPopular || false;
  27 + const order = query.order || 'desc';
  28 + const orderBy = query.orderBy || 'create_time';
  29 +
  30 + req.ctx(ArticleModel).articleList({
  31 + order,
  32 + orderBy,
  33 + pageNo,
  34 + pageSize,
  35 + isPopular
  36 + })
29 .then(result => { 37 .then(result => {
30 res.json({ 38 res.json({
31 code: 200, 39 code: 200,
@@ -21,8 +21,25 @@ class ArticleModel extends global.yoho.BaseModel { @@ -21,8 +21,25 @@ class ArticleModel extends global.yoho.BaseModel {
21 * 获取文章列表 21 * 获取文章列表
22 * @returns {*} 22 * @returns {*}
23 */ 23 */
24 - articleList() {  
25 - return mysqlCli.query(`select * from ${TABLE_ACT_ARTICLE}`); 24 + articleList({pageNo, pageSize, isPopular, orderBy, order}) {
  25 + let limitSql;
  26 + let whereSql = '';
  27 + let orderSql = `ORDER BY AA.${orderBy} ${order}`;
  28 +
  29 + if (isPopular) {
  30 + whereSql = 'WHERE AA.good_count > 10';
  31 + }
  32 +
  33 + limitSql = `LIMIT ${(pageNo - 1) * pageSize}, ${pageSize}`;
  34 +
  35 + return mysqlCli.query(
  36 + `SELECT AA.id, AA.good_count goodCount,
  37 + AAI.img_url imgUrl, AA.content
  38 + FROM ${TABLE_ACT_ARTICLE} AS AA
  39 + INNER JOIN ${TABLE_ACT_ARTICLE_IMG} AS AAI
  40 + ON AA.id = AAI.article_id
  41 + ${whereSql} ${orderSql} ${limitSql};`
  42 + );
26 } 43 }
27 44
28 /** 45 /**