Commit 4ed87cea by Евгений

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

1 parent 744d5464
......@@ -56,7 +56,7 @@ class AdvertisementsAdd extends Command
->leftJoin('ad_images', 'advertisements.ad_image_hash', '=', 'ad_images.hash')
->leftJoin('goal_ad_images', function($join) use ($token) {
$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) {
$query->select(DB::raw(1))
......
......@@ -43,13 +43,15 @@ class ProcessCallLimitedAPI implements ShouldQueue//, ShouldBeUnique
$objects = $limits->countObjectsLimit($this->api);
if (!$objects) {
//нет свободных баллов, замораживаем до следующего часа
Log::debug('Нет баллов? ' . $objects);
Log::debug('Нет баллов? ' . $objects . ' ' . $this->api->getService() . ' ' . $this->api->getMethod());
$this->reRunHour();
return;
}
try{
//резервируем на это количетсво
$limit = $limits->getSpent($objects, $this->api);
Log::debug('Резервируем баллы ' . $limit . ' на объекты ' . $objects . ' ' . $this->api->getService() . ' ' . $this->api->getMethod());
$limitId = $limits->doRezerv($this->api, $objects);
}catch(\Exception $e){
......
......@@ -64,6 +64,8 @@ class Limits implements \App\Service\Contract\Limits {
*/
function countObjectsLimit(\App\Service\Contract\APIRequest $request): int
{
if ($this->current()==0)
return 0;
$cost = $this->limitCosts->getCostObject($request);
$maxCount = $request->getMaxCount();
......@@ -122,7 +124,7 @@ class Limits implements \App\Service\Contract\Limits {
$limit = $this->getSpent($objects, $request);
if ($this->token->limits->count() > 0 && $this->token->limit < $limit) {
throw new \Exception('Недостаточно баллов');
throw new \Exception('Недостаточно баллов ' . ' ' . $request->getService() . ' ' . $request->getMethod());
}
DB::beginTransaction();
......
......@@ -51,6 +51,12 @@ class DeleteKeywords extends DirectRequest
Log::debug("DeleteKeywords, empty Id");
Log::debug($delete_result);
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;
}
......@@ -75,6 +81,7 @@ class DeleteKeywords extends DirectRequest
'Ids' => $params['ids'],
],
];
Log::debug($params);
$this->setParams($params);
}
......
......@@ -59,7 +59,6 @@ class GetBidModifiers extends DirectRequest
if (!isset($response['result']['BidModifiers'])) {
return;
}
Log::debug(print_r($response['result'], true));
$campaigns_external_ids = [];
$ad_groups_external_ids = [];
......
......@@ -14,7 +14,7 @@ class AddRetargetinglistsExternalIdColumn extends Migration
public function up()
{
Schema::table('retargetinglists', function (Blueprint $table) {
$table->bigInteger('external_id');
$table->bigInteger('external_id')->nullable();
});
}
......
......@@ -13,6 +13,7 @@ use App\Models\Variable;
use App\Service\Contract\API;
use App\Service\Limits;
use App\Service\Requests\APIRequest;
use App\Service\Requests\Direct\DeleteKeywords;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
......@@ -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!