Commit b3d58ad3 by Евгений

Поправил расчет лимитов, для первого запуска

1 parent b9c066d8
Showing with 14 additions and 7 deletions
......@@ -66,16 +66,23 @@ class Limits implements \App\Service\Contract\Limits {
$cost = $this->limitCosts->getCostObject($request);
$maxCount = $request->getMaxCount();
if ($this->limitCosts->getCostCall($request) > $this->current()){
return 0;
}
if ($cost == 0 || $maxCount === 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) {
$objectsCount = $maxCount;
......@@ -99,7 +106,7 @@ class Limits implements \App\Service\Contract\Limits {
function doRezerv(\App\Service\Contract\APIRequest $request, int $objects): int
{
$limit = $this->getSpent($objects, $request);
if ($this->token->limit<$limit){
if ($this->token->limits->count()>1 && $this->token->limit<$limit){
throw new \Exception('Недостаточно баллов');
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!