Commit d4934254 by Евгений

Улучшение #19453

Первоначальная загрузка всех РК аккаунтов.
1 parent b94fb42e
<?php
namespace App\Console\Commands;
use App\Jobs\ProcessCallLimitedAPI;
use App\Models\Tokens;
use App\Service\API\API;
use App\Service\Direct\CheckDictionaries;
use App\Service\Direct\GetCampaigns;
use App\Service\Requests\APIRequest;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Bus;
class CheckChangeCampaigns extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'campaigns:checkChange';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Проверка изменений в РК';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$token = Tokens::where('type', Tokens::MAIN)->first();
if (!$token){
throw new \Exception('Не найден токен блин');
}
$factory = APIRequest::getInstance(API::YANDEX);
$factory->setToken($token);
$factory->getRequest('change', 'checkCampaigns')
->call();
return 0;
}
}
...@@ -53,9 +53,8 @@ class FirstLoadCampaigns extends Command ...@@ -53,9 +53,8 @@ class FirstLoadCampaigns extends Command
$factory->setToken($token); $factory->setToken($token);
$factory->getRequest('change', 'CheckDictionaries') $factory->getRequest('change', 'CheckDictionaries')
->call( ->call();
$factory->getRequest('campaigns', 'get') $factory->getRequest('campaigns', 'get')->call();
);
return 0; return 0;
} }
......
...@@ -17,9 +17,11 @@ class CheckDictionariesChange extends DirectRequest { ...@@ -17,9 +17,11 @@ class CheckDictionariesChange extends DirectRequest {
} }
function handle($response){ function handle($response){
if ($this->next){ // if ($this->next){
$this->next->call(null, $response); // $this->next->call(null, $response);
} // }
$this->token->timestamp = $response['result']['Timestamp'] ?? '';
$this->token->save();
} }
private function requestPrepare($response){ private function requestPrepare($response){
......
...@@ -59,7 +59,7 @@ class GetCampaigns extends DirectRequest{ ...@@ -59,7 +59,7 @@ class GetCampaigns extends DirectRequest{
private function requestPrepare($response){ private function requestPrepare($response){
$this->setService('campaigns'); $this->setService('campaigns');
$this->setMethod('get'); $this->setMethod('get');
$this->setTimestamp($response); // $this->setTimestamp($response);
$params = [ $params = [
'SelectionCriteria' => [ 'SelectionCriteria' => [
'Types' => ["TEXT_CAMPAIGN"] 'Types' => ["TEXT_CAMPAIGN"]
...@@ -74,8 +74,8 @@ class GetCampaigns extends DirectRequest{ ...@@ -74,8 +74,8 @@ class GetCampaigns extends DirectRequest{
$this->setParams($params); $this->setParams($params);
} }
private function setTimestamp($response){ // private function setTimestamp($response){
$this->timestamp = $response['result']['Timestamp'] ?? ''; // $this->timestamp = $response['result']['Timestamp'] ?? '';
} // }
} }
...@@ -20,7 +20,7 @@ class CreateTokensTable extends Migration ...@@ -20,7 +20,7 @@ class CreateTokensTable extends Migration
$table->enum('api', ['yd']); $table->enum('api', ['yd']);
$table->enum('type', ['main', 'goal'])->nullable(); $table->enum('type', ['main', 'goal'])->nullable();
$table->integer('created_by'); $table->integer('created_by');
$table->timestamps(); $table->timestamps()->nullable();
$table->unique('token'); $table->unique('token');
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!