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 c938fbf8
authored
Aug 10, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#20695 Отключение объявлений.
1 parent
f544823d
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
46 additions
and
46 deletions
app/Console/Commands/AdvertisementsAdd.php
app/Console/Commands/AdvertisementsArchive.php
app/Console/Commands/AdvertisementsCheckArchive.php
app/Console/Commands/DictionaryCampaignsSyncByCampaign.php
app/Console/Kernel.php
app/Models/Advertisement.php
app/Models/Pivots/GoalAdGroup.php
app/Models/Pivots/GoalAdvertisement.php
app/Service/Requests/Direct/ArchiveAds.php
app/Service/Requests/Direct/GetAds.php
database/migrations/2021_08_09_140729_add_advertisements_archive_column.php
app/Console/Commands/AdvertisementsAdd.php
View file @
c938fbf
...
...
@@ -55,8 +55,8 @@ class AdvertisementsAdd extends Command
->
leftJoin
(
'goal_ad_extensions'
,
'goal_advertisement_goal_ad_extensions.goal_ad_extension_id'
,
'='
,
'goal_ad_extensions.id'
)
->
leftJoin
(
'ad_images'
,
'advertisements.ad_image_hash'
,
'='
,
'ad_images.hash'
)
->
leftJoin
(
'goal_ad_images'
,
function
(
$join
)
use
(
$token
)
{
$join
->
on
(
'goal_ad_images.ad_image_id'
,
'='
,
'ad_images.id'
)
;
$join
->
on
(
'goal_ad_images.token_id'
,
'='
,
$token
->
id
);
$join
->
on
(
'goal_ad_images.ad_image_id'
,
'='
,
'ad_images.id'
)
->
where
(
'goal_ad_images.token_id'
,
'='
,
$token
->
id
);
})
->
whereNotExists
(
function
(
Builder
$query
)
{
$query
->
select
(
DB
::
raw
(
1
))
...
...
app/Console/Commands/AdvertisementsArchive.php
View file @
c938fbf
...
...
@@ -8,7 +8,6 @@ use App\Models\Tokens;
use
App\Service\Requests\Direct\ArchiveAds
;
use
Carbon\Carbon
;
use
Illuminate\Console\Command
;
use
Illuminate\Database\Eloquent\Builder
;
class
AdvertisementsArchive
extends
Command
{
...
...
@@ -43,19 +42,18 @@ class AdvertisementsArchive extends Command
*/
public
function
handle
()
{
$token
=
Tokens
::
has
(
'goalAdvertisementsForNeedArchivedForNotReserveArchiveForNotArchived'
)
->
firstWhere
(
'type'
,
'!='
,
Tokens
::
MAIN
);
$token
=
Tokens
::
firstWhere
(
'type'
,
'!='
,
Tokens
::
MAIN
);
if
(
$token
)
{
$this
->
sendRequest
(
$token
,
Advertisement
::
forNotArchived
()
->
n
otN
eedArchived
()
->
forNotReserveArchive
()
->
get
());
$this
->
sendRequest
(
$token
,
Advertisement
::
forNotArchived
()
->
needArchived
()
->
forNotReserveArchive
()
->
get
());
}
$tokens
=
Tokens
::
has
(
'dictionaryCampaignsEnabledForExternalSynchronized.goalAdvertisementsForNeedArchivedForNotReserveArchiveForNotArchived'
)
->
where
(
'type'
,
Tokens
::
MAIN
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
foreach
(
$tokens
as
$token
)
{
$this
->
sendRequest
(
$token
,
$token
->
dictionaryCampaignsEnabledForExternalSynchronized
->
pluck
(
'goalAdvertisementsForNeedArchivedForNotReserveArchiveForNotArchived'
));
$this
->
sendRequest
(
$token
,
$token
->
dictionaryCampaignsEnabledForExternalSynchronized
->
pluck
(
'goalAdvertisementsForNeedArchivedForNotReserveArchiveForNotArchived'
)
->
collapse
()
);
}
return
0
;
...
...
@@ -82,7 +80,6 @@ class AdvertisementsArchive extends Command
}
}
$request
=
new
ArchiveAds
();
$request
->
setToken
(
$token
)
->
call
([
...
...
app/Console/Commands/AdvertisementsCheckArchive.php
View file @
c938fbf
...
...
@@ -5,6 +5,7 @@ namespace App\Console\Commands;
use
App\Models\Advertisement
;
use
App\Models\Tokens
;
use
App\Service\Requests\Direct\GetAds
;
use
Carbon\Carbon
;
use
Illuminate\Console\Command
;
use
Illuminate\Database\Eloquent\Builder
;
...
...
@@ -41,26 +42,19 @@ class AdvertisementsCheckArchive extends Command
*/
public
function
handle
()
{
$advertisements
=
Advertisement
::
forNotArchived
()
->
notNeedArchived
()
->
get
();
/* @var Advertisement[] $advertisements */
$advertisements
=
Advertisement
::
forArchived
()
->
get
();
if
(
$advertisements
->
count
())
{
$token
=
Tokens
::
where
(
'type'
,
Tokens
::
MAIN
)
->
first
();
if
(
!
$token
)
{
throw
new
\Exception
(
'Не найден токен блин'
);
foreach
(
$advertisements
as
$advertisement
)
{
$advertisement
->
goalAdvertisements
()
->
notNeedArchived
()
->
update
([
'archived_need'
=>
Carbon
::
now
(),
]);
}
$ids
=
$advertisements
->
pluck
(
'external_id'
)
->
toArray
();
$request
=
new
GetAds
();
$request
->
setToken
(
$token
)
->
call
([
'Ids'
=>
$ids
,
'States'
=>
[
Advertisement
::
STATE_ARCHIVED
,
],
]);
}
return
0
;
...
...
app/Console/Commands/DictionaryCampaignsSyncByCampaign.php
View file @
c938fbf
...
...
@@ -221,7 +221,7 @@ class DictionaryCampaignsSyncByCampaign extends Command
LEFT JOIN goal_v_cards gvc on vc.id = gvc.v_card_id and gag.dictionary_campaign_id = gvc.dictionary_campaign_id
LEFT JOIN sitelinks s on ad.sitelink_external_id = s.external_id
LEFT JOIN goal_sitelinks gs on s.id = gs.sitelink_id and gs.token_id = d.token_id
WHERE gad.advertisement_id is null and ad.
archive_at is not and ad.archived_need is not
and ad.campaign_id is not null
WHERE gad.advertisement_id is null and ad.
state != '"
.
Advertisement
::
STATE_ARCHIVED
.
"}' and ad.archived_need is null
and ad.campaign_id is not null
and (ad.sitelink_external_id is null or (ad.sitelink_external_id is not null and s.id is not null))
and (ad.v_card_external_id is null or (ad.v_card_external_id is not null and vc.id is not null))
"
);
...
...
app/Console/Kernel.php
View file @
c938fbf
...
...
@@ -10,6 +10,7 @@ use App\Console\Commands\AdGroupsUpdate;
use
App\Console\Commands\AdImagesAdd
;
use
App\Console\Commands\AdImagesLoad
;
use
App\Console\Commands\AdvertisementsAdd
;
use
App\Console\Commands\AdvertisementsArchive
;
use
App\Console\Commands\AdvertisementsLoadUpdated
;
use
App\Console\Commands\AdvertisementsUpdate
;
use
App\Console\Commands\AudienceTargetsAdd
;
...
...
@@ -117,6 +118,7 @@ class Kernel extends ConsoleKernel
$schedule
->
command
(
AdvertisementsAdd
::
class
)
->
hourlyAt
(
50
);
$schedule
->
command
(
AdvertisementsUpdate
::
class
)
->
hourlyAt
(
50
);
$schedule
->
command
(
AdvertisementsArchive
::
class
)
->
hourlyAt
(
50
);
$schedule
->
call
(
function
()
{
$items
=
new
\FilesystemIterator
(
config
(
'clockwork.storage_files_path'
));
...
...
app/Models/Advertisement.php
View file @
c938fbf
...
...
@@ -101,7 +101,6 @@ class Advertisement extends Model
'updated_self'
,
'archived_need'
,
'reserve_archive_at'
,
'archive_at'
,
];
protected
$casts
=
[
...
...
@@ -118,7 +117,6 @@ class Advertisement extends Model
'prefer_v_card_over_business'
=>
'boolean'
,
'archived_need'
=>
'datetime'
,
'reserve_archive_at'
=>
'datetime'
,
'archive_at'
=>
'datetime'
,
];
/**
...
...
@@ -161,7 +159,7 @@ class Advertisement extends Model
*/
public
function
scopeForArchived
(
$query
)
{
return
$query
->
where
NotNull
(
'archive_at'
);
return
$query
->
where
(
'state'
,
Advertisement
::
STATE_ARCHIVED
);
}
/**
...
...
@@ -170,7 +168,7 @@ class Advertisement extends Model
*/
public
function
scopeForNotArchived
(
$query
)
{
return
$query
->
where
Null
(
'archive_at'
);
return
$query
->
where
(
'state'
,
'!=='
,
Advertisement
::
STATE_ARCHIVED
);
}
/**
...
...
app/Models/Pivots/GoalAdGroup.php
View file @
c938fbf
...
...
@@ -247,7 +247,7 @@ class GoalAdGroup extends Pivot
public
function
goalAudienceTargets
()
{
return
$this
->
hasMany
(
GoalAudienceTarget
::
class
,
'ad_group_id'
);
return
$this
->
hasMany
(
GoalAudienceTarget
::
class
,
'
goal_
ad_group_id'
);
}
}
app/Models/Pivots/GoalAdvertisement.php
View file @
c938fbf
...
...
@@ -34,6 +34,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @method static Builder|GoalAdvertisement forNotReserveArchive()
* @method static Builder|GoalAdvertisement needUpdated()
* @method static Builder|GoalAdvertisement needArchived()
* @method static Builder|GoalAdvertisement notNeedArchived()
* @method static Builder|GoalAdvertisement newModelQuery()
* @method static Builder|GoalAdvertisement newQuery()
* @method static Builder|GoalAdvertisement query()
...
...
@@ -192,6 +193,15 @@ class GoalAdvertisement extends Pivot
* @param Builder $query
* @return Builder
*/
public
function
scopeNotNeedArchived
(
$query
)
{
return
$query
->
whereNull
(
'archived_need'
);
}
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeForNotReserveArchive
(
$query
)
{
return
$query
->
whereNull
(
'reserve_archive_at'
);
...
...
app/Service/Requests/Direct/ArchiveAds.php
View file @
c938fbf
...
...
@@ -25,12 +25,12 @@ class ArchiveAds extends DirectRequest
public
function
getObjectsCount
()
{
return
count
(
$this
->
getParams
()[
'SelectionCriteria'
][
'
A
ds'
]);
return
count
(
$this
->
getParams
()[
'SelectionCriteria'
][
'
I
ds'
]);
}
public
function
slice
(
$maxObjects
)
:
?
APIRequest
{
return
$this
->
sliceByKey
(
$maxObjects
,
'Ads'
);;
return
$this
->
sliceByKey
(
$maxObjects
,
[
'SelectionCriteria'
,
'Ids'
]
);;
}
public
function
handle
(
$response
)
...
...
@@ -44,15 +44,15 @@ class ArchiveAds extends DirectRequest
if
(
!
isset
(
$archive_result
[
'Id'
]))
{
Log
::
debug
(
"ArchiveAds, empty Id"
);
Log
::
debug
(
$archive_result
);
Log
::
debug
(
$this
->
getParams
()[
'
A
ds'
][
$key
]);
Log
::
debug
(
$this
->
getParams
()[
'
SelectionCriteria'
][
'I
ds'
][
$key
]);
if
(
$this
->
getToken
()
->
isMain
())
{
Advertisement
::
whereExternalId
(
$this
->
getParams
()[
'SelectionCriteria'
][
'
Ads'
][
'
Ids'
][
$key
])
Advertisement
::
whereExternalId
(
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
][
$key
])
->
update
([
'reserve_archive_at'
=>
null
,
]);
}
else
{
GoalAdvertisement
::
whereExternalId
(
$this
->
getParams
()[
'SelectionCriteria'
][
'
Ads'
][
'
Ids'
][
$key
])
GoalAdvertisement
::
whereExternalId
(
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
][
$key
])
->
update
([
'reserve_archive_at'
=>
null
,
]);
...
...
@@ -67,7 +67,8 @@ class ArchiveAds extends DirectRequest
Advertisement
::
needArchived
()
->
where
(
'external_id'
,
$external_id
)
->
update
([
'archive_at'
=>
Carbon
::
now
(),
'state'
=>
Advertisement
::
STATE_ARCHIVED
,
'status_clarification'
=>
'Archived.'
,
'archived_need'
=>
null
,
'reserve_archive_at'
=>
null
,
]);
...
...
@@ -92,12 +93,12 @@ class ArchiveAds extends DirectRequest
public
function
failed
()
{
if
(
$this
->
getToken
()
->
isMain
())
{
Advertisement
::
whereIn
(
'external_id'
,
$this
->
getParams
()[
'SelectionCriteria'
][
'
Ads'
][
'
Ids'
])
Advertisement
::
whereIn
(
'external_id'
,
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
])
->
update
([
'reserve_archive_at'
=>
null
,
]);
}
else
{
GoalAdvertisement
::
whereIn
(
'external_id'
,
$this
->
getParams
()[
'SelectionCriteria'
][
'
Ads'
][
'
Ids'
])
GoalAdvertisement
::
whereIn
(
'external_id'
,
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
])
->
update
([
'reserve_archive_at'
=>
null
,
]);
...
...
app/Service/Requests/Direct/GetAds.php
View file @
c938fbf
...
...
@@ -111,9 +111,6 @@ class GetAds extends DirectRequest
'sub_type'
=>
$ad
[
'Subtype'
],
'updated_self'
=>
null
,
'archived_need'
=>
$ad
[
'State'
]
===
Advertisement
::
STATE_ARCHIVED
?
Carbon
::
now
()
:
null
,
];
if
(
isset
(
$ad
[
'TextAd'
]))
{
...
...
@@ -164,10 +161,12 @@ class GetAds extends DirectRequest
'external_id'
=>
$external_id
],
$data
);
if
(
$advertisement
->
archived_need
)
{
$advertisement
->
goalAdvertisements
()
->
update
([
'archived_need'
=>
Carbon
::
now
(),
]);
if
(
$advertisement
->
state
===
Advertisement
::
STATE_ARCHIVED
)
{
$advertisement
->
goalAdvertisements
()
->
notNeedArchived
()
->
update
([
'archived_need'
=>
Carbon
::
now
(),
]);
}
$adExtensions_sync
=
$advertisement
->
adExtensions
()
->
sync
(
$ad_extensions
->
pluck
(
'id'
));
...
...
database/migrations/2021_08_09_140729_add_advertisements_archive_column.php
View file @
c938fbf
...
...
@@ -14,7 +14,6 @@ class AddAdvertisementsArchiveColumn extends Migration
public
function
up
()
{
Schema
::
table
(
'advertisements'
,
function
(
Blueprint
$table
)
{
$table
->
timestamp
(
'archive_at'
)
->
nullable
();
$table
->
timestamp
(
'archived_need'
)
->
nullable
();
$table
->
timestamp
(
'reserve_archive_at'
)
->
nullable
();
});
...
...
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