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 76d05e25
authored
Sep 22, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#20794 Сделать чтобы в целевых РК оставалась одна карточка (Удаление объявлений)
1 parent
df9dfe11
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
63 deletions
app/Models/Advertisement.php
app/Models/Campaigns.php
app/Service/Requests/Direct/ArchiveAds.php
app/Service/Requests/Direct/GetAds.php
database/migrations/2021_09_22_112540_add_ads_loaded_at_column.php
app/Models/Advertisement.php
View file @
76d05e2
...
...
@@ -103,6 +103,8 @@ class Advertisement extends Model
'reserve_archive_at'
,
'deleted_need'
,
'reserve_delete_at'
,
'deleted_at'
,
];
protected
$casts
=
[
...
...
app/Models/Campaigns.php
View file @
76d05e2
...
...
@@ -35,6 +35,7 @@ use Illuminate\Support\Collection;
* @property bool $manage
* @property bool $enabled
* @property \Illuminate\Support\Carbon|null $groups_loaded_at
* @property \Illuminate\Support\Carbon|null $ads_loaded_at
* @property \Illuminate\Support\Carbon|null $bid_modifiers_loaded_at
* @property \Illuminate\Support\Carbon|null $disabled_at
* @property \Illuminate\Support\Carbon|null $created_at
...
...
@@ -113,6 +114,7 @@ class Campaigns extends Model
'attribution_model'
,
'priority_goals'
,
'groups_loaded_at'
,
'ads_loaded_at'
,
'bid_modifiers_loaded_at'
,
'updated_self'
,
'updated_children'
,
...
...
@@ -133,6 +135,7 @@ class Campaigns extends Model
'daily_budget'
=>
'array'
,
'priority_goals'
=>
'array'
,
'groups_loaded_at'
=>
'datetime'
,
'ads_loaded_at'
=>
'datetime'
,
'bid_modifiers_loaded_at'
=>
'datetime'
,
'updated_self'
=>
'datetime'
,
'updated_children'
=>
'datetime'
,
...
...
app/Service/Requests/Direct/ArchiveAds.php
View file @
76d05e2
...
...
@@ -6,6 +6,7 @@ use App\Jobs\ProcessCallLimitedAPI;
use
App\Models\Advertisement
;
use
App\Models\Pivots\GoalAdvertisement
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Log
;
...
...
@@ -39,91 +40,88 @@ class ArchiveAds extends DirectRequest
return
;
}
foreach
(
DirectResponseHelper
::
getExternalIdsChunkByResult
(
$response
[
'result'
][
'ArchiveResults'
])
as
$external_ids
)
{
if
(
$this
->
getToken
()
->
isMain
())
{
Advertisement
::
whereIn
(
'external_id'
,
$external_ids
)
->
update
([
'state'
=>
Advertisement
::
STATE_ARCHIVED
,
'status_clarification'
=>
'Archived.'
,
'archived_need'
=>
null
,
'reserve_archive_at'
=>
null
,
]);
}
else
{
GoalAdvertisement
::
whereIn
(
'external_id'
,
$external_ids
)
->
update
([
'archive_at'
=>
Carbon
::
now
(),
'archived_need'
=>
null
,
'reserve_archive_at'
=>
null
,
]);
}
}
foreach
(
$response
[
'result'
][
'ArchiveResults'
]
as
$key
=>
$archive_result
)
{
if
(
!
isset
(
$archive_result
[
'Id'
]))
{
$external_id
=
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
][
$key
];
/*
* array (
* 0 =>
* array (
* 'Code' => 8300,
* 'Message' => 'Invalid object status',
* 'Details' => 'Ad is a draft and cannot be archived',
* ),
* )
*/
if
(
isset
(
$archive_result
[
'Errors'
][
0
][
'Code'
])
==
8300
)
{
if
(
$this
->
getToken
()
->
isMain
())
{
Advertisement
::
whereExternalId
(
$external_id
)
->
update
([
'deleted_need'
=>
Carbon
::
now
(),
'archived_need'
=>
null
,
'reserve_archive_at'
=>
null
,
]);
}
else
{
GoalAdvertisement
::
whereExternalId
(
$external_id
)
->
update
([
'deleted_need'
=>
Carbon
::
now
(),
'archived_need'
=>
null
,
'reserve_archive_at'
=>
null
,
]);
}
}
elseif
(
isset
(
$archive_result
[
'Errors'
])
&&
count
(
$archive_result
[
'Errors'
]))
{
if
(
$this
->
getToken
()
->
isMain
())
{
$model
=
Advertisement
::
whereExternalId
(
$external_id
)
->
first
();
}
else
{
$model
=
GoalAdvertisement
::
whereExternalId
(
$external_id
)
->
first
();
}
if
(
$model
)
{
$model
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$external_id
,
'errors'
=>
$archive_result
[
'Errors'
],
]);
}
}
else
{
Log
::
debug
(
"ArchiveAds, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$archive_result
);
Log
::
debug
(
$external_id
);
}
if
(
isset
(
$archive_result
[
'Id'
]))
{
continue
;
}
$external_id
=
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
][
$key
];
/*
* array (
* 0 =>
* array (
* 'Code' => 8300,
* 'Message' => 'Invalid object status',
* 'Details' => 'Ad is a draft and cannot be archived',
* ),
* )
*/
if
(
isset
(
$archive_result
[
'Errors'
][
0
][
'Code'
])
==
8300
)
{
if
(
$this
->
getToken
()
->
isMain
())
{
Advertisement
::
whereExternalId
(
$external_id
)
->
update
([
'deleted_need'
=>
Carbon
::
now
(),
'archived_need'
=>
null
,
'reserve_archive_at'
=>
null
,
]);
}
else
{
GoalAdvertisement
::
whereExternalId
(
$external_id
)
->
update
([
'deleted_need'
=>
Carbon
::
now
(),
'archived_need'
=>
null
,
'reserve_archive_at'
=>
null
,
]);
}
}
elseif
(
isset
(
$archive_result
[
'Errors'
])
&&
count
(
$archive_result
[
'Errors'
]))
{
if
(
$this
->
getToken
()
->
isMain
())
{
$model
=
Advertisement
::
whereExternalId
(
$external_id
)
->
first
();
}
else
{
$model
=
GoalAdvertisement
::
whereExternalId
(
$external_id
)
->
first
();
}
continue
;
if
(
$model
)
{
$model
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$external_id
,
'errors'
=>
$archive_result
[
'Errors'
],
]);
}
}
else
{
Log
::
debug
(
"ArchiveAds, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$archive_result
);
Log
::
debug
(
$external_id
);
}
$external_id
=
(
string
)
$archive_result
[
'Id'
];
if
(
$this
->
getToken
()
->
isMain
())
{
Advertisement
::
needArchived
()
->
where
(
'external_id'
,
$external_id
)
Advertisement
::
whereExternalId
(
$external_id
)
->
update
([
'state'
=>
Advertisement
::
STATE_ARCHIVED
,
'status_clarification'
=>
'Archived.'
,
'archived_need'
=>
null
,
'reserve_archive_at'
=>
null
,
]);
}
else
{
GoalAdvertisement
::
forExternal
()
->
needArchived
()
->
where
(
'external_id'
,
$external_id
)
GoalAdvertisement
::
whereExternalId
(
$external_id
)
->
update
([
'archive_at'
=>
Carbon
::
now
(),
'archived_need'
=>
null
,
'reserve_archive_at'
=>
null
,
]);
}
...
...
app/Service/Requests/Direct/GetAds.php
View file @
76d05e2
...
...
@@ -6,9 +6,11 @@ use App\Jobs\ProcessCallLimitedAPI;
use
App\Models\AdExtension
;
use
App\Models\AdGroup
;
use
App\Models\Advertisement
;
use
App\Models\Campaigns
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Requests\DirectRequest
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\DB
;
class
GetAds
extends
DirectRequest
{
...
...
@@ -127,6 +129,7 @@ class GetAds extends DirectRequest
'turbo_page_moderation'
=>
$ad
[
'TextAd'
][
'TurboPageModeration'
],
'business_id'
=>
$ad
[
'TextAd'
][
'BusinessId'
],
'prefer_v_card_over_business'
=>
isset
(
$ad
[
'TextAd'
][
'PreferVCardOverBusiness'
])
?
$ad
[
'TextAd'
][
'PreferVCardOverBusiness'
]
===
'YES'
:
null
,
'deleted_at'
=>
null
,
]);
$ad_extensions_array
=
[];
...
...
@@ -187,6 +190,31 @@ class GetAds extends DirectRequest
}
}
if
(
$this
->
getToken
()
->
isMain
())
{
if
(
!
empty
(
$this
->
getParams
()[
'SelectionCriteria'
][
'CampaignIds'
])
&&
!
isset
(
$response
[
'result'
][
'LimitedBy'
])
)
{
$campaign_ids
=
$this
->
getParams
()[
'SelectionCriteria'
][
'CampaignIds'
];
DB
::
update
(
"UPDATE advertisements ad
INNER JOIN campaigns ca ON ad.campaign_id = ca.id
SET ad.deleted_at = now()
WHERE ca.ads_loaded_at IS NOT NULL
AND ad.updated_at <= ca.ads_loaded_at
AND ad.deleted_at is null
AND ca.external_id in ("
.
implode
(
", "
,
$campaign_ids
)
.
")"
);
Campaigns
::
whereIn
(
'external_id'
,
$campaign_ids
)
->
update
([
'ads_loaded_at'
=>
Carbon
::
now
(),
]);
}
}
}
private
function
requestPrepare
(
$filter
)
...
...
database/migrations/2021_09_22_112540_add_ads_loaded_at_column.php
0 → 100644
View file @
76d05e2
<?php
use
Illuminate\Database\Migrations\Migration
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
class
AddAdsLoadedAtColumn
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
table
(
'campaigns'
,
function
(
Blueprint
$table
)
{
$table
->
timestamp
(
'ads_loaded_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