Commit 4ed87cea by Евгений

Доработал удаление фраз

1 parent 744d5464
...@@ -56,7 +56,7 @@ class AdvertisementsAdd extends Command ...@@ -56,7 +56,7 @@ class AdvertisementsAdd extends Command
->leftJoin('ad_images', 'advertisements.ad_image_hash', '=', 'ad_images.hash') ->leftJoin('ad_images', 'advertisements.ad_image_hash', '=', 'ad_images.hash')
->leftJoin('goal_ad_images', function($join) use ($token) { ->leftJoin('goal_ad_images', function($join) use ($token) {
$join->on('goal_ad_images.ad_image_id', '=', 'ad_images.id'); $join->on('goal_ad_images.ad_image_id', '=', 'ad_images.id');
$join->on('goal_ad_images.token_id', '=', $token->id); $join->on('goal_ad_images.token_id', '=', DB::raw($token->id));
}) })
->whereNotExists(function (Builder $query) { ->whereNotExists(function (Builder $query) {
$query->select(DB::raw(1)) $query->select(DB::raw(1))
......
...@@ -43,13 +43,15 @@ class ProcessCallLimitedAPI implements ShouldQueue//, ShouldBeUnique ...@@ -43,13 +43,15 @@ class ProcessCallLimitedAPI implements ShouldQueue//, ShouldBeUnique
$objects = $limits->countObjectsLimit($this->api); $objects = $limits->countObjectsLimit($this->api);
if (!$objects) { if (!$objects) {
//нет свободных баллов, замораживаем до следующего часа //нет свободных баллов, замораживаем до следующего часа
Log::debug('Нет баллов? ' . $objects); Log::debug('Нет баллов? ' . $objects . ' ' . $this->api->getService() . ' ' . $this->api->getMethod());
$this->reRunHour(); $this->reRunHour();
return; return;
} }
try{ try{
//резервируем на это количетсво //резервируем на это количетсво
$limit = $limits->getSpent($objects, $this->api);
Log::debug('Резервируем баллы ' . $limit . ' на объекты ' . $objects . ' ' . $this->api->getService() . ' ' . $this->api->getMethod());
$limitId = $limits->doRezerv($this->api, $objects); $limitId = $limits->doRezerv($this->api, $objects);
}catch(\Exception $e){ }catch(\Exception $e){
......
...@@ -64,6 +64,8 @@ class Limits implements \App\Service\Contract\Limits { ...@@ -64,6 +64,8 @@ class Limits implements \App\Service\Contract\Limits {
*/ */
function countObjectsLimit(\App\Service\Contract\APIRequest $request): int function countObjectsLimit(\App\Service\Contract\APIRequest $request): int
{ {
if ($this->current()==0)
return 0;
$cost = $this->limitCosts->getCostObject($request); $cost = $this->limitCosts->getCostObject($request);
$maxCount = $request->getMaxCount(); $maxCount = $request->getMaxCount();
...@@ -122,7 +124,7 @@ class Limits implements \App\Service\Contract\Limits { ...@@ -122,7 +124,7 @@ class Limits implements \App\Service\Contract\Limits {
$limit = $this->getSpent($objects, $request); $limit = $this->getSpent($objects, $request);
if ($this->token->limits->count() > 0 && $this->token->limit < $limit) { if ($this->token->limits->count() > 0 && $this->token->limit < $limit) {
throw new \Exception('Недостаточно баллов'); throw new \Exception('Недостаточно баллов ' . ' ' . $request->getService() . ' ' . $request->getMethod());
} }
DB::beginTransaction(); DB::beginTransaction();
......
...@@ -51,6 +51,12 @@ class DeleteKeywords extends DirectRequest ...@@ -51,6 +51,12 @@ class DeleteKeywords extends DirectRequest
Log::debug("DeleteKeywords, empty Id"); Log::debug("DeleteKeywords, empty Id");
Log::debug($delete_result); Log::debug($delete_result);
Log::debug($this->getParams()['SelectionCriteria']['Ids'][$key]); Log::debug($this->getParams()['SelectionCriteria']['Ids'][$key]);
if ($delete_result['Errors'][0]['Code']==8800){
//объекта по какой то причине нет
if ($external_id = $this->getParams()['SelectionCriteria']['Ids'][$key]){
GoalKeyword::where('external_id', $external_id)->delete();
}
}
continue; continue;
} }
...@@ -75,6 +81,7 @@ class DeleteKeywords extends DirectRequest ...@@ -75,6 +81,7 @@ class DeleteKeywords extends DirectRequest
'Ids' => $params['ids'], 'Ids' => $params['ids'],
], ],
]; ];
Log::debug($params);
$this->setParams($params); $this->setParams($params);
} }
......
...@@ -59,7 +59,6 @@ class GetBidModifiers extends DirectRequest ...@@ -59,7 +59,6 @@ class GetBidModifiers extends DirectRequest
if (!isset($response['result']['BidModifiers'])) { if (!isset($response['result']['BidModifiers'])) {
return; return;
} }
Log::debug(print_r($response['result'], true));
$campaigns_external_ids = []; $campaigns_external_ids = [];
$ad_groups_external_ids = []; $ad_groups_external_ids = [];
......
...@@ -14,7 +14,7 @@ class AddRetargetinglistsExternalIdColumn extends Migration ...@@ -14,7 +14,7 @@ class AddRetargetinglistsExternalIdColumn extends Migration
public function up() public function up()
{ {
Schema::table('retargetinglists', function (Blueprint $table) { Schema::table('retargetinglists', function (Blueprint $table) {
$table->bigInteger('external_id'); $table->bigInteger('external_id')->nullable();
}); });
} }
......
...@@ -13,6 +13,7 @@ use App\Models\Variable; ...@@ -13,6 +13,7 @@ use App\Models\Variable;
use App\Service\Contract\API; use App\Service\Contract\API;
use App\Service\Limits; use App\Service\Limits;
use App\Service\Requests\APIRequest; use App\Service\Requests\APIRequest;
use App\Service\Requests\Direct\DeleteKeywords;
use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\Queue;
use Tests\TestCase; use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
...@@ -130,8 +131,37 @@ class ProcessCallSliceTest extends TestCase ...@@ -130,8 +131,37 @@ class ProcessCallSliceTest extends TestCase
} }
public function testHandleApi() public function testSliceDeleteKeywordApi()
{ {
$rezerv = new \App\Models\Limits();
$rezerv->token = $this->token->id;
$rezerv->service = 'Keywords';
$rezerv->method = 'delete';
$rezerv->spent = '100';
$rezerv->day = '100';
$rezerv->current = '6757';
$rezerv->reserved = 0;
$rezerv->save();
Queue::fake();
$this->token->limit = 6657;
$request = new DeleteKeywords();
$request->setToken($this->token)
->call([
'ids' => range(1, 10005)
]);
$limits = Limits::getInstance($request->getToken());
$maxObjects = $limits->countObjectsLimit($request);
$this->assertEquals($maxObjects, $this->token->limit-10);
$limit = $limits->getSpent($maxObjects, $request);
$this->assertEquals($maxObjects, $limit-10);
$requestR = $request->slice($maxObjects);
$this->assertEquals($this->token->limit-10, $request->getObjectsCount());
$this->assertEquals(10005 - $maxObjects, $requestR->getObjectsCount());
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!