Authored by 陈峰

commit

@@ -482,6 +482,30 @@ const article = { @@ -482,6 +482,30 @@ const article = {
482 message: INVALID_PARAMS 482 message: INVALID_PARAMS
483 }); 483 });
484 } 484 }
  485 + const user_ip = req.headers['X-Forwarded-For'] || req.ip || req.connection.remoteAddress;
  486 +
  487 + return req.ctx(ArticleModel).getActLimit(actId).then(actInfo => {
  488 + const {repeat_limit, vote_limit} = actInfo[0];
  489 +
  490 + return req.ctx(ArticleModel).getArticleIp(actId, 0, user_ip).then(userCount => {
  491 + if (userCount > vote_limit) {
  492 + return Promise.reject({code: 400});
  493 + }
  494 + if (repeat_limit) {
  495 + return Promise.resolve();
  496 + }
  497 + return req.ctx(ArticleModel).getArticleIp(actId, articleId, user_ip).then(actCount => {
  498 + if (actCount > 0) {
  499 + return Promise.reject({code: 400});
  500 + }
  501 + return Promise.resolve();
  502 + });
  503 + });
  504 + }).then(() => {
  505 + return vote();
  506 + }, (result) => {
  507 + return res.json(result);
  508 + }).catch(next);
485 509
486 // 获取活动投票限制参数 510 // 获取活动投票限制参数
487 req.ctx(ArticleModel).getActLimit(actId) 511 req.ctx(ArticleModel).getActLimit(actId)
@@ -494,7 +518,7 @@ const article = { @@ -494,7 +518,7 @@ const article = {
494 return {repeat: repeat, limit: limit}; 518 return {repeat: repeat, limit: limit};
495 }).then(limit_result => { 519 }).then(limit_result => {
496 console.log(limit_result); 520 console.log(limit_result);
497 - let user_ip = req.headers['X-Forwarded-For'] || req.ip || req.connection.remoteAddress; 521 +
498 522
499 // 获取用户IP今日已投票次数 523 // 获取用户IP今日已投票次数
500 req.ctx(ArticleModel).getArticleIp(actId, articleId, user_ip) 524 req.ctx(ArticleModel).getArticleIp(actId, articleId, user_ip)