Commit 55f993bd by Vladislav
2 parents bd4953fb b3d58ad3
Showing with 14 additions and 7 deletions
...@@ -66,16 +66,23 @@ class Limits implements \App\Service\Contract\Limits { ...@@ -66,16 +66,23 @@ class Limits implements \App\Service\Contract\Limits {
$cost = $this->limitCosts->getCostObject($request); $cost = $this->limitCosts->getCostObject($request);
$maxCount = $request->getMaxCount(); $maxCount = $request->getMaxCount();
if ($this->limitCosts->getCostCall($request) > $this->current()){
return 0;
}
if ($cost == 0 || $maxCount === self::NAN){ if ($cost == 0 || $maxCount === self::NAN){
return self::NAN; return self::NAN;
} }
$allowCount = floor(($this->current() - $this->limitCosts->getCostCall($request)) / $cost);
$objectsCount = $request->getObjectsCount(); if ($this->token->limits->count()>0){
if ($this->limitCosts->getCostCall($request) > $this->current()){
return 0;
}
$allowCount = floor(($this->current() - $this->limitCosts->getCostCall($request)) / $cost);
$objectsCount = $request->getObjectsCount();
} else {
$allowCount = $maxCount;//не было еще запросов, считаем что баллов хватает
$objectsCount = $maxCount;
}
if ($objectsCount > $maxCount) { if ($objectsCount > $maxCount) {
$objectsCount = $maxCount; $objectsCount = $maxCount;
...@@ -99,7 +106,7 @@ class Limits implements \App\Service\Contract\Limits { ...@@ -99,7 +106,7 @@ class Limits implements \App\Service\Contract\Limits {
function doRezerv(\App\Service\Contract\APIRequest $request, int $objects): int function doRezerv(\App\Service\Contract\APIRequest $request, int $objects): int
{ {
$limit = $this->getSpent($objects, $request); $limit = $this->getSpent($objects, $request);
if ($this->token->limit<$limit){ if ($this->token->limits->count()>1 && $this->token->limit<$limit){
throw new \Exception('Недостаточно баллов'); throw new \Exception('Недостаточно баллов');
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!