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
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
9 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;
...
@@ -6,9 +6,8 @@ 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\GetDictionaries
;
use
App\Service\Requests\
APIRequest
;
use
Illuminate\Console\Command
;
use
Illuminate\Console\Command
;
use
Illuminate\Support\Facades\Bus
;
class
DictionariesLoad
extends
Command
class
DictionariesLoad
extends
Command
{
{
...
@@ -39,18 +38,22 @@ class DictionariesLoad extends Command
...
@@ -39,18 +38,22 @@ class DictionariesLoad extends Command
/**
/**
* Execute the console command.
* Execute the console command.
*
*
* @return
void
* @return
int
* @throws \Exception
* @throws \Exception
*/
*/
public
function
handle
()
public
function
handle
()
{
{
$token
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
$token
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
if
(
!
$token
){
if
(
!
$token
)
{
throw
new
\Exception
(
'Не найден токен блин'
);
throw
new
\Exception
(
'Не найден токен блин'
);
}
}
GetDictionaries
::
getInstance
(
API
::
YANDEX
)
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
->
setToken
(
$token
)
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'dictionaries'
,
'get'
)
->
call
();
->
call
();
return
0
;
}
}
}
}
app/Service/Requests/Direct/GetDictionaries.php
View file @
bb0c146
...
@@ -3,7 +3,9 @@
...
@@ -3,7 +3,9 @@
namespace
App\Service\Requests\Direct
;
namespace
App\Service\Requests\Direct
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Dictionary
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\Requests\DirectRequest
;
use
Illuminate\Support\Facades\Log
;
class
GetDictionaries
extends
DirectRequest
class
GetDictionaries
extends
DirectRequest
{
{
...
@@ -19,14 +21,46 @@ class GetDictionaries extends DirectRequest
...
@@ -19,14 +21,46 @@ class GetDictionaries extends DirectRequest
function
handle
(
$response
)
function
handle
(
$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
)
{
if
(
$this
->
next
)
{
$this
->
next
->
call
(
null
,
$response
);
$this
->
next
->
call
(
null
,
$response
);
}
}
}
catch
(
\Exception
$e
)
{
Log
::
debug
(
$e
);
}
}
}
private
function
requestPrepare
(
$response
)
private
function
requestPrepare
(
$response
)
{
{
$this
->
setService
(
'dictionaries'
);
$this
->
setService
(
'dictionaries'
);
$this
->
setMethod
(
'get'
);
$this
->
setMethod
(
'get'
);
$params
=
[
'DictionaryNames'
=>
[
"GeoRegions"
,
],
];
$this
->
setParams
(
$params
);
}
}
}
}
app/Service/Requests/DirectRequest.php
View file @
bb0c146
<?php
<?php
namespace
App\Service\Requests
;
namespace
App\Service\Requests
;
use
App\Models\Tokens
;
/**
/**
* Class DirectRequest
* Class DirectRequest
* @package App\Service\Requests
* @package App\Service\Requests
...
...
composer.json
View file @
bb0c146
...
@@ -26,7 +26,8 @@
...
@@ -26,7 +26,8 @@
"nunomaduro/collision"
:
"^5.0"
,
"nunomaduro/collision"
:
"^5.0"
,
"phpunit/phpunit"
:
"^9.3"
,
"phpunit/phpunit"
:
"^9.3"
,
"reinink/remember-query-strings"
:
"^0.1.0"
,
"reinink/remember-query-strings"
:
"^0.1.0"
,
"tightenco/ziggy"
:
"^0.8.0"
"tightenco/ziggy"
:
"^0.8.0"
,
"ext-json"
:
"*"
},
},
"config"
:
{
"config"
:
{
"optimize-autoloader"
:
true
,
"optimize-autoloader"
:
true
,
...
...
database/migrations/2021_05_11_094828_create_dictionaries_table.php
View file @
bb0c146
...
@@ -15,7 +15,10 @@ class CreateDictionariesTable extends Migration
...
@@ -15,7 +15,10 @@ class CreateDictionariesTable extends Migration
{
{
Schema
::
create
(
'dictionaries'
,
function
(
Blueprint
$table
)
{
Schema
::
create
(
'dictionaries'
,
function
(
Blueprint
$table
)
{
$table
->
id
();
$table
->
id
();
$table
->
bigInteger
(
'region_id'
)
->
unique
();
$table
->
bigInteger
(
'parent_id'
)
->
nullable
();
$table
->
string
(
'name'
,
255
);
$table
->
string
(
'name'
,
255
);
$table
->
string
(
'type'
,
255
);
$table
->
timestamps
();
$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