...
|
...
|
@@ -10,8 +10,7 @@ const mysqlCli = global.yoho.utils.mysqlCli; |
|
|
const TABLE_USER = 'user';
|
|
|
const TABLE_ACT_ARTICLE = 'act_article';
|
|
|
const TABLE_ACT_ARTICLE_IMG = 'act_article_img';
|
|
|
|
|
|
// const TABLE_ACT_ARTICLE_GOOD = 'act_article_good';
|
|
|
const TABLE_ACT_ARTICLE_GOOD = 'act_article_good';
|
|
|
|
|
|
class ArticleModel extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
...
|
...
|
@@ -126,6 +125,47 @@ class ArticleModel extends global.yoho.BaseModel { |
|
|
}
|
|
|
);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 文章点赞
|
|
|
* @param actId
|
|
|
* @param articleId
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
likeArticle(actId, articleId) {
|
|
|
return mysqlCli.update(
|
|
|
`UPDATE ${TABLE_ACT_ARTICLE} AA
|
|
|
SET good_count = good_count + 1
|
|
|
WHERE AA.act_id = :actId
|
|
|
AND AA.id = :articleId;`,
|
|
|
{
|
|
|
actId,
|
|
|
articleId
|
|
|
}
|
|
|
);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 插入点赞详情
|
|
|
* @param actId
|
|
|
* @param articleId
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
insertLikeDetail(actId, articleId) {
|
|
|
const userId = _.get(this.ctx.req.session, 'user.id');
|
|
|
const ip = this.header['X-Forwarded-For'] || this.ctx.req.connection.remoteAddress;
|
|
|
|
|
|
return mysqlCli.insert(
|
|
|
`INSERT INTO ${TABLE_ACT_ARTICLE_GOOD} (act_id, article_id, user_id, ip)
|
|
|
VALUES (:actId, :articleId, :userId, :ip);`,
|
|
|
{
|
|
|
ip,
|
|
|
userId,
|
|
|
actId,
|
|
|
articleId
|
|
|
}
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
module.exports = ArticleModel;
|
...
|
...
|
|