Commit f93f2d53 by Vladislav

#19458 Обновление справочника городов.

1 parent 42d0c148
...@@ -2,28 +2,29 @@ ...@@ -2,28 +2,29 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Models\Tokens;
use App\Service\API\API; use App\Service\API\API;
use App\Service\Direct\CheckDictionaries; use App\Service\Direct\CheckDictionaries;
use App\Service\Direct\GetCampaigns; use App\Service\Direct\GetCampaigns;
use App\Service\Requests\Direct\CheckDictionariesChange; use App\Service\Requests\Direct\GetDictionaries;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\Bus; use Illuminate\Support\Facades\Bus;
class CallCheckDictionariesChange extends Command class DictionariesLoad extends Command
{ {
/** /**
* The name and signature of the console command. * The name and signature of the console command.
* *
* @var string * @var string
*/ */
protected $signature = 'call-check-dictionaries-change'; protected $signature = 'dictionaries:load';
/** /**
* The console command description. * The console command description.
* *
* @var string * @var string
*/ */
protected $description = 'Запрос остатка баллов'; protected $description = 'Обновление справочника городов';
/** /**
* Create a new command instance. * Create a new command instance.
...@@ -39,9 +40,17 @@ class CallCheckDictionariesChange extends Command ...@@ -39,9 +40,17 @@ class CallCheckDictionariesChange extends Command
* Execute the console command. * Execute the console command.
* *
* @return void * @return void
* @throws \Exception
*/ */
public function handle() public function handle()
{ {
CheckDictionariesChange::getInstance(API::YANDEX)->call(); $token = Tokens::where('type', Tokens::MAIN)->first();
if (!$token){
throw new \Exception('Не найден токен блин');
}
GetDictionaries::getInstance(API::YANDEX)
->setToken($token)
->call();
} }
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
namespace App\Console; namespace App\Console;
use App\Console\Commands\CallCheckDictionariesChange; use App\Console\Commands\DictionariesLoad;
use Illuminate\Console\Scheduling\Schedule; use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
...@@ -26,7 +26,7 @@ class Kernel extends ConsoleKernel ...@@ -26,7 +26,7 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule) protected function schedule(Schedule $schedule)
{ {
$schedule->command('refreshLimits')->hourly(); $schedule->command('refreshLimits')->hourly();
$schedule->command(CallCheckDictionariesChange::class)->saturdays()->at('05:00'); $schedule->command(DictionariesLoad::class)->saturdays()->at('05:00');
} }
/** /**
......
<?php
namespace App\Models;
class Dictionary extends Model
{
}
...@@ -19,6 +19,8 @@ class APIRequest implements \App\Service\Contract\APIRequest { ...@@ -19,6 +19,8 @@ class APIRequest implements \App\Service\Contract\APIRequest {
switch($type){ switch($type){
case API::YANDEX: case API::YANDEX:
return new DirectRequest($type); return new DirectRequest($type);
default:
null;
} }
} }
...@@ -30,6 +32,7 @@ class APIRequest implements \App\Service\Contract\APIRequest { ...@@ -30,6 +32,7 @@ class APIRequest implements \App\Service\Contract\APIRequest {
function setService(string $service) function setService(string $service)
{ {
$this->service = $service; $this->service = $service;
return $this;
} }
function getService() function getService()
...@@ -40,6 +43,7 @@ class APIRequest implements \App\Service\Contract\APIRequest { ...@@ -40,6 +43,7 @@ class APIRequest implements \App\Service\Contract\APIRequest {
function setMethod(string $method) function setMethod(string $method)
{ {
$this->method = $method; $this->method = $method;
return $this;
} }
function getMethod() function getMethod()
...@@ -50,6 +54,7 @@ class APIRequest implements \App\Service\Contract\APIRequest { ...@@ -50,6 +54,7 @@ class APIRequest implements \App\Service\Contract\APIRequest {
function setParams(array $params) function setParams(array $params)
{ {
$this->params = $params; $this->params = $params;
return $this;
} }
function getParams() function getParams()
...@@ -60,6 +65,7 @@ class APIRequest implements \App\Service\Contract\APIRequest { ...@@ -60,6 +65,7 @@ class APIRequest implements \App\Service\Contract\APIRequest {
function setToken(Tokens $token) function setToken(Tokens $token)
{ {
$this->token = $token; $this->token = $token;
return $this;
} }
function getToken(): Tokens function getToken(): Tokens
......
<?php
namespace App\Service\Requests\Direct;
use App\Jobs\ProcessCallLimitedAPI;
use App\Service\Requests\DirectRequest;
class GetDictionaries extends DirectRequest
{
protected $next;
function call($next = null, $response = null)
{
$this->next = $next;
$this->requestPrepare($response);
$process = new ProcessCallLimitedAPI($this);
dispatch($process)->onQueue('limits');
}
function handle($response)
{
if ($this->next) {
$this->next->call(null, $response);
}
}
private function requestPrepare($response)
{
$this->setService('dictionaries');
$this->setMethod('get');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCitiesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('dictionaries', function (Blueprint $table) {
$table->id();
$table->string('name', 255);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('dictionaries');
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!