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 16d4677a
authored
May 31, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#20207 Доработка изменения РК
1 parent
57beb8cd
Hide whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
83 additions
and
69 deletions
app/Console/Commands/AdGroupsLoadUpdated.php
app/Console/Commands/CampaignsAdd.php
app/Console/Commands/CampaignsCheckChange.php
app/Console/Commands/CampaignsFirstLoad.php
app/Console/Commands/CampaignsLoadGroups.php
app/Console/Commands/CampaignsLoadUpdated.php
app/Console/Commands/CampaignsLoadUpdatedChildrenAdGroups.php
app/Console/Commands/CampaignsResume.php
app/Console/Commands/CampaignsSuspend.php
app/Console/Commands/CampaignsUpdate.php
app/Console/Commands/DictionariesLoad.php
app/Jobs/ProcessCallAPI.php
app/Jobs/ProcessCallLimitedAPI.php
app/Models/Tokens.php
app/Service/Contract/APIRequest.php
app/Service/Contract/Limits.php
app/Service/Limits.php
app/Service/Requests/APIRequest.php
app/Service/Requests/Direct/AddCampaigns.php
app/Service/Requests/Direct/CheckCampaignsChange.php
app/Service/Requests/Direct/CheckChanges.php
app/Service/Requests/Direct/CheckDictionariesChange.php
app/Service/Requests/Direct/GetAdGroups.php
app/Service/Requests/Direct/GetCampaigns.php
app/Service/Requests/Direct/GetDictionaries.php
app/Service/Requests/Direct/ResumeCampaigns.php
app/Service/Requests/Direct/SuspendCampaigns.php
app/Service/Requests/Direct/UpdateCampaigns.php
app/Service/Requests/DirectRequest.php
tests/Unit/AddCampaignsTest.php
app/Console/Commands/AdGroupsLoadUpdated.php
View file @
16d4677
...
@@ -58,7 +58,7 @@ class AdGroupsLoadUpdated extends Command
...
@@ -58,7 +58,7 @@ class AdGroupsLoadUpdated extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'
adg
roups'
,
'get'
)
$factory
->
getRequest
(
'
AdG
roups'
,
'get'
)
->
call
([
->
call
([
'CampaignIds'
=>
$token
->
campaignsAdGroupsForUpdatedSelf
->
pluck
(
'campaign_external_id'
)
->
all
(),
'CampaignIds'
=>
$token
->
campaignsAdGroupsForUpdatedSelf
->
pluck
(
'campaign_external_id'
)
->
all
(),
]);
]);
...
...
app/Console/Commands/CampaignsAdd.php
View file @
16d4677
...
@@ -56,7 +56,7 @@ class CampaignsAdd extends Command
...
@@ -56,7 +56,7 @@ class CampaignsAdd extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'
c
ampaigns'
,
'add'
)
$factory
->
getRequest
(
'
C
ampaigns'
,
'add'
)
->
call
([
->
call
([
'dictionaryCampaigns'
=>
$token
->
dictionaryCampaignsEnabledForNotExternal
,
'dictionaryCampaigns'
=>
$token
->
dictionaryCampaignsEnabledForNotExternal
,
'variables'
=>
Variable
::
all
(),
'variables'
=>
Variable
::
all
(),
...
...
app/Console/Commands/CampaignsCheckChange.php
View file @
16d4677
...
@@ -46,7 +46,7 @@ class CampaignsCheckChange extends Command
...
@@ -46,7 +46,7 @@ class CampaignsCheckChange extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token_main
);
$factory
->
setToken
(
$token_main
);
$factory
->
getRequest
(
'
change
'
,
'checkCampaigns'
)
$factory
->
getRequest
(
'
Changes
'
,
'checkCampaigns'
)
->
call
();
->
call
();
}
}
...
@@ -57,7 +57,7 @@ class CampaignsCheckChange extends Command
...
@@ -57,7 +57,7 @@ class CampaignsCheckChange extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'
change
'
,
'checkCampaigns'
)
$factory
->
getRequest
(
'
Changes
'
,
'checkCampaigns'
)
->
call
();
->
call
();
}
}
...
...
app/Console/Commands/CampaignsFirstLoad.php
View file @
16d4677
...
@@ -48,8 +48,8 @@ class CampaignsFirstLoad extends Command
...
@@ -48,8 +48,8 @@ class CampaignsFirstLoad extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'
change
'
,
'CheckDictionaries'
)
->
call
();
$factory
->
getRequest
(
'
Changes
'
,
'CheckDictionaries'
)
->
call
();
$factory
->
getRequest
(
'
c
ampaigns'
,
'get'
)
->
call
();
$factory
->
getRequest
(
'
C
ampaigns'
,
'get'
)
->
call
();
return
0
;
return
0
;
}
}
...
...
app/Console/Commands/CampaignsLoadGroups.php
View file @
16d4677
...
@@ -56,7 +56,7 @@ class CampaignsLoadGroups extends Command
...
@@ -56,7 +56,7 @@ class CampaignsLoadGroups extends Command
$factory
->
setToken
(
$token
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'
adg
roups'
,
'get'
)
$factory
->
getRequest
(
'
AdG
roups'
,
'get'
)
->
call
([
->
call
([
'CampaignIds'
=>
$campaigns
->
pluck
(
'external_id'
)
->
all
(),
'CampaignIds'
=>
$campaigns
->
pluck
(
'external_id'
)
->
all
(),
]);
]);
...
...
app/Console/Commands/CampaignsLoadUpdated.php
View file @
16d4677
...
@@ -60,7 +60,7 @@ class CampaignsLoadUpdated extends Command
...
@@ -60,7 +60,7 @@ class CampaignsLoadUpdated extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'
c
ampaigns'
,
'get'
)
->
call
([
$factory
->
getRequest
(
'
C
ampaigns'
,
'get'
)
->
call
([
'ids'
=>
$campaigns
->
pluck
(
'external_id'
)
->
all
(),
'ids'
=>
$campaigns
->
pluck
(
'external_id'
)
->
all
(),
]);
]);
...
@@ -77,7 +77,7 @@ class CampaignsLoadUpdated extends Command
...
@@ -77,7 +77,7 @@ class CampaignsLoadUpdated extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'
c
ampaigns'
,
'get'
)
->
call
([
$factory
->
getRequest
(
'
C
ampaigns'
,
'get'
)
->
call
([
'ids'
=>
$token
->
dictionaryCampaignsEnabledForExternalSynchronizedUpdatedSelf
'ids'
=>
$token
->
dictionaryCampaignsEnabledForExternalSynchronizedUpdatedSelf
->
pluck
(
'external_id'
)
->
all
(),
->
pluck
(
'external_id'
)
->
all
(),
]);
]);
...
...
app/Console/Commands/CampaignsLoadUpdatedChildrenAdGroups.php
View file @
16d4677
...
@@ -60,7 +60,7 @@ class CampaignsLoadUpdatedChildrenAdGroups extends Command
...
@@ -60,7 +60,7 @@ class CampaignsLoadUpdatedChildrenAdGroups extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'
c
hanges'
,
'check'
)
->
call
([
$factory
->
getRequest
(
'
C
hanges'
,
'check'
)
->
call
([
'CampaignIds'
=>
$campaigns
->
pluck
(
'external_id'
)
->
all
(),
'CampaignIds'
=>
$campaigns
->
pluck
(
'external_id'
)
->
all
(),
'FieldNames'
=>
[
'FieldNames'
=>
[
'AdGroupIds'
,
'AdGroupIds'
,
...
@@ -81,7 +81,7 @@ class CampaignsLoadUpdatedChildrenAdGroups extends Command
...
@@ -81,7 +81,7 @@ class CampaignsLoadUpdatedChildrenAdGroups extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'
c
hanges'
,
'check'
)
->
call
([
$factory
->
getRequest
(
'
C
hanges'
,
'check'
)
->
call
([
'CampaignIds'
=>
$token
->
dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren
'CampaignIds'
=>
$token
->
dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren
->
pluck
(
'external_id'
)
->
all
(),
->
pluck
(
'external_id'
)
->
all
(),
'FieldNames'
=>
[
'FieldNames'
=>
[
...
...
app/Console/Commands/CampaignsResume.php
View file @
16d4677
...
@@ -74,7 +74,7 @@ class CampaignsResume extends Command
...
@@ -74,7 +74,7 @@ class CampaignsResume extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'
c
ampaigns'
,
'resume'
)
$factory
->
getRequest
(
'
C
ampaigns'
,
'resume'
)
->
call
([
->
call
([
'ids'
=>
$token
->
dictionaryCampaignsEnabledForExternalDisabled
->
pluck
(
'external_id'
)
->
all
(),
'ids'
=>
$token
->
dictionaryCampaignsEnabledForExternalDisabled
->
pluck
(
'external_id'
)
->
all
(),
]);
]);
...
...
app/Console/Commands/CampaignsSuspend.php
View file @
16d4677
...
@@ -73,7 +73,7 @@ class CampaignsSuspend extends Command
...
@@ -73,7 +73,7 @@ class CampaignsSuspend extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'
c
ampaigns'
,
'suspend'
)
$factory
->
getRequest
(
'
C
ampaigns'
,
'suspend'
)
->
call
([
->
call
([
'ids'
=>
$token
->
dictionaryCampaignsNotEnabledForExternalNotDisabled
->
pluck
(
'external_id'
)
->
all
(),
'ids'
=>
$token
->
dictionaryCampaignsNotEnabledForExternalNotDisabled
->
pluck
(
'external_id'
)
->
all
(),
]);
]);
...
...
app/Console/Commands/CampaignsUpdate.php
View file @
16d4677
...
@@ -58,7 +58,6 @@ class CampaignsUpdate extends Command
...
@@ -58,7 +58,6 @@ class CampaignsUpdate extends Command
$factory
->
getRequest
(
'campaigns'
,
'update'
)
$factory
->
getRequest
(
'campaigns'
,
'update'
)
->
call
([
->
call
([
'dictionaryCampaigns'
=>
$token
->
dictionaryCampaignsEnabledForExternalNeedUpdated
,
'dictionaryCampaigns'
=>
$token
->
dictionaryCampaignsEnabledForExternalNeedUpdated
,
'variables'
=>
Variable
::
all
(),
]);
]);
}
}
...
...
app/Console/Commands/DictionariesLoad.php
View file @
16d4677
...
@@ -51,7 +51,7 @@ class DictionariesLoad extends Command
...
@@ -51,7 +51,7 @@ class DictionariesLoad extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'
d
ictionaries'
,
'get'
)
$factory
->
getRequest
(
'
D
ictionaries'
,
'get'
)
->
call
();
->
call
();
return
0
;
return
0
;
...
...
app/Jobs/ProcessCallAPI.php
View file @
16d4677
...
@@ -19,6 +19,7 @@ class ProcessCallAPI implements ShouldQueue
...
@@ -19,6 +19,7 @@ class ProcessCallAPI implements ShouldQueue
private
$api
;
private
$api
;
private
$limitId
;
private
$limitId
;
/**
/**
* Create a new job instance.
* Create a new job instance.
*
*
...
@@ -39,21 +40,21 @@ class ProcessCallAPI implements ShouldQueue
...
@@ -39,21 +40,21 @@ class ProcessCallAPI implements ShouldQueue
{
{
$limits
=
Limits
::
getInstance
(
$this
->
api
->
getToken
());
$limits
=
Limits
::
getInstance
(
$this
->
api
->
getToken
());
try
{
try
{
$api
=
API
::
getInstance
(
$this
->
api
);
$api
=
API
::
getInstance
(
$this
->
api
);
//считаем на сколько объектов зарезервировано получение данных
//считаем на сколько объектов зарезервировано получение данных
//только их и запрашиваем
//только их и запрашиваем
$limit
=
\App\Models\Limits
::
find
(
$this
->
limitId
);
$limit
=
\App\Models\Limits
::
find
(
$this
->
limitId
);
//те на которые не хватило баллов помещаем в очередь
//те на которые не хватило баллов помещаем в очередь
if
(
$apiR
=
$this
->
api
->
chunk
(
$limit
->
spent
))
{
if
(
$apiR
=
$this
->
api
->
slice
(
$limit
->
spent
))
{
dispatch
(
new
ProcessCallLimitedAPI
(
$apiR
));
dispatch
(
new
ProcessCallLimitedAPI
(
$apiR
));
}
}
$response
=
$api
->
execute
();
$response
=
$api
->
execute
();
$limits
->
acceptRezerv
(
$this
->
limitId
,
new
HeaderLimits
(
$response
->
headers
())
);
$limits
->
acceptRezerv
(
$this
->
limitId
,
new
HeaderLimits
(
$response
->
headers
()));
//TODO: обработать результат.
//TODO: обработать результат.
// если не хватило баллов на все что хотели запросить, то в очередь отправляем новый запрос на получение новых данных
// если не хватило баллов на все что хотели запросить, то в очередь отправляем новый запрос на получение новых данных
AdsHandler
::
getInstance
(
$this
->
api
)
->
handle
(
$response
);
AdsHandler
::
getInstance
(
$this
->
api
)
->
handle
(
$response
);
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
//TODO: надо отдельно выделить ошибки вызовов, за которые списываются баллы
//TODO: надо отдельно выделить ошибки вызовов, за которые списываются баллы
//https://yandex.ru/dev/direct/doc/dg/concepts/errors.html
//https://yandex.ru/dev/direct/doc/dg/concepts/errors.html
$limits
->
removeRezerv
(
$this
->
limitId
);
$limits
->
removeRezerv
(
$this
->
limitId
);
...
...
app/Jobs/ProcessCallLimitedAPI.php
View file @
16d4677
...
@@ -48,7 +48,7 @@ class ProcessCallLimitedAPI implements ShouldQueue//, ShouldBeUnique
...
@@ -48,7 +48,7 @@ class ProcessCallLimitedAPI implements ShouldQueue//, ShouldBeUnique
try
{
try
{
//резервируем на это количетсво
//резервируем на это количетсво
$limitId
=
$limits
->
doRezerv
(
$this
->
api
,
$
objects
);
$limitId
=
$limits
->
doRezerv
(
$this
->
api
,
$
limits
->
countObjects
(
$this
->
api
)
);
}
catch
(
\Exception
$e
){
}
catch
(
\Exception
$e
){
//нет свободных баллов, замораживаем до следующего часа
//нет свободных баллов, замораживаем до следующего часа
$this
->
reRunHour
();
$this
->
reRunHour
();
...
...
app/Models/Tokens.php
View file @
16d4677
...
@@ -80,6 +80,7 @@ class Tokens extends Model
...
@@ -80,6 +80,7 @@ class Tokens extends Model
];
];
protected
$casts
=
[
protected
$casts
=
[
'limit'
=>
'integer'
,
'check_changes'
=>
'datetime'
,
'check_changes'
=>
'datetime'
,
'check_changes_campaign'
=>
'datetime'
,
'check_changes_campaign'
=>
'datetime'
,
'check_changes_ad_group'
=>
'datetime'
,
'check_changes_ad_group'
=>
'datetime'
,
...
...
app/Service/Contract/APIRequest.php
View file @
16d4677
...
@@ -14,7 +14,8 @@ interface APIRequest{
...
@@ -14,7 +14,8 @@ interface APIRequest{
function
getToken
()
:
Tokens
;
function
getToken
()
:
Tokens
;
function
getApi
()
:
string
;
function
getApi
()
:
string
;
function
chunk
(
$objects
)
:
?
APIRequest
;
function
getCountObjects
()
:
int
;
function
slice
(
$objects
)
:
?
APIRequest
;
function
call
(
$params
=
null
);
function
call
(
$params
=
null
);
function
handle
(
$response
);
function
handle
(
$response
);
...
...
app/Service/Contract/Limits.php
View file @
16d4677
...
@@ -5,6 +5,7 @@ interface Limits{
...
@@ -5,6 +5,7 @@ interface Limits{
function
current
()
:
int
;
function
current
()
:
int
;
function
DayLimit
()
:
int
;
function
DayLimit
()
:
int
;
function
countObjectsLimit
(
APIRequest
$request
)
:
int
;
function
countObjectsLimit
(
APIRequest
$request
)
:
int
;
function
countObjects
(
APIRequest
$request
)
:
int
;
function
doRezerv
(
APIRequest
$request
,
int
$limit
)
:
int
;
function
doRezerv
(
APIRequest
$request
,
int
$limit
)
:
int
;
function
removeRezerv
(
int
$id
);
function
removeRezerv
(
int
$id
);
function
updateLimits
(
HeaderLimits
$limits
);
function
updateLimits
(
HeaderLimits
$limits
);
...
...
app/Service/Limits.php
View file @
16d4677
...
@@ -53,13 +53,21 @@ class Limits implements \App\Service\Contract\Limits {
...
@@ -53,13 +53,21 @@ class Limits implements \App\Service\Contract\Limits {
$this
->
token
->
save
();
$this
->
token
->
save
();
}
}
function
countObjects
(
\App\Service\Contract\APIRequest
$request
)
:
int
{
return
$request
->
getCountObjects
();
}
function
countObjectsLimit
(
\App\Service\Contract\APIRequest
$request
)
:
int
function
countObjectsLimit
(
\App\Service\Contract\APIRequest
$request
)
:
int
{
{
$cost
=
$this
->
limitCosts
->
getCostObject
(
$request
);
$cost
=
$this
->
limitCosts
->
getCostObject
(
$request
);
if
(
$this
->
limitCosts
->
getCostCall
(
$request
)
>
$this
->
current
()){
$costCall
=
$this
->
limitCosts
->
getCostCall
(
$request
);
if
(
$costCall
>
$this
->
current
())
{
return
0
;
return
0
;
}
}
return
$cost
>
0
?
floor
((
$this
->
current
()
-
$this
->
limitCosts
->
getCostCall
(
$request
))
/
$cost
)
:
-
1
;
return
$cost
>
0
?
floor
(
$this
->
current
()
-
$this
->
getSpent
(
$this
->
countObjects
(
$request
),
$request
))
:
-
1
;
}
}
/**
/**
...
@@ -91,6 +99,7 @@ class Limits implements \App\Service\Contract\Limits {
...
@@ -91,6 +99,7 @@ class Limits implements \App\Service\Contract\Limits {
$rezerv
->
save
();
$rezerv
->
save
();
$this
->
token
->
limit
-=
$limit
;
$this
->
token
->
limit
-=
$limit
;
$this
->
token
->
save
();
$this
->
token
->
save
();
DB
::
commit
();
DB
::
commit
();
...
...
app/Service/Requests/APIRequest.php
View file @
16d4677
...
@@ -73,7 +73,12 @@ class APIRequest implements \App\Service\Contract\APIRequest {
...
@@ -73,7 +73,12 @@ class APIRequest implements \App\Service\Contract\APIRequest {
return
$this
->
token
;
return
$this
->
token
;
}
}
function
chunk
(
$count
)
:
?
\App\Service\Contract\APIRequest
function
getCountObjects
()
:
int
{
throw
new
Exception
(
'Я не знаю как считать кол-во объектов'
);
}
function
slice
(
$count
)
:
?
\App\Service\Contract\APIRequest
{
{
throw
new
Exception
(
'Я не знаю формата запрсов, чтобы его разбить'
);
throw
new
Exception
(
'Я не знаю формата запрсов, чтобы его разбить'
);
}
}
...
...
app/Service/Requests/Direct/AddCampaigns.php
View file @
16d4677
...
@@ -9,16 +9,11 @@ use App\Models\Variable;
...
@@ -9,16 +9,11 @@ use App\Models\Variable;
use
App\Service\Requests\DirectRequest
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\StrReplaceByVariables
;
use
App\Service\StrReplaceByVariables
;
use
Carbon\Carbon
;
use
Carbon\Carbon
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Support\Facades\Log
;
use
Illuminate\Support\Facades\Log
;
class
AddCampaigns
extends
DirectRequest
class
AddCampaigns
extends
DirectRequest
{
{
protected
$timestamp
;
protected
$timestamp
;
/* @var Collection|DictionaryCampaign[] $dictionaryCampaigns */
protected
$dictionaryCampaigns
;
/* @var Collection|Variable[] $dictionaryCampaigns */
protected
$variables
;
public
function
call
(
$params
=
null
)
public
function
call
(
$params
=
null
)
{
{
...
@@ -35,16 +30,16 @@ class AddCampaigns extends DirectRequest
...
@@ -35,16 +30,16 @@ class AddCampaigns extends DirectRequest
}
}
foreach
(
$response
[
'result'
][
'AddResults'
]
as
$key
=>
$add_result
)
{
foreach
(
$response
[
'result'
][
'AddResults'
]
as
$key
=>
$add_result
)
{
$id
=
$add_result
[
'Id'
]
??
''
;
$
external_
id
=
$add_result
[
'Id'
]
??
''
;
if
(
!
$id
)
{
if
(
!
$
external_
id
)
{
Log
::
debug
(
"AddCampaigns, empty Id
, [dictionary_campaigns.id =
{
$this
->
dictionaryCampaigns
->
get
(
$key
)
->
getKey
()
}
]
"
);
Log
::
debug
(
"AddCampaigns, empty Id"
);
Log
::
debug
(
$add_result
);
Log
::
debug
(
$add_result
);
continue
;
continue
;
}
}
$this
->
dictionaryCampaigns
->
get
(
$key
)
->
update
([
DictionaryCampaign
::
where
(
'external_id'
,
$external_id
)
->
update
([
'external_id'
=>
$id
,
'external_id'
=>
$
external_
id
,
'external_upload_at'
=>
Carbon
::
now
(),
'external_upload_at'
=>
Carbon
::
now
(),
]);
]);
}
}
...
@@ -53,22 +48,13 @@ class AddCampaigns extends DirectRequest
...
@@ -53,22 +48,13 @@ class AddCampaigns extends DirectRequest
}
}
}
}
public
function
putParams
(
$params
)
{
$this
->
dictionaryCampaigns
=
$params
[
'dictionaryCampaigns'
];
$this
->
variables
=
$params
[
'variables'
];
}
private
function
requestPrepare
(
$params
)
private
function
requestPrepare
(
$params
)
{
{
$this
->
setService
(
'
c
ampaigns'
);
$this
->
setService
(
'
C
ampaigns'
);
$this
->
setMethod
(
'add'
);
$this
->
setMethod
(
'add'
);
$this
->
putParams
(
$params
);
$this
->
setParams
([
$this
->
setParams
([
'Campaigns'
=>
$this
->
dictionaryCampaigns
->
map
(
function
(
$dictionaryCampaign
)
{
'Campaigns'
=>
$this
[
'dictionaryCampaigns'
]
->
map
(
function
(
DictionaryCampaign
$dictionaryCampaign
)
{
/* @var DictionaryCampaign $dictionaryCampaign */
$list
=
Variable
::
getListVariablesByDictionaryCampaign
(
$dictionaryCampaign
);
$list
=
Variable
::
getListVariablesByDictionaryCampaign
(
$dictionaryCampaign
);
...
...
app/Service/Requests/Direct/CheckCampaignsChange.php
View file @
16d4677
...
@@ -68,7 +68,7 @@ class CheckCampaignsChange extends DirectRequest
...
@@ -68,7 +68,7 @@ class CheckCampaignsChange extends DirectRequest
private
function
requestPrepare
(
$params
)
private
function
requestPrepare
(
$params
)
{
{
$this
->
setService
(
'
c
hanges'
);
$this
->
setService
(
'
C
hanges'
);
$this
->
setMethod
(
'checkCampaigns'
);
$this
->
setMethod
(
'checkCampaigns'
);
$this
->
setParams
([
$this
->
setParams
([
'Timestamp'
=>
$this
->
getToken
()
->
check_changes_campaign_at
->
toIso8601ZuluString
(),
'Timestamp'
=>
$this
->
getToken
()
->
check_changes_campaign_at
->
toIso8601ZuluString
(),
...
...
app/Service/Requests/Direct/CheckChanges.php
View file @
16d4677
...
@@ -78,7 +78,7 @@ class CheckChanges extends DirectRequest
...
@@ -78,7 +78,7 @@ class CheckChanges extends DirectRequest
private
function
requestPrepare
(
$params
)
private
function
requestPrepare
(
$params
)
{
{
$this
->
setService
(
'
c
hanges'
);
$this
->
setService
(
'
C
hanges'
);
$this
->
setMethod
(
'check'
);
$this
->
setMethod
(
'check'
);
$this
->
setParams
(
$params
);
$this
->
setParams
(
$params
);
...
...
app/Service/Requests/Direct/CheckDictionariesChange.php
View file @
16d4677
...
@@ -15,7 +15,7 @@ class CheckDictionariesChange extends DirectRequest {
...
@@ -15,7 +15,7 @@ class CheckDictionariesChange extends DirectRequest {
}
}
private
function
requestPrepare
(
$params
){
private
function
requestPrepare
(
$params
){
$this
->
setService
(
'
c
hanges'
);
$this
->
setService
(
'
C
hanges'
);
$this
->
setMethod
(
'checkDictionaries'
);
$this
->
setMethod
(
'checkDictionaries'
);
}
}
}
}
app/Service/Requests/Direct/GetAdGroups.php
View file @
16d4677
...
@@ -98,7 +98,7 @@ class GetAdGroups extends DirectRequest
...
@@ -98,7 +98,7 @@ class GetAdGroups extends DirectRequest
private
function
requestPrepare
(
$filter
)
private
function
requestPrepare
(
$filter
)
{
{
$this
->
setService
(
'
adg
roups'
);
$this
->
setService
(
'
AdG
roups'
);
$this
->
setMethod
(
'get'
);
$this
->
setMethod
(
'get'
);
$params
=
[
$params
=
[
'SelectionCriteria'
=>
[
'SelectionCriteria'
=>
[
...
...
app/Service/Requests/Direct/GetCampaigns.php
View file @
16d4677
...
@@ -68,7 +68,7 @@ class GetCampaigns extends DirectRequest
...
@@ -68,7 +68,7 @@ class GetCampaigns extends DirectRequest
private
function
requestPrepare
(
$filter
)
private
function
requestPrepare
(
$filter
)
{
{
$this
->
setService
(
'
c
ampaigns'
);
$this
->
setService
(
'
C
ampaigns'
);
$this
->
setMethod
(
'get'
);
$this
->
setMethod
(
'get'
);
$params
=
[
$params
=
[
'SelectionCriteria'
=>
[
'SelectionCriteria'
=>
[
...
...
app/Service/Requests/Direct/GetDictionaries.php
View file @
16d4677
...
@@ -46,7 +46,7 @@ class GetDictionaries extends DirectRequest
...
@@ -46,7 +46,7 @@ class GetDictionaries extends DirectRequest
private
function
requestPrepare
(
$params
)
private
function
requestPrepare
(
$params
)
{
{
$this
->
setService
(
'
d
ictionaries'
);
$this
->
setService
(
'
D
ictionaries'
);
$this
->
setMethod
(
'get'
);
$this
->
setMethod
(
'get'
);
$params
=
[
$params
=
[
'DictionaryNames'
=>
[
'DictionaryNames'
=>
[
...
...
app/Service/Requests/Direct/ResumeCampaigns.php
View file @
16d4677
...
@@ -48,7 +48,7 @@ class ResumeCampaigns extends DirectRequest
...
@@ -48,7 +48,7 @@ class ResumeCampaigns extends DirectRequest
private
function
requestPrepare
(
$filter
)
private
function
requestPrepare
(
$filter
)
{
{
$this
->
setService
(
'
c
ampaigns'
);
$this
->
setService
(
'
C
ampaigns'
);
$this
->
setMethod
(
'resume'
);
$this
->
setMethod
(
'resume'
);
$params
=
[
$params
=
[
'SelectionCriteria'
=>
[
'SelectionCriteria'
=>
[
...
...
app/Service/Requests/Direct/SuspendCampaigns.php
View file @
16d4677
...
@@ -49,7 +49,7 @@ class SuspendCampaigns extends DirectRequest
...
@@ -49,7 +49,7 @@ class SuspendCampaigns extends DirectRequest
private
function
requestPrepare
(
$filter
)
private
function
requestPrepare
(
$filter
)
{
{
$this
->
setService
(
'
c
ampaigns'
);
$this
->
setService
(
'
C
ampaigns'
);
$this
->
setMethod
(
'suspend'
);
$this
->
setMethod
(
'suspend'
);
$params
=
[
$params
=
[
'SelectionCriteria'
=>
[
'SelectionCriteria'
=>
[
...
...
app/Service/Requests/Direct/UpdateCampaigns.php
View file @
16d4677
...
@@ -27,6 +27,23 @@ class UpdateCampaigns extends DirectRequest
...
@@ -27,6 +27,23 @@ class UpdateCampaigns extends DirectRequest
dispatch
(
$process
)
->
onQueue
(
'limits'
);
dispatch
(
$process
)
->
onQueue
(
'limits'
);
}
}
function
slice
(
$count
)
:
?
\App\Service\Contract\APIRequest
{
if
(
$count
<
0
)
return
null
;
//для запросов get ничего не разбиваем, т.к. заранее не знаем сколько чего будет
//для них только после выполнения запроса будет известно есть ли кроме $count еще данные
//а текущий запрос просто устанавливается в $count
//а вот для запросов мутаторов будем разбивать. Но тут уже будет зависеть от запроса
//будем под каждый реализовывать делитель
if
(
!
isset
(
$this
->
params
[
'Page'
])){
$this
->
params
[
'Page'
]
=
[];
}
$this
->
params
[
'Page'
][
'Limit'
]
=
$count
;
return
null
;
}
public
function
handle
(
$response
)
public
function
handle
(
$response
)
{
{
try
{
try
{
...
@@ -34,7 +51,7 @@ class UpdateCampaigns extends DirectRequest
...
@@ -34,7 +51,7 @@ class UpdateCampaigns extends DirectRequest
$external_id
=
$add_result
[
'Id'
]
??
''
;
$external_id
=
$add_result
[
'Id'
]
??
''
;
if
(
!
$external_id
)
{
if
(
!
$external_id
)
{
Log
::
debug
(
"AddCampaigns, empty Id
, [dictionary_campaigns.id =
{
$this
->
dictionaryCampaigns
->
get
(
$key
)
->
getKey
()
}
]
"
);
Log
::
debug
(
"AddCampaigns, empty Id"
);
Log
::
debug
(
$add_result
);
Log
::
debug
(
$add_result
);
continue
;
continue
;
}
}
...
@@ -50,22 +67,13 @@ class UpdateCampaigns extends DirectRequest
...
@@ -50,22 +67,13 @@ class UpdateCampaigns extends DirectRequest
}
}
}
}
public
function
putParams
(
$params
)
{
$this
->
dictionaryCampaigns
=
$params
[
'dictionaryCampaigns'
];
$this
->
variables
=
$params
[
'variables'
];
}
private
function
requestPrepare
(
$params
)
private
function
requestPrepare
(
$params
)
{
{
$this
->
setService
(
'
c
ampaigns'
);
$this
->
setService
(
'
C
ampaigns'
);
$this
->
setMethod
(
'update'
);
$this
->
setMethod
(
'update'
);
$this
->
putParams
(
$params
);
$this
->
setParams
([
$this
->
setParams
([
'Campaigns'
=>
$this
->
dictionaryCampaigns
->
map
(
function
(
$dictionaryCampaign
)
{
'Campaigns'
=>
$params
[
'dictionaryCampaigns'
]
->
map
(
function
(
DictionaryCampaign
$dictionaryCampaign
)
{
/* @var DictionaryCampaign $dictionaryCampaign */
$list
=
Variable
::
getListVariablesByDictionaryCampaign
(
$dictionaryCampaign
);
$list
=
Variable
::
getListVariablesByDictionaryCampaign
(
$dictionaryCampaign
);
...
...
app/Service/Requests/DirectRequest.php
View file @
16d4677
...
@@ -20,7 +20,12 @@ class DirectRequest extends APIRequest {
...
@@ -20,7 +20,12 @@ class DirectRequest extends APIRequest {
$this
->
url
=
config
(
'api.yandex.url'
);
$this
->
url
=
config
(
'api.yandex.url'
);
}
}
function
chunk
(
$count
)
:
?
\App\Service\Contract\APIRequest
function
getCountObjects
()
:
int
{
return
1
;
}
function
slice
(
$count
)
:
?
\App\Service\Contract\APIRequest
{
{
return
null
;
return
null
;
if
(
$count
<
0
)
if
(
$count
<
0
)
...
...
tests/Unit/AddCampaignsTest.php
View file @
16d4677
...
@@ -107,8 +107,6 @@ class AddCampaignsTest extends TestCase
...
@@ -107,8 +107,6 @@ class AddCampaignsTest extends TestCase
]
]
];
];
$this
->
request
->
putParams
(
$this
->
params
);
$this
->
request
->
handle
(
$data
);
$this
->
request
->
handle
(
$data
);
$this
->
dictionary
->
campaigns
->
first
()
->
pivot
->
refresh
();
$this
->
dictionary
->
campaigns
->
first
()
->
pivot
->
refresh
();
...
...
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