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 886c1fd3
authored
Jul 02, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#20364 Загрузка и синхронизация расширений
1 parent
e9f07f96
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
191 additions
and
8 deletions
app/Console/Commands/AdExtensionsAdd.php
app/Console/Commands/AdvertisementsAdd.php
app/Console/Commands/CampaignsFirstLoad.php
app/Models/Advertisement.php
app/Models/Pivots/AdvertisementAdExtension.php
app/Models/Pivots/GoalAdvertisement.php
app/Models/Pivots/GoalAdvertisementGoalAdExtension.php
app/Service/Requests/Direct/GetAdExtensions.php
app/Service/Requests/Direct/GetAds.php
app/Console/Commands/AdExtensionsAdd.php
0 → 100644
View file @
886c1fd
<?php
namespace
App\Console\Commands
;
use
App\Models\Campaigns
;
use
App\Models\Tokens
;
use
App\Service\API\API
;
use
App\Service\Requests\APIRequest
;
use
Illuminate\Console\Command
;
class
AdExtensionsAdd
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'adextensions:add'
;
/**
* 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
* @throws \Exception
*/
public
function
handle
()
{
$token
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
if
(
!
$token
)
{
throw
new
\Exception
(
'Не найден токен блин'
);
}
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'AdExtensions'
,
'get'
)
->
call
([
'ModifiedSince'
=>
$token
->
check_changes_ad_extension
,
]);
return
0
;
}
}
app/Console/Commands/AdvertisementsAdd.php
View file @
886c1fd
...
...
@@ -10,6 +10,7 @@ use Carbon\Carbon;
use
Illuminate\Console\Command
;
use
Illuminate\Database\Eloquent\Relations\HasMany
;
use
Illuminate\Database\Eloquent\Relations\HasManyThrough
;
use
Illuminate\Database\Query\Builder
;
use
Illuminate\Support\Facades\DB
;
class
AdvertisementsAdd
extends
Command
...
...
@@ -46,11 +47,10 @@ class AdvertisementsAdd extends Command
public
function
handle
()
{
$tokens
=
Tokens
::
has
(
'dictionaryCampaignsEnabledForExternalSynchronized.goalAdvertisementsForNotExternalForNotReserveCreate.advertisement'
)
->
whereDoesntHave
(
'dictionaryCampaignsEnabledForExternalSynchronized.goalAdvertisementsForNotExternalForNotReserveCreate.goalAdExtensionsForNotExternal'
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
dd
(
$tokens
);
foreach
(
$tokens
as
$token
)
{
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
...
...
@@ -60,6 +60,12 @@ class AdvertisementsAdd extends Command
->
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_advertisements.id'
,
'='
,
'goal_ad_extensions.goal_ad_extension_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'
)
->
whereColumn
(
'goal_advertisements.id'
,
'goal_advertisement_goal_ad_extensions.goal_advertisement_id'
);
})
->
whereNull
(
'advertisements.deleted_at'
)
->
whereNull
(
'goal_advertisements.external_id'
)
->
whereNull
(
'goal_advertisements.reserve_create_at'
)
...
...
@@ -79,7 +85,7 @@ class AdvertisementsAdd extends Command
'advertisements.v_card_id as v_card_id'
,
'advertisements.ad_image_hash as ad_image_hash'
,
'advertisements.site_link_set_id as site_link_set_id'
,
DB
::
raw
(
'JSON_
OBJECT
AGG(goal_ad_extensions.external_id) as ad_extension_ids'
),
DB
::
raw
(
'JSON_
ARRAY
AGG(goal_ad_extensions.external_id) as ad_extension_ids'
),
'advertisements.ad_extensions as ad_extensions'
,
'advertisements.video_extension as video_extension'
,
'advertisements.price_extension as price_extension'
,
...
...
@@ -87,6 +93,7 @@ class AdvertisementsAdd extends Command
'advertisements.business_id as business_id'
,
'advertisements.prefer_v_card_over_business as prefer_v_card_over_business'
,
])
->
groupBy
(
'goal_advertisements.id'
)
->
get
();
foreach
(
array_chunk
(
$goalAds
->
pluck
(
'id'
)
->
toArray
(),
1000
)
as
$items
)
{
...
...
app/Console/Commands/CampaignsFirstLoad.php
View file @
886c1fd
...
...
@@ -53,6 +53,7 @@ class CampaignsFirstLoad extends Command
Artisan
::
call
(
DictionariesLoad
::
class
);
Artisan
::
call
(
CampaignsLoadGroups
::
class
);
Artisan
::
call
(
AdGroupsLoadKeywords
::
class
);
Artisan
::
call
(
AdExtensionsLoad
::
class
);
Artisan
::
call
(
CampaignsLoadAds
::
class
);
Artisan
::
call
(
CampaignsLoadBidModifiers
::
class
);
...
...
app/Models/Advertisement.php
View file @
886c1fd
...
...
@@ -2,6 +2,7 @@
namespace
App\Models
;
use
App\Models\Pivots\AdvertisementAdExtension
;
use
App\Models\Pivots\GoalAdvertisement
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Model
;
...
...
@@ -168,4 +169,12 @@ class Advertisement extends Model
return
$this
->
hasMany
(
GoalAdvertisement
::
class
,
'advertisement_id'
);
}
public
function
adExtensions
()
{
return
$this
->
belongsToMany
(
AdExtension
::
class
,
AdvertisementAdExtension
::
getModel
()
->
getTable
(),
'advertisement_id'
,
'ad_extension_id'
)
->
using
(
AdvertisementAdExtension
::
class
)
->
withPivot
(
AdvertisementAdExtension
::
getWithPivot
())
->
withTimestamps
();
}
}
app/Models/Pivots/AdvertisementAdExtension.php
0 → 100644
View file @
886c1fd
<?php
namespace
App\Models\Pivots
;
use
App\Models\AdExtension
;
use
App\Models\Advertisement
;
use
Illuminate\Database\Eloquent\Relations\Pivot
;
class
AdvertisementAdExtension
extends
Pivot
{
protected
$table
=
'advertisement_ad_extensions'
;
protected
$fillable
=
[
'advertisement_id'
,
'ad_extension_id'
,
];
public
$incrementing
=
true
;
static
public
function
getWithPivot
()
{
return
[
'id'
,
'advertisement_id'
,
'ad_extension_id'
,
];
}
public
function
Advertisement
()
{
return
$this
->
belongsTo
(
Advertisement
::
class
,
'advertisement_id'
);
}
public
function
adExtension
()
{
return
$this
->
belongsTo
(
AdExtension
::
class
,
'ad_extension_id'
);
}
}
app/Models/Pivots/GoalAdvertisement.php
View file @
886c1fd
...
...
@@ -148,4 +148,17 @@ class GoalAdvertisement extends Pivot
return
$this
->
belongsTo
(
DictionaryCampaign
::
class
,
'dictionary_campaign_id'
);
}
public
function
goalAdExtensions
()
{
return
$this
->
belongsToMany
(
GoalAdExtension
::
class
,
GoalAdvertisementGoalAdExtension
::
getModel
()
->
getTable
(),
'goal_advertisement_id'
,
'goal_ad_extension_id'
)
->
using
(
GoalAdvertisementGoalAdExtension
::
class
)
->
withPivot
(
GoalAdvertisementGoalAdExtension
::
getWithPivot
())
->
withTimestamps
();
}
public
function
goalAdExtensionsForNotExternal
()
{
return
$this
->
goalAdExtensions
()
->
forNotExternal
();
}
}
app/Models/Pivots/GoalAdvertisementGoalAdExtension.php
0 → 100644
View file @
886c1fd
<?php
namespace
App\Models\Pivots
;
use
App\Models\AdExtension
;
use
App\Models\Advertisement
;
use
Illuminate\Database\Eloquent\Relations\Pivot
;
class
GoalAdvertisementGoalAdExtension
extends
Pivot
{
protected
$table
=
'goal_advertisement_goal_ad_extensions'
;
protected
$fillable
=
[
'goal_advertisement_id'
,
'goal_ad_extension_id'
,
];
public
$incrementing
=
true
;
static
public
function
getWithPivot
()
{
return
[
'id'
,
'goal_advertisement_id'
,
'goal_ad_extension_id'
,
];
}
public
function
GoalAdvertisement
()
{
return
$this
->
belongsTo
(
GoalAdvertisement
::
class
,
'goal_advertisement_id'
);
}
public
function
adExtension
()
{
return
$this
->
belongsTo
(
GoalAdExtension
::
class
,
'goal_ad_extension_id'
);
}
}
app/Service/Requests/Direct/GetAdExtensions.php
View file @
886c1fd
...
...
@@ -46,7 +46,6 @@ class GetAdExtensions extends DirectRequest
function
handle
(
$response
)
{
try
{
dd
(
$response
);
if
(
isset
(
$response
[
'result'
][
'AdExtensions'
]))
{
foreach
(
$response
[
'result'
][
'AdExtensions'
]
as
$ad_extension
)
{
...
...
app/Service/Requests/Direct/GetAds.php
View file @
886c1fd
...
...
@@ -3,6 +3,7 @@
namespace
App\Service\Requests\Direct
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\AdExtension
;
use
App\Models\AdGroup
;
use
App\Models\Advertisement
;
use
App\Service\Contract\APIRequest
;
...
...
@@ -92,6 +93,8 @@ class GetAds extends DirectRequest
if
(
$this
->
getToken
()
->
isMain
())
{
$ad_extensions
=
collect
();
$data
=
[
'external_id'
=>
$external_id
,
'campaign_external_id'
=>
$ad_group
->
campaign
->
external_id
,
...
...
@@ -126,7 +129,6 @@ class GetAds extends DirectRequest
'v_card_moderation'
=>
$ad
[
'TextAd'
][
'VCardModeration'
],
'site_links_moderation'
=>
$ad
[
'TextAd'
][
'SitelinksModeration'
],
'ad_image_moderation'
=>
$ad
[
'TextAd'
][
'AdImageModeration'
],
'ad_extensions'
=>
$ad
[
'TextAd'
][
'AdExtensions'
],
'video_extension'
=>
$ad
[
'TextAd'
][
'VideoExtension'
],
'price_extension'
=>
$ad
[
'TextAd'
][
'PriceExtension'
],
'turbo_page_id'
=>
$ad
[
'TextAd'
][
'TurboPageId'
],
...
...
@@ -135,19 +137,32 @@ class GetAds extends DirectRequest
'prefer_v_card_over_business'
=>
isset
(
$ad
[
'TextAd'
][
'PreferVCardOverBusiness'
])
?
$ad
[
'TextAd'
][
'PreferVCardOverBusiness'
]
===
'YES'
:
null
,
]);
$ad_extensions_array
=
[];
foreach
(
$ad
[
'TextAd'
][
'AdExtensions'
]
as
$ad_extensions_data
)
{
/*
* TODO: #20364 Загрузка и синхронизация расширений
*/
$ad_extension_external_id
=
(
string
)
$ad_extensions_data
[
'AdExtensionId'
];
$ad_extension
=
AdExtension
::
firstWhere
(
'external_id'
,
$ad_extension_external_id
);
if
(
!
$ad_extension
)
{
$ad_extensions_array
[]
=
$ad_extensions_data
;
continue
;
}
$ad_extensions
->
push
(
$ad_extension
);
}
$data
[
'ad_extensions'
]
=
$ad_extensions_array
;
}
$advertisement
=
Advertisement
::
updateOrCreate
([
'external_id'
=>
$external_id
],
$data
);
$advertisement
->
adExtensions
()
->
sync
(
$ad_extensions
->
pluck
(
'id'
));
if
(
$advertisement
->
wasRecentlyCreated
)
{
$campaign_ids_synced_need
[
$advertisement
->
campaign_id
]
=
true
;
}
elseif
(
$advertisement
->
wasChanged
([
'campaign_id'
]))
{
...
...
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