validation); $this->user_id = $value; $this->type = $type; $sid = $this->args['sid'] ?? 0; $this->sid = $sid; $limit = $this->args['limit'] ?? 0; if ($limit <= 0) { throw new LogicException('Limit is null'); } $res = self::check($value, $this->type, $sid, $this->limit); if (!$res) { $this->validation->addError('', "限制 {$this->limit} 次"); } return $res; } /** * 限流检查 * @param $user_id * @param $type * @param $limit * @return bool */ public static function check($user_id, $type, $limit, $sid = 0) { if (Times::check($user_id, $type, $sid, $limit)) { return true; } return false; } public function consume($times = 1) { Times::add($this->user_id, $this->type, $this->sid, $times); } }