mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-24 04:01:31 +08:00
74 lines
1.8 KiB
PHP
74 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Frontend\Comment;
|
|
|
|
use App\Models\CommentVote as CommentVoteModel;
|
|
use App\Repos\CommentVote as CommentVoteRepo;
|
|
use App\Services\Frontend\CommentTrait;
|
|
use App\Services\Frontend\Service as FrontendService;
|
|
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
|
|
|
|
class OpposeVote extends FrontendService
|
|
{
|
|
|
|
use CommentTrait, VoteTrait;
|
|
|
|
public function handle($id)
|
|
{
|
|
$comment = $this->checkComment($id);
|
|
|
|
$user = $this->getLoginUser();
|
|
|
|
$validator = new UserDailyLimitValidator();
|
|
|
|
$validator->checkCommentVoteLimit($user);
|
|
|
|
$commentVoteRepo = new CommentVoteRepo();
|
|
|
|
$commentVote = $commentVoteRepo->findCommentVote($comment->id, $user->id);
|
|
|
|
if (!$commentVote) {
|
|
|
|
$commentVote = new CommentVoteModel();
|
|
|
|
$commentVote->comment_id = $comment->id;
|
|
$commentVote->user_id = $user->id;
|
|
$commentVote->type = CommentVoteModel::TYPE_OPPOSE;
|
|
|
|
$commentVote->create();
|
|
|
|
$this->incrOpposeCount($comment);
|
|
|
|
} else {
|
|
|
|
if ($commentVote->type == CommentVoteModel::TYPE_AGREE) {
|
|
|
|
$commentVote->type = CommentVoteModel::TYPE_OPPOSE;
|
|
|
|
$this->decrAgreeCount($comment);
|
|
|
|
$this->incrOpposeCount($comment);
|
|
|
|
} elseif ($commentVote->type == CommentVoteModel::TYPE_OPPOSE) {
|
|
|
|
$commentVote->type = CommentVoteModel::TYPE_NONE;
|
|
|
|
$this->decrOpposeCount($comment);
|
|
|
|
} elseif ($commentVote->type == CommentVoteModel::TYPE_NONE) {
|
|
|
|
$commentVote->type = CommentVoteModel::TYPE_OPPOSE;
|
|
|
|
$this->incrOpposeCount($comment);
|
|
}
|
|
|
|
$commentVote->update();
|
|
}
|
|
|
|
$this->incrUserDailyCommentVoteCount($user);
|
|
|
|
return $comment;
|
|
}
|
|
|
|
}
|