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({
}));
app.use(cookieParser());
app.use(global.yoho.httpCtx());
app.enable('trust proxy');
app.use((req, res, next) => {
req.user = {}; // 全局的用户数据
... ...
... ... @@ -20,12 +20,20 @@ const article = {
* @param res
*/
list(req, res) {
// const query = req.query;
// const pageNo = query.pageNo;
// const popular = query.popular || false;
// const pageSize = query.pageSize;
req.ctx(ArticleModel).articleList()
const query = req.query;
const pageNo = query.pageNo || 1;
const pageSize = query.pageSize || 10;
const isPopular = query.isPopular || false;
const order = query.order || 'desc';
const orderBy = query.orderBy || 'create_time';
req.ctx(ArticleModel).articleList({
order,
orderBy,
pageNo,
pageSize,
isPopular
})
.then(result => {
res.json({
code: 200,
... ...
... ... @@ -21,8 +21,25 @@ class ArticleModel extends global.yoho.BaseModel {
* 获取文章列表
* @returns {*}
*/
articleList() {
return mysqlCli.query(`select * from ${TABLE_ACT_ARTICLE}`);
articleList({pageNo, pageSize, isPopular, orderBy, order}) {
let limitSql;
let whereSql = '';
let orderSql = `ORDER BY AA.${orderBy} ${order}`;
if (isPopular) {
whereSql = 'WHERE AA.good_count > 10';
}
limitSql = `LIMIT ${(pageNo - 1) * pageSize}, ${pageSize}`;
return mysqlCli.query(
`SELECT AA.id, AA.good_count goodCount,
AAI.img_url imgUrl, AA.content
FROM ${TABLE_ACT_ARTICLE} AS AA
INNER JOIN ${TABLE_ACT_ARTICLE_IMG} AS AAI
ON AA.id = AAI.article_id
${whereSql} ${orderSql} ${limitSql};`
);
}
/**
... ...