1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-24 12:05:39 +08:00
course-tencent-cloud/app/Validators/UserDailyLimit.php
2020-03-16 15:33:36 +08:00

115 lines
2.9 KiB
PHP

<?php
namespace App\Validators;
use App\Caches\UserDailyCounter as CacheUserDailyCounter;
use App\Exceptions\BadRequest as BadRequestException;
use App\Models\User as UserModel;
class UserDailyLimit extends Validator
{
protected $counter;
public function __construct()
{
$this->counter = new CacheUserDailyCounter();
}
public function checkFavoriteLimit(UserModel $user)
{
$count = $this->counter->hGet($user->id, 'favorite_count');
$limit = $user->vip ? 100 : 50;
if ($count > $limit) {
throw new BadRequestException('user_daily_limit.reach_favorite_limit');
}
}
public function checkCommentLimit(UserModel $user)
{
$count = $this->counter->hGet($user->id, 'comment_count');
$limit = $user->vip ? 100 : 50;
if ($count > $limit) {
throw new BadRequestException('user_daily_limit.reach_comment_limit');
}
}
public function checkConsultLimit(UserModel $user)
{
$count = $this->counter->hGet($user->id, 'consult_count');
$limit = $user->vip ? 20 : 10;
if ($count > $limit) {
throw new BadRequestException('user_daily_limit.reach_consult_limit');
}
}
public function checkReviewLimit(UserModel $user)
{
$count = $this->counter->hGet($user->id, 'review_count');
if ($count > 10) {
throw new BadRequestException('user_daily_limit.reach_review_limit');
}
}
public function checkOrderLimit(UserModel $user)
{
$count = $this->counter->hGet($user->id, 'order_count');
if ($count > 10) {
throw new BadRequestException('user_daily_limit.reach_order_limit');
}
}
public function checkChapterVoteLimit(UserModel $user)
{
$count = $this->counter->hGet($user->id, 'chapter_vote_count');
$limit = $user->vip ? 200 : 100;
if ($count > $limit) {
throw new BadRequestException('user_daily_limit.reach_vote_limit');
}
}
public function checkCommentVoteLimit(UserModel $user)
{
$count = $this->counter->hGet($user->id, 'comment_vote_count');
$limit = $user->vip ? 200 : 100;
if ($count > $limit) {
throw new BadRequestException('user_daily_limit.reach_vote_limit');
}
}
public function checkConsultVoteLimit(UserModel $user)
{
$count = $this->counter->hGet($user->id, 'consult_vote_count');
$limit = $user->vip ? 200 : 100;
if ($count > $limit) {
throw new BadRequestException('user_daily_limit.reach_vote_limit');
}
}
public function checkReviewVoteLimit(UserModel $user)
{
$count = $this->counter->hGet($user->id, 'review_vote_count');
$limit = $user->vip ? 200 : 100;
if ($count > $limit) {
throw new BadRequestException('user_daily_limit.reach_vote_limit');
}
}
}