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