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 9753f212
authored
Jul 05, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#20364 Загрузка и синхронизация расширений
1 parent
fdf9d4c6
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
69 additions
and
26 deletions
app/Console/Commands/AdExtensionsAdd.php
app/Console/Commands/AdvertisementsAdd.php
app/Console/Commands/DictionaryCampaignsSyncByCampaign.php
app/Console/Kernel.php
app/Models/Pivots/DictionaryCampaign.php
app/Models/Pivots/GoalAdExtension.php
app/Models/Tokens.php
app/Service/Requests/Direct/AddAdExtensions.php
app/Service/Requests/Direct/GetAdExtensions.php
database/migrations/2021_07_05_103552_add_goal_ad_extensions_reserve_column.php
app/Console/Commands/AdExtensionsAdd.php
View file @
9753f21
...
...
@@ -2,7 +2,7 @@
namespace
App\Console\Commands
;
use
App\Models\AdExtension
;
use
App\Models\
Pivots\Goal
AdExtension
;
use
App\Models\Tokens
;
use
App\Service\API\API
;
use
App\Service\Requests\APIRequest
;
...
...
@@ -44,26 +44,25 @@ class AdExtensionsAdd extends Command
*/
public
function
handle
()
{
$tokens
=
Tokens
::
whereHas
(
'
dictionaryCampaignsEnabledForExternalSynchronized.a
dExtensionsForNotExternalForNotReserveCreate.adExtension'
)
$tokens
=
Tokens
::
whereHas
(
'
goalA
dExtensionsForNotExternalForNotReserveCreate.adExtension'
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
foreach
(
$tokens
as
$token
)
{
$token
->
load
([
'
dictionaryCampaignsEnabledForExternalSynchronized.a
dExtensionsForNotExternalForNotReserveCreate'
=>
function
(
HasMany
$query
)
{
'
goalA
dExtensionsForNotExternalForNotReserveCreate'
=>
function
(
HasMany
$query
)
{
return
$query
->
has
(
'adExtension'
);
},
'
dictionaryCampaignsEnabledForExternalSynchronized.a
dExtensionsForNotExternalForNotReserveCreate.adExtension'
,
'
goalA
dExtensionsForNotExternalForNotReserveCreate.adExtension'
,
]);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$goalAdExtensions
=
$token
->
dictionaryCampaignsEnabledForExternalSynchronized
->
pluck
(
'adExtensionsForNotExternalForNotReserveCreate'
)
->
collapse
();
$goalAdExtensions
=
$token
->
goalAdExtensionsForNotExternalForNotReserveCreate
;
foreach
(
array_chunk
(
$goalAdExtensions
->
pluck
(
'id'
)
->
toArray
(),
1000
)
as
$items
)
{
AdExtension
::
whereIn
(
'id'
,
$items
)
Goal
AdExtension
::
whereIn
(
'id'
,
$items
)
->
update
([
'reserve_create_at'
=>
Carbon
::
now
(),
]);
...
...
app/Console/Commands/AdvertisementsAdd.php
View file @
9753f21
...
...
@@ -59,11 +59,12 @@ class AdvertisementsAdd extends Command
$goalAds
=
DB
::
table
(
'goal_advertisements'
)
->
join
(
'advertisements'
,
'goal_advertisements.advertisement_id'
,
'='
,
'advertisements.id'
)
->
leftJoin
(
'goal_advertisement_goal_ad_extensions'
,
'goal_advertisements.id'
,
'='
,
'goal_advertisement_goal_ad_extensions.goal_advertisement_id'
)
->
leftJoin
(
'goal_ad_extensions'
,
'goal_advertisement
s.id'
,
'='
,
'goal_ad_extensions.goal_ad_extension_
id'
)
->
leftJoin
(
'goal_ad_extensions'
,
'goal_advertisement
_goal_ad_extensions.goal_ad_extension_id'
,
'='
,
'goal_ad_extensions.
id'
)
->
whereNotExists
(
function
(
Builder
$query
)
{
$query
->
select
(
DB
::
raw
(
1
))
->
from
(
'goal_advertisement_goal_ad_extensions'
)
->
join
(
'goal_ad_extensions'
,
'goal_advertisements.id'
,
'='
,
'goal_ad_extensions.goal_ad_extension_id'
)
->
join
(
'goal_ad_extensions'
,
'goal_advertisement_goal_ad_extensions.goal_ad_extension_id'
,
'='
,
'goal_ad_extensions.id'
)
->
whereNull
(
'goal_ad_extensions.external_id'
)
->
whereColumn
(
'goal_advertisements.id'
,
'goal_advertisement_goal_ad_extensions.goal_advertisement_id'
);
})
->
whereNull
(
'advertisements.deleted_at'
)
...
...
app/Console/Commands/DictionaryCampaignsSyncByCampaign.php
View file @
9753f21
...
...
@@ -158,14 +158,16 @@ class DictionaryCampaignsSyncByCampaign extends Command
//грузим связь объевлений к расширения которых по какой то причне нет в целевых.
DB
::
insert
(
"
INSERT INTO goal_advertisement_goal_ad_extensions(goal_advertisement_id, goal_ad_extension_id, created_at, updated_at)
SELECT
ae
.id, gae.id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
SELECT
ga
.id, gae.id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
FROM advertisement_ad_extensions aae
INNER JOIN ad_extensions ae on aae.ad_extension_id = ae.id
INNER JOIN ad_extensions ae on aae.ad_extension_id = ae.id
and ae.deleted_at is null
INNER JOIN goal_ad_extensions gae on ae.id = gae.ad_extension_id
INNER JOIN advertisements a on aae.advertisement_id = a.id
INNER JOIN advertisements a on aae.advertisement_id = a.id
and a.deleted_at is null
INNER JOIN goal_advertisements ga on a.id = ga.advertisement_id
INNER JOIN dictionary_campaigns dc on ga.dictionary_campaign_id = dc.id
INNER JOIN dictionaries d on dc.dictionary_id = d.id and d.token_id = gae.token_id
LEFT JOIN goal_advertisement_goal_ad_extensions gagae on gae.id = gagae.goal_ad_extension_id and ga.id = gagae.goal_advertisement_id
WHERE gagae.ad_extension_id is null
WHERE gagae.
goal_
ad_extension_id is null
"
);
//грузим объявления которых по какой то причне нет в целевых.
...
...
app/Console/Kernel.php
View file @
9753f21
...
...
@@ -2,6 +2,7 @@
namespace
App\Console
;
use
App\Console\Commands\AdExtensionsAdd
;
use
App\Console\Commands\AdExtensionsLoad
;
use
App\Console\Commands\AdGroupsAdd
;
use
App\Console\Commands\AdGroupsLoadUpdated
;
...
...
@@ -64,6 +65,7 @@ class Kernel extends ConsoleKernel
$schedule
->
command
(
AdGroupsLoadKeywords
::
class
)
->
hourlyAt
(
30
);
$schedule
->
command
(
AdExtensionsLoad
::
class
)
->
hourlyAt
(
25
);
$schedule
->
command
(
AdExtensionsAdd
::
class
)
->
hourlyAt
(
30
);
$schedule
->
command
(
AdGroupsAdd
::
class
)
->
hourlyAt
(
30
);
$schedule
->
command
(
AdGroupsUpdate
::
class
)
->
hourlyAt
(
30
);
...
...
app/Models/Pivots/DictionaryCampaign.php
View file @
9753f21
...
...
@@ -486,16 +486,6 @@ class DictionaryCampaign extends Pivot
return
$this
->
hasMany
(
GoalKeywordDelete
::
class
,
'dictionary_campaign_id'
);
}
public
function
adExtensions
()
{
return
$this
->
hasMany
(
GoalAdExtension
::
class
,
'dictionary_campaign_id'
);
}
public
function
adExtensionsForNotExternalForNotReserveCreate
()
{
return
$this
->
adExtensions
()
->
forNotExternal
()
->
forNotReserveCreate
();
}
public
function
goalAdvertisements
()
{
return
$this
->
hasMany
(
GoalAdvertisement
::
class
,
'dictionary_campaign_id'
);
...
...
app/Models/Pivots/GoalAdExtension.php
View file @
9753f21
...
...
@@ -16,6 +16,7 @@ class GoalAdExtension extends Pivot
protected
$fillable
=
[
'external_id'
,
'ad_extension_id'
,
'token_id'
,
'external_upload_at'
,
'external_updated_at'
,
'updated_need'
,
...
...
@@ -39,6 +40,7 @@ class GoalAdExtension extends Pivot
'id'
,
'external_id'
,
'ad_extension_id'
,
'token_id'
,
'external_upload_at'
,
'external_updated_at'
,
'updated_need'
,
...
...
app/Models/Tokens.php
View file @
9753f21
...
...
@@ -3,6 +3,7 @@
namespace
App\Models
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Pivots\GoalAdExtension
;
use
Carbon\Carbon
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Model
;
...
...
@@ -52,6 +53,8 @@ use Illuminate\Database\Eloquent\Model;
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Dictionary[] $campaignsForManaged
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Dictionary[] $campaignsNotForManaged
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Pivots\GoalAdExtension[] $goalAdExtensions
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Pivots\GoalAdExtension[] $goalAdExtensionsForNotExternalForNotReserveCreate
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Limits[] $limits
* @property-read int|null $limits_count
* @property string|null $timestamp
...
...
@@ -254,4 +257,15 @@ class Tokens extends Model
{
return
$this
->
campaigns
()
->
forManaged
(
false
);
}
public
function
goalAdExtensions
()
{
return
$this
->
hasMany
(
GoalAdExtension
::
class
,
'token_id'
);
}
public
function
goalAdExtensionsForNotExternalForNotReserveCreate
()
{
return
$this
->
goalAdExtensions
()
->
forNotExternal
()
->
forNotReserveCreate
();
}
}
app/Service/Requests/Direct/AddAdExtensions.php
View file @
9753f21
...
...
@@ -88,7 +88,7 @@ class AddAdExtensions extends DirectRequest
public
function
failed
()
{
GoalAd
Group
::
whereIn
(
'id'
,
$this
->
goalAdExtensions
->
pluck
(
'id'
)
->
toArray
())
GoalAd
Extension
::
whereIn
(
'id'
,
$this
->
goalAdExtensions
->
pluck
(
'id'
)
->
toArray
())
->
update
([
'reserve_create_at'
=>
null
,
]);
...
...
@@ -113,7 +113,7 @@ class AddAdExtensions extends DirectRequest
$this
->
setParams
([
'AdExtensions'
=>
$this
->
goalAdExtensions
->
map
(
function
(
GoalAdExtension
$goalAdExtension
)
use
(
$variables
,
&
$lists
)
{
if
(
!
isset
(
$lists
[
$goalAd
Group
->
dictionary_campaign_id
]))
{
if
(
!
isset
(
$lists
[
$goalAd
Extension
->
dictionary_campaign_id
]))
{
$list
=
Variable
::
getListVariablesByDictionaryCampaign
(
$goalAdExtension
->
dictionary_campaign_id
,
$variables
);
$lists
[
$goalAdExtension
->
dictionary_campaign_id
]
=
$list
;
}
else
{
...
...
app/Service/Requests/Direct/GetAdExtensions.php
View file @
9753f21
...
...
@@ -57,7 +57,6 @@ class GetAdExtensions extends DirectRequest
'external_id'
=>
$external_id
,
'callout_text'
=>
$ad_extension
[
'Callout'
][
'CalloutText'
],
'associated'
=>
$ad_extension
[
'Associated'
]
===
'YES'
,
'state'
=>
$ad_extension
[
'State'
],
'status'
=>
$ad_extension
[
'Status'
],
'status_clarification'
=>
$ad_extension
[
'StatusClarification'
],
];
...
...
@@ -94,6 +93,9 @@ class GetAdExtensions extends DirectRequest
"Types"
=>
[
AdExtension
::
TYPE_CALLOUT
,
],
"States"
=>
[
AdExtension
::
STATE_ON
,
],
],
"FieldNames"
=>
[
"Id"
,
"Type"
,
"Status"
,
...
...
database/migrations/2021_07_05_103552_add_goal_ad_extensions_reserve_column.php
0 → 100644
View file @
9753f21
<?php
use
Illuminate\Database\Migrations\Migration
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
class
AddGoalAdExtensionsReserveColumn
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
table
(
'goal_ad_extensions'
,
function
(
Blueprint
$table
)
{
$table
->
timestamp
(
'reserve_create_at'
)
->
nullable
();
$table
->
timestamp
(
'reserve_update_at'
)
->
nullable
();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
//
}
}
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