...
|
...
|
@@ -10,6 +10,8 @@ const ArticleModel = require('../models/article'); |
|
|
const POST_SUCCESS = '操作成功';
|
|
|
const GET_SUCCESS = '获取成功';
|
|
|
const INVALID_PARAMS = '参数错误';
|
|
|
const VOTE_REPEAT = '不能给同一位选手重复投票';
|
|
|
const VOTE_MAX = '达到每天投票上限';
|
|
|
|
|
|
const article = {
|
|
|
/**
|
...
|
...
|
@@ -457,6 +459,23 @@ const article = { |
|
|
like(req, res, next) {
|
|
|
const actId = req.body.actId;
|
|
|
const articleId = req.body.articleId;
|
|
|
const voteType = req.body.type || 'v'; // v为投票,s为刷票
|
|
|
const voteLimit = parseInt(req.body.vl / 100, 10) || 5;
|
|
|
|
|
|
let vote = function() {
|
|
|
req.ctx(ArticleModel).likeArticle(actId, articleId)
|
|
|
.then(() => {
|
|
|
return req.ctx(ArticleModel)
|
|
|
.insertLikeDetail(actId, articleId);
|
|
|
})
|
|
|
.then(() => {
|
|
|
res.json({
|
|
|
code: 200,
|
|
|
message: POST_SUCCESS
|
|
|
});
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
|
|
|
|
|
if (!actId || !articleId) {
|
|
|
return res.json({
|
...
|
...
|
@@ -465,18 +484,61 @@ const article = { |
|
|
});
|
|
|
}
|
|
|
|
|
|
req.ctx(ArticleModel).likeArticle(actId, articleId)
|
|
|
.then(() => {
|
|
|
return req.ctx(ArticleModel)
|
|
|
.insertLikeDetail(actId, articleId);
|
|
|
})
|
|
|
.then(() => {
|
|
|
res.json({
|
|
|
code: 200,
|
|
|
message: POST_SUCCESS
|
|
|
if (voteType === 's') {
|
|
|
vote();
|
|
|
} else {
|
|
|
req.ctx(ArticleModel).getArticleLimit(actId, articleId)
|
|
|
.then(limit_data => {
|
|
|
let repeat = limit_data[0].repeat_limit;
|
|
|
let limit = limit_data[0].vote_limit;
|
|
|
let limit_result = {};
|
|
|
|
|
|
limit_result.repeat = repeat;
|
|
|
limit_result.limit = limit;
|
|
|
return limit_result;
|
|
|
}).then(limit_result => {
|
|
|
req.ctx(ArticleModel).getArticleIp(actId, articleId, 1)
|
|
|
.then(count_result => {
|
|
|
console.log(count_result);
|
|
|
let now_vote_num = 0;
|
|
|
|
|
|
if (count_result.length > 0) {
|
|
|
now_vote_num = count_result[0].vote_count || 0;
|
|
|
}
|
|
|
|
|
|
if (!limit_result.repeat) {
|
|
|
req.ctx(ArticleModel).getArticleIp(actId, articleId, 0)
|
|
|
.then(ip_result => {
|
|
|
if (ip_result.length > 0 && ip_result[0].vote_count > 0) {
|
|
|
res.json({
|
|
|
code: 203,
|
|
|
message: VOTE_REPEAT
|
|
|
});
|
|
|
} else {
|
|
|
if (now_vote_num < voteLimit) {
|
|
|
vote();
|
|
|
} else {
|
|
|
res.json({
|
|
|
code: 201,
|
|
|
message: VOTE_MAX
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
if (now_vote_num < voteLimit) {
|
|
|
vote();
|
|
|
} else {
|
|
|
res.json({
|
|
|
code: 201,
|
|
|
message: VOTE_MAX
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}).catch(next);
|
|
|
});
|
|
|
})
|
|
|
.catch(next);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
|