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 1acc74a1
authored
Sep 16, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#20794 Сделать чтобы в целевых РК оставалась одна карточка (резервирование удаление фраз)
1 parent
bd616e9b
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
95 additions
and
92 deletions
app/Console/Commands/KeywordsDelete.php
app/Console/Kernel.php
app/Models/Pivots/GoalKeyword.php
app/Service/Requests/Direct/DeleteAds.php
app/Service/Requests/Direct/DeleteKeywords.php
app/Service/Requests/Direct/SetBidModifiers.php
app/Service/Requests/Direct/UpdateAdGroups.php
app/Service/Requests/Direct/UpdateAds.php
app/Service/Requests/Direct/UpdateCampaigns.php
app/Service/Requests/Direct/UpdateKeywords.php
database/migrations/2021_09_16_091521_create_keywords_reserve_table.php
app/Console/Commands/KeywordsDelete.php
View file @
1acc74a
...
...
@@ -2,8 +2,10 @@
namespace
App\Console\Commands
;
use
App\Models\Pivots\GoalKeyword
;
use
App\Models\Tokens
;
use
App\Service\Requests\Direct\DeleteKeywords
;
use
Carbon\Carbon
;
use
Illuminate\Console\Command
;
use
Illuminate\Support\Facades\DB
;
...
...
@@ -47,7 +49,8 @@ class KeywordsDelete extends Command
INNER JOIN dictionary_campaigns c ON c.id=gk.dictionary_campaign_id
INNER JOIN dictionaries d ON d.id=c.dictionary_id
WHERE gk.external_id is not null
AND d.token_id="
.
$token
->
id
.
"
AND gk.reserve_delete_at is null
AND d.token_id="
.
$token
->
id
.
"
AND (
(k.deleted_at is not null)
OR (
...
...
@@ -74,6 +77,13 @@ class KeywordsDelete extends Command
continue
;
}
foreach
(
array_chunk
(
$ids
,
1000
)
as
$items
)
{
GoalKeyword
::
whereIn
(
'external_id'
,
$items
)
->
update
([
'reserve_delete_at'
=>
Carbon
::
now
(),
]);
}
$request
=
new
DeleteKeywords
();
$request
->
setToken
(
$token
)
->
call
([
...
...
app/Console/Kernel.php
View file @
1acc74a
...
...
@@ -69,6 +69,8 @@ class Kernel extends ConsoleKernel
*/
protected
function
schedule
(
Schedule
$schedule
)
{
return
;
$schedule
->
command
(
DictionaryCampaignsSyncByCampaign
::
class
)
->
everyThirtyMinutes
();
$schedule
->
command
(
RefreshLimits
::
class
)
->
hourly
();
...
...
app/Models/Pivots/GoalKeyword.php
View file @
1acc74a
...
...
@@ -63,6 +63,7 @@ class GoalKeyword extends Pivot
'updated_need'
,
'reserve_create_at'
,
'reserve_update_at'
,
'reserve_delete_at'
,
];
protected
$casts
=
[
...
...
@@ -71,6 +72,7 @@ class GoalKeyword extends Pivot
'updated_need'
=>
'datetime'
,
'reserve_create_at'
=>
'datetime'
,
'reserve_update_at'
=>
'datetime'
,
'reserve_delete_at'
=>
'datetime'
,
];
public
$incrementing
=
true
;
...
...
@@ -90,52 +92,7 @@ class GoalKeyword extends Pivot
'updated_need'
,
'reserve_create_at'
,
'reserve_update_at'
,
];
}
/**
* @return Collection
*/
static
public
function
getPropertiesCopyWithPivot
()
{
return
collect
([
]);
}
/**
* @param Keyword|array $keyword
*
* @return array
*/
static
public
function
copyPropertyFromMain
(
$keyword
)
{
return
self
::
getPropertiesCopyWithPivot
()
->
transform
(
function
(
$property_name
)
use
(
$keyword
)
{
$value
=
null
;
if
(
$keyword
instanceof
Keyword
)
{
$value
=
$keyword
->
{
$property_name
};
}
elseif
(
is_array
(
$keyword
)
&&
isset
(
$keyword
[
$property_name
]))
{
$value
=
$keyword
[
$property_name
];
}
return
[
$property_name
=>
$value
];
})
->
collapse
()
->
put
(
'keyword_id'
,
$keyword
[
GoalKeyword
::
getModel
()
->
getKeyName
()])
->
all
();
}
static
public
function
getDataByMain
(
Keyword
$keyword
,
GoalAdGroup
$goalAdGroup
,
DictionaryCampaign
$dictionaryCampaign
)
{
return
[
'dictionary_campaign_id'
=>
$dictionaryCampaign
->
getKey
(),
'dictionary_campaign_external_id'
=>
$dictionaryCampaign
->
external_id
,
'goal_ad_group_id'
=>
$goalAdGroup
->
getKey
(),
'goal_ad_group_external_id'
=>
$goalAdGroup
->
external_id
,
'keyword_id'
=>
$keyword
->
getKey
(),
'reserve_delete_at'
,
];
}
...
...
app/Service/Requests/Direct/DeleteAds.php
View file @
1acc74a
...
...
@@ -51,12 +51,10 @@ class DeleteAds extends DirectRequest
)
{
if
(
$this
->
getToken
()
->
isMain
())
{
Advertisement
::
needDeleted
()
->
where
(
'external_id'
,
$external_id
)
Advertisement
::
where
(
'external_id'
,
$external_id
)
->
delete
();
}
else
{
GoalAdvertisement
::
forExternal
()
->
needDeleted
()
->
where
(
'external_id'
,
$external_id
)
GoalAdvertisement
::
where
(
'external_id'
,
$external_id
)
->
delete
();
}
...
...
@@ -104,12 +102,10 @@ class DeleteAds extends DirectRequest
$external_id
=
(
string
)
$delete_result
[
'Id'
];
if
(
$this
->
getToken
()
->
isMain
())
{
Advertisement
::
needDeleted
()
->
where
(
'external_id'
,
$external_id
)
Advertisement
::
where
(
'external_id'
,
$external_id
)
->
delete
();
}
else
{
GoalAdvertisement
::
forExternal
()
->
needDeleted
()
->
where
(
'external_id'
,
$external_id
)
GoalAdvertisement
::
where
(
'external_id'
,
$external_id
)
->
delete
();
}
...
...
app/Service/Requests/Direct/DeleteKeywords.php
View file @
1acc74a
...
...
@@ -6,6 +6,7 @@ use App\Jobs\ProcessCallLimitedAPI;
use
App\Models\Pivots\GoalKeyword
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Requests\DirectRequest
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Log
;
class
DeleteKeywords
extends
DirectRequest
...
...
@@ -37,43 +38,56 @@ class DeleteKeywords extends DirectRequest
return
;
}
foreach
(
$response
[
'result'
][
'DeleteResults'
]
as
$key
=>
$delete_result
)
{
$delete_results
=
$response
[
'result'
][
'DeleteResults'
];
$external_id
=
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
][
$key
];
foreach
(
array_chunk
(
array_column
(
array_filter
(
$delete_results
,
function
(
$delete_result
)
{
return
isset
(
$delete_result
[
'Id'
])
||
(
isset
(
$delete_result
[
'Errors'
][
0
][
'Details'
])
&&
$delete_result
[
'Errors'
][
0
][
'Details'
]
===
'Keyword not found'
);
}),
'Id'
),
1000
)
as
$external_ids
)
{
GoalKeyword
::
whereExternalId
(
$external_ids
)
->
delete
();
}
if
(
!
isset
(
$delete_result
[
'Id'
]))
{
if
(
isset
(
$delete_result
[
'Errors'
][
0
][
'Details'
])
&&
$delete_result
[
'Errors'
][
0
][
'Details'
]
===
'Keyword not found'
)
{
//объекта по какой то причине нет
GoalKeyword
::
where
(
'external_id'
,
$external_id
)
->
delete
();
}
elseif
(
isset
(
$delete_result
[
'Errors'
])
&&
count
(
$delete_result
[
'Errors'
]))
{
$goalKeyword
=
GoalKeyword
::
whereExternalId
(
$external_id
)
->
first
();
if
(
$goalKeyword
)
{
$goalKeyword
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$external_id
,
'errors'
=>
$delete_result
[
'Errors'
],
]);
}
}
else
{
Log
::
debug
(
"DeleteKeywords, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$delete_result
);
Log
::
debug
(
$external_id
);
}
foreach
(
$delete_results
as
$key
=>
$delete_result
)
{
if
(
isset
(
$delete_result
[
'Id'
]))
{
continue
;
}
$external_id
=
(
string
)
$delete_result
[
'Id'
];
$external_id
=
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
][
$key
];
if
(
isset
(
$delete_result
[
'Errors'
])
&&
count
(
$delete_result
[
'Errors'
]))
{
$goalKeyword
=
GoalKeyword
::
whereExternalId
(
$external_id
)
->
first
();
if
(
$goalKeyword
)
{
$goalKeyword
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$external_id
,
'errors'
=>
$delete_result
[
'Errors'
],
]);
}
}
else
{
Log
::
debug
(
"DeleteKeywords, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$delete_result
);
Log
::
debug
(
$external_id
);
}
GoalKeyword
::
where
(
'external_id'
,
$external_id
)
->
delete
();
GoalKeyword
::
whereExternalId
(
$external_id
)
->
update
([
'reserve_delete_at'
=>
null
,
]);
}
}
public
function
failed
()
{
GoalKeyword
::
whereIn
(
'external_id'
,
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
])
->
update
([
'reserve_delete_at'
=>
null
,
]);
}
private
function
requestPrepare
(
$params
)
{
$this
->
setService
(
'Keywords'
);
...
...
app/Service/Requests/Direct/SetBidModifiers.php
View file @
1acc74a
...
...
@@ -69,14 +69,13 @@ class SetBidModifiers extends DirectRequest
->
update
([
'reserve_update_at'
=>
null
,
]);
continue
;
}
$external_id
=
(
string
)
$set_result
[
'Id'
];
GoalBidModifier
::
forExternal
()
->
needUpdated
()
->
where
(
'external_id'
,
$external_id
)
GoalBidModifier
::
where
(
'external_id'
,
$external_id
)
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
...
...
app/Service/Requests/Direct/UpdateAdGroups.php
View file @
1acc74a
...
...
@@ -75,8 +75,7 @@ class UpdateAdGroups extends DirectRequest
$external_id
=
(
string
)
$update_result
[
'Id'
];
GoalAdGroup
::
forExternal
()
->
needUpdated
()
->
where
(
'external_id'
,
$external_id
)
GoalAdGroup
::
where
(
'external_id'
,
$external_id
)
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
...
...
app/Service/Requests/Direct/UpdateAds.php
View file @
1acc74a
...
...
@@ -89,8 +89,7 @@ class UpdateAds extends DirectRequest
$external_id
=
(
string
)
$update_result
[
'Id'
];
GoalAdvertisement
::
forExternal
()
->
needUpdated
()
->
where
(
'external_id'
,
$external_id
)
GoalAdvertisement
::
where
(
'external_id'
,
$external_id
)
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
...
...
app/Service/Requests/Direct/UpdateCampaigns.php
View file @
1acc74a
...
...
@@ -79,8 +79,7 @@ class UpdateCampaigns extends DirectRequest
$external_id
=
(
string
)
$update_result
[
'Id'
];
DictionaryCampaign
::
forExternal
()
->
needUpdated
()
->
where
(
'external_id'
,
$external_id
)
DictionaryCampaign
::
where
(
'external_id'
,
$external_id
)
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
...
...
app/Service/Requests/Direct/UpdateKeywords.php
View file @
1acc74a
...
...
@@ -80,8 +80,7 @@ class UpdateKeywords extends DirectRequest
$external_id
=
(
string
)
$update_result
[
'Id'
];
GoalKeyword
::
forExternal
()
->
needUpdated
()
->
where
(
'external_id'
,
$external_id
)
GoalKeyword
::
where
(
'external_id'
,
$external_id
)
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
...
...
database/migrations/2021_09_16_091521_create_keywords_reserve_table.php
0 → 100644
View file @
1acc74a
<?php
use
Illuminate\Database\Migrations\Migration
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
class
CreateKeywordsReserveTable
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
table
(
'goal_keywords'
,
function
(
Blueprint
$table
)
{
$table
->
timestamp
(
'reserve_delete_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