Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Письменов Дмитрий Иванович
/
yourroomads
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit bb0c1463
authored
May 12, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19458 Обновление справочника городов.
1 parent
b94fb42e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
11 deletions
app/Console/Commands/DictionariesLoad.php
app/Service/Requests/Direct/GetDictionaries.php
app/Service/Requests/DirectRequest.php
composer.json
database/migrations/2021_05_11_094828_create_dictionaries_table.php
app/Console/Commands/DictionariesLoad.php
View file @
bb0c146
...
...
@@ -6,9 +6,8 @@ use App\Models\Tokens;
use
App\Service\API\API
;
use
App\Service\Direct\CheckDictionaries
;
use
App\Service\Direct\GetCampaigns
;
use
App\Service\Requests\
Direct\GetDictionaries
;
use
App\Service\Requests\
APIRequest
;
use
Illuminate\Console\Command
;
use
Illuminate\Support\Facades\Bus
;
class
DictionariesLoad
extends
Command
{
...
...
@@ -39,18 +38,22 @@ class DictionariesLoad extends Command
/**
* Execute the console command.
*
* @return
void
* @return
int
* @throws \Exception
*/
public
function
handle
()
{
$token
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
if
(
!
$token
){
if
(
!
$token
)
{
throw
new
\Exception
(
'Не найден токен блин'
);
}
GetDictionaries
::
getInstance
(
API
::
YANDEX
)
->
setToken
(
$token
)
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'dictionaries'
,
'get'
)
->
call
();
return
0
;
}
}
app/Service/Requests/Direct/GetDictionaries.php
View file @
bb0c146
...
...
@@ -3,7 +3,9 @@
namespace
App\Service\Requests\Direct
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Dictionary
;
use
App\Service\Requests\DirectRequest
;
use
Illuminate\Support\Facades\Log
;
class
GetDictionaries
extends
DirectRequest
{
...
...
@@ -19,8 +21,34 @@ class GetDictionaries extends DirectRequest
function
handle
(
$response
)
{
if
(
$this
->
next
)
{
$this
->
next
->
call
(
null
,
$response
);
try
{
$data
=
collect
();
foreach
(
$response
[
'result'
][
'GeoRegions'
]
as
$region
)
{
$data
->
push
([
'region_id'
=>
$region
[
'GeoRegionId'
],
'parent_id'
=>
$region
[
'ParentId'
],
'name'
=>
$region
[
'GeoRegionName'
],
'type'
=>
$region
[
'GeoRegionType'
],
]);
}
foreach
(
$data
->
chunk
(
100
)
as
$list
)
{
Dictionary
::
upsert
(
$list
->
toArray
(),
[
'region_id'
],
[
'parent_id'
,
'name'
,
'type'
,
]);
}
if
(
$this
->
next
)
{
$this
->
next
->
call
(
null
,
$response
);
}
}
catch
(
\Exception
$e
)
{
Log
::
debug
(
$e
);
}
}
...
...
@@ -28,5 +56,11 @@ class GetDictionaries extends DirectRequest
{
$this
->
setService
(
'dictionaries'
);
$this
->
setMethod
(
'get'
);
$params
=
[
'DictionaryNames'
=>
[
"GeoRegions"
,
],
];
$this
->
setParams
(
$params
);
}
}
app/Service/Requests/DirectRequest.php
View file @
bb0c146
<?php
namespace
App\Service\Requests
;
use
App\Models\Tokens
;
/**
* Class DirectRequest
* @package App\Service\Requests
...
...
composer.json
View file @
bb0c146
...
...
@@ -26,7 +26,8 @@
"nunomaduro/collision"
:
"^5.0"
,
"phpunit/phpunit"
:
"^9.3"
,
"reinink/remember-query-strings"
:
"^0.1.0"
,
"tightenco/ziggy"
:
"^0.8.0"
"tightenco/ziggy"
:
"^0.8.0"
,
"ext-json"
:
"*"
},
"config"
:
{
"optimize-autoloader"
:
true
,
...
...
database/migrations/2021_05_11_094828_create_dictionaries_table.php
View file @
bb0c146
...
...
@@ -15,7 +15,10 @@ class CreateDictionariesTable extends Migration
{
Schema
::
create
(
'dictionaries'
,
function
(
Blueprint
$table
)
{
$table
->
id
();
$table
->
bigInteger
(
'region_id'
)
->
unique
();
$table
->
bigInteger
(
'parent_id'
)
->
nullable
();
$table
->
string
(
'name'
,
255
);
$table
->
string
(
'type'
,
255
);
$table
->
timestamps
();
});
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment