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 477b8faf
authored
Jun 24, 2021
by
Евгений
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Улучшение #19474
Синхронизация фраз
1 parent
1db4933c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
26 deletions
app/Console/Commands/DictionaryCampaignsSyncByCampaign.php
app/Console/Commands/KeywordsDelete.php
app/Models/Keyword.php
app/Service/Requests/Direct/DeleteKeywords.php
app/Service/Requests/Direct/GetKeywords.php
app/Console/Commands/DictionaryCampaignsSyncByCampaign.php
View file @
477b8fa
...
@@ -129,7 +129,7 @@ class DictionaryCampaignsSyncByCampaign extends Command
...
@@ -129,7 +129,7 @@ class DictionaryCampaignsSyncByCampaign extends Command
INNER JOIN ad_groups ag on k.ad_group_id = ag.id
INNER JOIN ad_groups ag on k.ad_group_id = ag.id
INNER JOIN goal_ad_groups gag on ag.id = gag.ad_group_id
INNER JOIN goal_ad_groups gag on ag.id = gag.ad_group_id
LEFT JOIN goal_keywords gk on k.id = gk.keyword_id AND gk.goal_ad_group_id=gag.id
LEFT JOIN goal_keywords gk on k.id = gk.keyword_id AND gk.goal_ad_group_id=gag.id
WHERE gk.keyword_id is null
WHERE gk.keyword_id is null
AND k.deleted_at is null
"
);
"
);
//грузим ключевые фразы которых по какой то причне нет в целевых.
//грузим ключевые фразы которых по какой то причне нет в целевых.
...
...
app/Console/Commands/KeywordsDelete.php
View file @
477b8fa
...
@@ -6,6 +6,7 @@ use App\Models\Tokens;
...
@@ -6,6 +6,7 @@ use App\Models\Tokens;
use
App\Service\API\API
;
use
App\Service\API\API
;
use
App\Service\Requests\APIRequest
;
use
App\Service\Requests\APIRequest
;
use
Illuminate\Console\Command
;
use
Illuminate\Console\Command
;
use
Illuminate\Support\Facades\DB
;
class
KeywordsDelete
extends
Command
class
KeywordsDelete
extends
Command
{
{
...
@@ -47,16 +48,27 @@ class KeywordsDelete extends Command
...
@@ -47,16 +48,27 @@ class KeywordsDelete extends Command
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
->
get
();
foreach
(
$tokens
as
$token
)
{
foreach
(
Tokens
::
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
()
as
$token
)
{
$sql
=
"SELECT gk.external_id
FROM goal_keywords gk
INNER JOIN keywords k ON gk.keyword_id=k.id
INNER JOIN dictionary_campaigns c ON c.id=gk.dictionary_campaign_id
INNER JOIN dictionaries d ON d.id=c.dictionary_id
WHERE k.deleted_at is not null AND d.token_id="
.
$token
->
id
;
$result
=
DB
::
select
(
$sql
);
$ids
=
[];
foreach
(
$result
as
$item
){
$ids
[]
=
$item
->
external_id
;
}
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'Keywords'
,
'delete'
)
$factory
->
getRequest
(
'Keywords'
,
'delete'
)
->
call
([
->
call
([
'ids'
=>
$token
->
dictionaryCampaignsForExternalWithTrashed
->
pluck
(
'goalKeywordsDelete'
)
'ids'
=>
$ids
->
collapse
()
->
pluck
(
'external_id'
)
->
toArray
(),
]);
]);
}
}
...
...
app/Models/Keyword.php
View file @
477b8fa
...
@@ -111,21 +111,21 @@ class Keyword extends Model
...
@@ -111,21 +111,21 @@ class Keyword extends Model
{
{
parent
::
boot
();
parent
::
boot
();
static
::
deleted
(
function
(
Keyword
$keyword
)
{
//
static::deleted(function (Keyword $keyword) {
//
if
(
!
$keyword
->
isForceDeleting
())
{
//
if (!$keyword->isForceDeleting()) {
//
$keyword
->
goalKeywords
->
each
(
function
(
GoalKeyword
$goalKeyword
)
{
//
$keyword->goalKeywords->each(function (GoalKeyword $goalKeyword) {
//
GoalKeywordDelete
::
updateOrCreateByMain
(
$goalKeyword
);
//
GoalKeywordDelete::updateOrCreateByMain($goalKeyword);
//
$goalKeyword
->
delete
();
//
$goalKeyword->delete();
//
});
//
});
//
}
//
}
//
});
//
});
}
}
public
function
goalKeywords
()
public
function
goalKeywords
()
...
...
app/Service/Requests/Direct/DeleteKeywords.php
View file @
477b8fa
...
@@ -61,7 +61,7 @@ class DeleteKeywords extends DirectRequest
...
@@ -61,7 +61,7 @@ class DeleteKeywords extends DirectRequest
$external_id
=
(
string
)
$delete_result
[
'Id'
];
$external_id
=
(
string
)
$delete_result
[
'Id'
];
GoalKeyword
Delete
::
where
(
'external_id'
,
$external_id
)
->
delete
();
GoalKeyword
::
where
(
'external_id'
,
$external_id
)
->
delete
();
}
}
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
...
...
app/Service/Requests/Direct/GetKeywords.php
View file @
477b8fa
...
@@ -120,6 +120,7 @@ class GetKeywords extends DirectRequest
...
@@ -120,6 +120,7 @@ class GetKeywords extends DirectRequest
'state'
=>
$keyword
[
'State'
],
'state'
=>
$keyword
[
'State'
],
'status'
=>
$keyword
[
'Status'
],
'status'
=>
$keyword
[
'Status'
],
'serving_status'
=>
$keyword
[
'ServingStatus'
],
'serving_status'
=>
$keyword
[
'ServingStatus'
],
'updated_at'
=>
DB
::
raw
(
'now()'
),
'deleted_at'
=>
null
//не забыть убрать признак удаления, если вдруг опять пришла удаленная ранее фраза
'deleted_at'
=>
null
//не забыть убрать признак удаления, если вдруг опять пришла удаленная ранее фраза
];
];
...
@@ -141,7 +142,12 @@ class GetKeywords extends DirectRequest
...
@@ -141,7 +142,12 @@ class GetKeywords extends DirectRequest
}
}
foreach
(
array_chunk
(
$insertData
,
1000
)
as
$data
)
{
foreach
(
array_chunk
(
$insertData
,
1000
)
as
$data
)
{
$items
=
[];
foreach
(
$data
as
$item
){
$items
[]
=
$item
[
'external_id'
];
}
Keyword
::
insertOrIgnore
(
$data
);
Keyword
::
insertOrIgnore
(
$data
);
Keyword
::
whereIn
(
'external_id'
,
$items
)
->
update
([
'updated_at'
=>
DB
::
raw
(
'now()'
)]);
}
}
...
@@ -194,13 +200,16 @@ class GetKeywords extends DirectRequest
...
@@ -194,13 +200,16 @@ class GetKeywords extends DirectRequest
//это означает что этой фразы не было в результатах и в БД она по этой причине не обновилась
//это означает что этой фразы не было в результатах и в БД она по этой причине не обновилась
//надо такие пометить на удаление
//надо такие пометить на удаление
//при удалении для всех таких надо будет удалить фразы из целевых и потом удалить их сами
//при удалении для всех таких надо будет удалить фразы из целевых и потом удалить их сами
$sql
=
"UPDATE keywords k
$sql
=
"UPDATE keywords k
INNER JOIN ad_groups ag ON k.ad_group_id=ag.id
INNER JOIN ad_groups ag ON k.ad_group_id=ag.id
SET k.deleted_at = now(),
SET k.deleted_at = now()
ag.keywords_loaded_at=now()
WHERE k.updated_at<=ag.keywords_loaded_at
WHERE k.updated_at>ag.keywords_loaded_at
AND k.deleted_at is null
AND k.deleted_at is null
AND ag.id in ("
.
implode
(
", "
,
$ag_groups
)
.
")"
;
AND ag.external_id in ("
.
implode
(
", "
,
$ag_groups
)
.
")"
;
DB
::
update
(
$sql
);
$sql
=
"UPDATE ad_groups SET keywords_loaded_at=now() WHERE external_id in ("
.
implode
(
", "
,
$ag_groups
)
.
")"
;
DB
::
update
(
$sql
);
DB
::
update
(
$sql
);
}
}
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
...
...
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