/** * Description: 评分 */ public function score() { $articleId = Request::getRequest('article_id', 'int', 58); $score = Request::getRequest('score', 'int', 1); //判断参数 if ($score != 1 && $score != 2) { View::showErrorMessage(GAME_URL, '非法操作'); } //返回 $data = array(); //判断是否24小时内已经投过了。cookie判断,伪验证。 $addScore = Request::getCookie('add_score'); if (!empty($addScore) && $addScore - time() <= 86400) { $data['status'] = -2; $data['msg'] = '<p class="text-center">说你呢-.-</p><p class="text-center">不要贪得无厌哦</p><p class="text-center">24小时内只能顶一次'; return json_encode($data); } Response::setCookie('add_score', time(), time() + 86400); //更新数据库 if ($score == 1) { $result = ArticleBusiness::goodNum($articleId); } else { if ($score == 2) { $result = ArticleBusiness::badNum($articleId); } } //整理返回值 if ($result) { $data['status'] = 0; $data['msg'] = 1; } else { $data['status'] = -1; $data['msg'] = '不明所以的失败了,请重新。'; } return json_encode($data); }