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 0a8bf962
authored
Sep 01, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#20794 Сделать чтобы в целевых РК оставалась одна карточка
1 parent
909272f7
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
5 deletions
app/Console/Commands/AdGroupsAdd.php
app/Models/AdGroup.php
app/Models/Pivots/GoalAdvertisement.php
app/Service/Requests/Direct/AddAds.php
app/Service/Requests/Direct/UpdateAds.php
app/Console/Commands/AdGroupsAdd.php
View file @
0a8bf96
...
...
@@ -7,6 +7,7 @@ use App\Models\Tokens;
use
App\Service\Requests\Direct\AddAdGroups
;
use
Carbon\Carbon
;
use
Illuminate\Console\Command
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Relations\HasMany
;
class
AdGroupsAdd
extends
Command
...
...
@@ -42,14 +43,18 @@ class AdGroupsAdd extends Command
*/
public
function
handle
()
{
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternalSynchronized.groupsForNotExternalForNotReserveCreate.group'
)
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternalSynchronized.groupsForNotExternalForNotReserveCreate.group'
,
function
(
Builder
$query
)
{
return
$query
->
has
(
'keywords'
)
->
orHas
(
'bidModifiers'
)
->
orHas
(
'advertisements'
);
})
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
foreach
(
$tokens
as
$token
)
{
$token
->
load
([
'dictionaryCampaignsEnabledForExternalSynchronized.groupsForNotExternalForNotReserveCreate'
=>
function
(
HasMany
$query
)
{
return
$query
->
has
(
'group'
);
return
$query
->
whereHas
(
'group'
,
function
(
Builder
$query
)
{
return
$query
->
has
(
'keywords'
)
->
orHas
(
'bidModifiers'
)
->
orHas
(
'advertisements'
);
});
},
'dictionaryCampaignsEnabledForExternalSynchronized.groupsForNotExternalForNotReserveCreate.group'
,
'dictionaryCampaignsEnabledForExternalSynchronized.groupsForNotExternalForNotReserveCreate.goalNegativeKeywordSharedSets'
,
...
...
app/Models/AdGroup.php
View file @
0a8bf96
...
...
@@ -209,6 +209,16 @@ class AdGroup extends Model
return
$this
->
hasMany
(
Keyword
::
class
,
'ad_group_id'
);
}
public
function
bidModifiers
()
{
return
$this
->
hasMany
(
BidModifier
::
class
,
'ad_group_id'
);
}
public
function
advertisements
()
{
return
$this
->
hasMany
(
Advertisement
::
class
,
'ad_group_id'
);
}
public
function
negativeKeywordSharedSets
()
{
return
$this
->
belongsToMany
(
NegativeKeywordSharedSet
::
class
,
AdGroupNegativeKeywordSharedSet
::
getModel
()
->
getTable
(),
'ad_group_id'
,
'negative_keyword_shared_set_id'
)
...
...
app/Models/Pivots/GoalAdvertisement.php
View file @
0a8bf96
...
...
@@ -259,6 +259,11 @@ class GoalAdvertisement extends Pivot
return
$this
->
belongsTo
(
GoalVCard
::
class
,
'goal_v_card_id'
);
}
public
function
goalAdGroup
()
{
return
$this
->
belongsTo
(
GoalAdGroup
::
class
,
'goal_ad_group_id'
);
}
public
function
goalAdExtensions
()
{
return
$this
->
belongsToMany
(
GoalAdExtension
::
class
,
GoalAdvertisementGoalAdExtension
::
getModel
()
->
getTable
(),
'goal_advertisement_id'
,
'goal_ad_extension_id'
)
...
...
app/Service/Requests/Direct/AddAds.php
View file @
0a8bf96
...
...
@@ -76,8 +76,14 @@ class AddAds extends DirectRequest
Advertisement
::
where
(
'id'
,
$goalAd
->
id
)
->
forceDelete
();
}
else
{
GoalAdvertisement
::
where
(
'id'
,
$goalAd
->
id
)
->
forceDelete
();
$model
=
GoalAdvertisement
::
with
(
'goalAdGroup'
)
->
firstWhere
(
'id'
,
$goalAd
->
id
);
if
(
$model
)
{
if
(
$model
->
goalAdGroup
)
{
$model
->
goalAdGroup
->
delete
();
}
$model
->
forceDelete
();
}
}
continue
;
...
...
app/Service/Requests/Direct/UpdateAds.php
View file @
0a8bf96
...
...
@@ -47,7 +47,20 @@ class UpdateAds extends DirectRequest
if
(
isset
(
$update_result
[
'Errors'
][
0
][
'Details'
])
&&
$update_result
[
'Errors'
][
0
][
'Details'
]
===
'You cannot update an archived ad'
)
{
GoalAdvertisement
::
whereExternalId
(
$this
->
getParams
()[
'Ads'
][
$key
][
'Id'
])
->
forceDelete
();
->
update
([
'deleted_need'
=>
Carbon
::
now
(),
'archived_need'
=>
null
,
'reserve_archive_at'
=>
null
,
'reserve_update_at'
=>
null
,
]);
continue
;
}
elseif
(
isset
(
$update_result
[
'Errors'
][
0
][
'Details'
])
&&
$update_result
[
'Errors'
][
0
][
'Details'
]
===
'Ad not found'
)
{
GoalAdvertisement
::
whereExternalId
(
$this
->
getParams
()[
'Ads'
][
$key
][
'Id'
])
->
update
([
'reserve_update_at'
=>
null
,
]);
GoalAdvertisement
::
whereExternalId
(
$this
->
getParams
()[
'Ads'
][
$key
][
'Id'
])
->
delete
();
continue
;
}
...
...
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