protected function isRequiredToUpdatePeriod(PeriodInterface $period)
 {
     $periodEnd = Carbon::createFromFormat('Y-m-d', $period->end())->endOfDay();
     $today = Carbon::today()->endOfDay();
     if ($periodEnd->lte($today)) {
         return true;
     }
     return false;
 }
Пример #2
0
 public function can($identifier, $count = 1, $reduce = true, PeriodInterface $period)
 {
     $limit = $this->redis->hashGet("throttle:hashes:limit:{$identifier}", $this->user);
     if ($limit === false) {
         $limit = $this->subscriber->left($this->subscription['subscription_id'], $identifier, $period->start(), $period->end());
         if (!is_null($limit)) {
             $limit = $limit - $this->usages[$identifier];
         }
         $this->redis->hashSet("throttle:hashes:limit:{$identifier}", $this->user, $limit);
     }
     if ($limit === "" or is_null($limit)) {
         return true;
     } else {
         if ($limit >= $count) {
             if ($reduce === true) {
                 $this->redis->hashIncrement("throttle:hashes:limit:{$identifier}", $this->user, -$count);
             }
             return true;
         } else {
             return false;
         }
     }
 }
Пример #3
0
 public function addPeriod(PeriodInterface $period)
 {
     if (is_null($this->subscription)) {
         throw new Exceptions\NoSubscriptionException();
     }
     $this->periodRepo->store($this->subscription['id'], $period->start(), $period->end());
     return $this->user($this->user);
 }
Пример #4
0
 public function seedPackForNewPeriod($subscriptionId, PeriodInterface $period)
 {
     $packs = $this->getPacksBySubscriptionId($subscriptionId);
     foreach ($packs as $pack) {
         $this->db->table(Config::get('throttle::table.user_pack'))->where('id', $pack['id'])->update(['status' => 0]);
         $this->db->table(Config::get('throttle::tables.user_pack'))->insert(['subscription_id' => $pack['subscription_id'], 'pack_id' => $pack['pack_id'], 'units' => $pack['units'], 'status' => 1, 'period_start' => $period->start(), 'period_end' => $period->end()]);
     }
 }
Пример #5
0
 public function getUserUsage($subscriptionId, PeriodInterface $period)
 {
     return $this->db->table(Config::get('throttle::tables.user_feature_limit') . ' as ufl')->leftJoin(Config::get('throttle::tables.features') . ' as f', 'ufl.feature_id', '=', 'f.id')->leftJoin(Config::get('throttle::tables.user_feature_usage') . ' as ufu', 'ufl.feature_id', '=', 'ufu.feature_id')->where('ufl.subscription_id', $subscriptionId)->whereBetween('ufu.date', [$period->start(), $period->end()])->select(\DB::raw('f.id as feature_id, f.identifier as feature_identifier, f.name as feature_name, ufl.limit as feature_limit, SUM(ufu.used_quantity) as feature_usage'))->groupBy('ufu.feature_id')->get();
 }