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 879faa7e
authored
Jun 08, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19468 Первоначальная загрузка групп объявлений.
1 parent
3c283578
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
50 additions
and
109 deletions
app/Console/Commands/AdGroupLoadUpdated.php
app/Console/Commands/AdGroupsAdd.php
app/Console/Commands/AdGroupsLoadUpdated.php
app/Models/AdGroup.php
app/Models/Campaigns.php
app/Models/Pivots/DictionaryCampaign.php
app/Models/Pivots/GoalAdGroup.php
app/Models/Tokens.php
app/Service/Requests/Direct/CheckChanges.php
app/Console/Commands/AdGroupLoadUpdated.php
deleted
100644 → 0
View file @
3c28357
<?php
namespace
App\Console\Commands
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\AdGroup
;
use
App\Models\Campaigns
;
use
App\Models\Pivots\DictionaryCampaign
;
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\Database\Eloquent\Relations\HasManyThrough
;
use
Illuminate\Support\Facades\Bus
;
class
AdGroupLoadUpdated
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'adgroups:loadUpdated'
;
/**
* 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
()
{
$campaigns
=
AdGroup
::
forUpdatedSelf
()
->
get
();
if
(
!
$campaigns
->
count
())
{
return
;
}
$token
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
if
(
!
$token
)
{
throw
new
\Exception
(
'Не найден токен блин'
);
}
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'Campaigns'
,
'get'
)
->
call
([
'ids'
=>
$campaigns
->
pluck
(
'external_id'
)
->
all
(),
]);
$tokens
=
Tokens
::
has
(
'dictionaryCampaignsEnabledForExternalSynchronized.groupsForExternalForUpdatedSelf'
)
->
with
(
'dictionaryCampaignsEnabledForExternalSynchronized.groupsForExternalForUpdatedSelf'
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
foreach
(
$tokens
as
$token
)
{
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'AdGroups'
,
'get'
)
->
call
([
'Ids'
=>
$token
->
dictionaryCampaignsEnabledForExternalSynchronized
->
pluck
(
'groupsForExternalForUpdatedSelf'
)
->
collapse
()
->
all
(),
]);
}
return
0
;
}
}
app/Console/Commands/AdGroupsAdd.php
View file @
879faa7
...
...
@@ -54,10 +54,9 @@ class AdGroupsAdd extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'AdGroups'
,
'add'
)
->
call
([
'goalAdGroups'
=>
$token
->
dictionaryCampaignsEnabledForExternal
->
pluck
(
'dictionaryCampaignsEnabledForExternalSynchronized
'
)
'goalAdGroups'
=>
$token
->
dictionaryCampaignsEnabledForExternal
Synchronized
->
pluck
(
'groupsForNotExternal
'
)
->
collapse
(),
]);
}
...
...
app/Console/Commands/AdGroupsLoadUpdated.php
View file @
879faa7
...
...
@@ -2,11 +2,18 @@
namespace
App\Console\Commands
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\AdGroup
;
use
App\Models\Campaigns
;
use
App\Models\Pivots\DictionaryCampaign
;
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\Database\Eloquent\Relations\HasManyThrough
;
use
Illuminate\Support\Facades\Bus
;
class
AdGroupsLoadUpdated
extends
Command
{
...
...
@@ -22,7 +29,7 @@ class AdGroupsLoadUpdated extends Command
*
* @var string
*/
protected
$description
=
'Загрузка измененны
х групп
'
;
protected
$description
=
'Загрузка измененны
е группы
'
;
/**
* Create a new command instance.
...
...
@@ -38,27 +45,43 @@ class AdGroupsLoadUpdated extends Command
* Execute the console command.
*
* @return int
* @throws \Exception
*/
public
function
handle
()
{
$
token
=
Tokens
::
has
(
'campaignsAdGroupsForUpdatedSelf'
)
->
with
(
'campaignsAdGroupsForUpdatedSelf'
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
first
();
$
adGroups
=
AdGroup
::
forUpdatedSelf
()
->
get
();
if
(
!
$adGroups
->
count
())
{
return
;
}
$token
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
if
(
!
$token
)
{
return
0
;
throw
new
\Exception
(
'Не найден токен блин'
)
;
}
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'AdGroups'
,
'get'
)
->
call
([
'CampaignIds'
=>
$token
->
campaignsAdGroupsForUpdatedSelf
->
pluck
(
'campaign_external_id'
)
->
all
(),
$factory
->
getRequest
(
'AdGroups'
,
'get'
)
->
call
([
'Ids'
=>
$adGroups
->
pluck
(
'external_id'
)
->
all
(),
]);
$tokens
=
Tokens
::
has
(
'dictionaryCampaignsEnabledForExternalSynchronized.groupsForExternalForUpdatedSelf'
)
->
with
(
'dictionaryCampaignsEnabledForExternalSynchronized.groupsForExternalForUpdatedSelf'
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
foreach
(
$tokens
as
$token
)
{
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'AdGroups'
,
'get'
)
->
call
([
'Ids'
=>
$token
->
dictionaryCampaignsEnabledForExternalSynchronized
->
pluck
(
'groupsForExternalForUpdatedSelf'
)
->
collapse
()
->
pluck
(
'external_id'
)
->
all
(),
]);
}
return
0
;
}
}
app/Models/AdGroup.php
View file @
879faa7
...
...
@@ -105,8 +105,6 @@ class AdGroup extends Model
protected
$casts
=
[
'campaign_id'
=>
'int'
,
'external_id'
=>
'int'
,
'campaign_external_id'
=>
'int'
,
'region_ids'
=>
'array'
,
'negative_keywords'
=>
'json'
,
'negative_keyword_shared_set_ids'
=>
'json'
,
...
...
@@ -126,7 +124,6 @@ class AdGroup extends Model
static
public
function
getPropertiesWatch
()
{
return
collect
([
'campaign_external_id'
,
'name'
,
'region_ids'
,
'negative_keywords'
,
...
...
@@ -156,10 +153,14 @@ class AdGroup extends Model
if
(
GoalAdGroup
::
getPropertiesCopyWithPivot
()
->
first
(
function
(
$property_name
)
use
(
$ad_group
)
{
return
$ad_group
->
{
$property_name
}
!==
$ad_group
->
getOriginal
(
$property_name
);
}))
{
if
(
!
is_null
(
$ad_group
->
campaign_id
)
&&
is_null
(
$ad_group
->
getOriginal
(
'campaign_id'
)))
{
$ad_group
->
campaign
->
copyGroupInGoalGroup
();
}
else
{
$ad_group
->
goalGroups
()
->
update
(
GoalAdGroup
::
copyPropertyFromMain
(
$ad_group
)
);
}
}
if
(
self
::
getPropertiesWatch
()
->
first
(
function
(
$property_name
)
use
(
$ad_group
)
{
return
$ad_group
->
{
$property_name
}
!==
$ad_group
->
getOriginal
(
$property_name
);
...
...
app/Models/Campaigns.php
View file @
879faa7
...
...
@@ -111,7 +111,6 @@ class Campaigns extends Model
];
protected
$casts
=
[
'external_id'
=>
'int'
,
'time_targeting'
=>
'array'
,
'negative_keywords'
=>
'array'
,
'blocked_ips'
=>
'array'
,
...
...
@@ -232,7 +231,8 @@ class Campaigns extends Model
$campaign
->
groups
()
->
get
()
->
each
(
function
(
AdGroup
$adGroup
)
use
(
$dictionaryCampaign
)
{
$dictionaryCampaign
->
groups
()
->
updateOrCreate
([
'campaign_id'
=>
$dictionaryCampaign
->
external_id
,
'campaign_external_id'
=>
$dictionaryCampaign
->
external_id
,
'ad_group_id'
=>
$adGroup
->
getKey
(),
],
GoalAdGroup
::
copyPropertyFromMain
(
$adGroup
));
});
...
...
app/Models/Pivots/DictionaryCampaign.php
View file @
879faa7
...
...
@@ -102,7 +102,6 @@ class DictionaryCampaign extends Pivot
];
protected
$casts
=
[
'external_id'
=>
'int'
,
'campaign_id'
=>
'int'
,
'dictionary_id'
=>
'int'
,
'negative_keywords'
=>
'array'
,
...
...
app/Models/Pivots/GoalAdGroup.php
View file @
879faa7
...
...
@@ -71,8 +71,6 @@ class GoalAdGroup extends Pivot
];
protected
$casts
=
[
'external_id'
=>
'int'
,
'campaign_external_id'
=>
'int'
,
'ad_group_id'
=>
'int'
,
'dictionary_campaign_id'
=>
'int'
,
'negative_keywords'
=>
'array'
,
...
...
app/Models/Tokens.php
View file @
879faa7
...
...
@@ -27,8 +27,8 @@ use Illuminate\Database\Eloquent\Model;
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Campaigns[] $campaigns
* @property-read int|null $campaigns_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\AdGroup[] $campaignsAdGroups
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\AdGroup[] $campaignsAdGroupsForUpdatedSelf
* @property-read int|null $campaigns_ad_groups_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\AdGroup[] $campaigns
ForEnabled
AdGroupsForUpdatedSelf
* @property-read int|null $campaigns_
for_enabled_
ad_groups_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Campaigns[] $campaignsNotEnabledNotDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Campaigns[] $campaignsEnabledDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Campaigns[] $campaignsEnabledNotDisabledUpdatedChildren
...
...
@@ -145,9 +145,9 @@ class Tokens extends Model
return
$this
->
hasManyThrough
(
AdGroup
::
class
,
Campaigns
::
class
,
'token'
,
'campaign_id'
);
}
public
function
campaignsAdGroupsForUpdatedSelf
()
public
function
campaigns
ForEnabled
AdGroupsForUpdatedSelf
()
{
return
$this
->
campaignsAdGroups
()
->
forUpdatedSelf
();
return
$this
->
campaignsAdGroups
()
->
forUpdatedSelf
()
->
where
(
Campaigns
::
getModel
()
->
getTable
()
.
'.enabled'
,
true
)
;
}
public
function
campaignsNotEnabledNotDisabled
()
...
...
app/Service/Requests/Direct/CheckChanges.php
View file @
879faa7
...
...
@@ -72,6 +72,12 @@ class CheckChanges extends DirectRequest
$adGroup
->
update
([
'updated_self'
=>
Carbon
::
now
(),
]);
}
else
{
$adGroup
=
AdGroup
::
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'external_id'
=>
$ad_group_id
,
'updated_self'
=>
Carbon
::
now
(),
]);
}
}
else
{
$goalAdGroup
=
GoalAdGroup
::
where
(
'external_id'
,
$ad_group_id
)
->
first
();
...
...
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