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 fc95f60a
authored
Jun 18, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Оптимизация добавления фраз
1 parent
f811963b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
36 deletions
app/Console/Commands/KeywordsAdd.php
app/Service/Requests/Direct/AddKeywords.php
app/Console/Commands/KeywordsAdd.php
View file @
fc95f60
...
@@ -6,7 +6,8 @@ use App\Models\Tokens;
...
@@ -6,7 +6,8 @@ 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\Database\Eloquent\Relations\HasMany
;
use
Illuminate\Database\Eloquent\Relations\HasManyThrough
;
use
Illuminate\Support\Facades\DB
;
class
KeywordsAdd
extends
Command
class
KeywordsAdd
extends
Command
{
{
...
@@ -48,21 +49,48 @@ class KeywordsAdd extends Command
...
@@ -48,21 +49,48 @@ class KeywordsAdd extends Command
foreach
(
$tokens
as
$token
)
{
foreach
(
$tokens
as
$token
)
{
$token
->
load
([
$token
->
load
([
'dictionaryCampaignsEnabledForExternalSynchronized
.goalKeywordsForNotExternal'
=>
function
(
HasMany
$query
)
{
'dictionaryCampaignsEnabledForExternalSynchronized
'
=>
function
(
HasManyThrough
$query
)
{
return
$query
->
has
(
'keyword'
);
return
$query
->
has
(
'
goalKeywordsForNotExternal.
keyword'
);
},
},
'dictionaryCampaignsEnabledForExternalSynchronized.goalKeywordsForNotExternal.keyword'
,
]);
]);
$goalKeywords
=
$token
->
dictionaryCampaignsEnabledForExternalSynchronized
->
pluck
(
'goalKeywordsForNotExternal'
)
->
collapse
();
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
setToken
(
$token
);
dd
(
DB
::
table
(
'goal_keywords'
)
->
join
(
'keywords'
,
'goal_keywords.keyword_id'
,
'='
,
'keywords.id'
)
->
whereNull
(
'keywords.deleted_at'
)
->
whereNull
(
'goal_keywords.external_id'
)
->
whereIn
(
'goal_keywords.dictionary_campaign_id'
,
$token
->
dictionaryCampaignsEnabledForExternalSynchronized
->
pluck
(
'id'
))
->
select
([
'goal_keywords.dictionary_campaign_id as dictionary_campaign_id'
,
'goal_keywords.goal_ad_group_external_id as goal_ad_group_external_id'
,
'keywords.keyword as keyword'
,
'keywords.bid as bid'
,
'keywords.context_bid as context_bid'
,
'keywords.strategy_priority as strategy_priority'
,
'keywords.user_param_1 as user_param_1'
,
'keywords.user_param_2 as user_param_2'
,
])
->
get
());
$factory
->
getRequest
(
'Keywords'
,
'add'
)
$factory
->
getRequest
(
'Keywords'
,
'add'
)
->
call
([
->
call
([
'goalKeywords'
=>
$goalKeywords
,
'goalKeywords'
=>
DB
::
table
(
'goal_keywords'
)
->
join
(
'keywords'
,
'goal_keywords.keyword_id'
,
'='
,
'keywords.id'
)
->
whereNull
(
'keywords.deleted_at'
)
->
whereNull
(
'goal_keywords.external_id'
)
->
whereIn
(
'goal_keywords.dictionary_campaign_id'
,
$token
->
dictionaryCampaignsEnabledForExternalSynchronized
->
pluck
(
'id'
))
->
select
([
'goal_keywords.dictionary_campaign_id as dictionary_campaign_id'
,
'goal_keywords.goal_ad_group_external_id as goal_ad_group_external_id'
,
'keywords.keyword as keyword'
,
'keywords.bid as bid'
,
'keywords.context_bid as context_bid'
,
'keywords.user_param_1 as user_param_1'
,
'keywords.user_param_2 as user_param_2'
,
])
->
get
(),
]);
]);
}
}
...
...
app/Service/Requests/Direct/AddKeywords.php
View file @
fc95f60
...
@@ -3,13 +3,11 @@
...
@@ -3,13 +3,11 @@
namespace
App\Service\Requests\Direct
;
namespace
App\Service\Requests\Direct
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Pivots\GoalKeyword
;
use
App\Models\Variable
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\StrReplaceByVariables
;
use
App\Service\StrReplaceByVariables
;
use
Carbon\Carbon
;
use
Carbon\Carbon
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Support\Facades\Log
;
use
Illuminate\Support\Facades\Log
;
class
AddKeywords
extends
DirectRequest
class
AddKeywords
extends
DirectRequest
...
@@ -17,7 +15,7 @@ class AddKeywords extends DirectRequest
...
@@ -17,7 +15,7 @@ class AddKeywords extends DirectRequest
protected
$max_count
=
1000
;
protected
$max_count
=
1000
;
protected
$timestamp
;
protected
$timestamp
;
/* @var
Collection|GoalKeyword[]
*/
/* @var
array
*/
protected
$goalKeywords
;
protected
$goalKeywords
;
public
function
call
(
$params
=
null
)
public
function
call
(
$params
=
null
)
...
@@ -37,11 +35,11 @@ class AddKeywords extends DirectRequest
...
@@ -37,11 +35,11 @@ class AddKeywords extends DirectRequest
$splinter
=
$this
->
sliceByKey
(
$maxObjects
,
'Keywords'
);
$splinter
=
$this
->
sliceByKey
(
$maxObjects
,
'Keywords'
);
$splinter
->
putParams
([
$splinter
->
putParams
([
'goalKeywords'
=>
$this
->
goalKeywords
->
slice
(
$maxObjects
)
->
values
(
),
'goalKeywords'
=>
array_values
(
array_slice
(
$this
->
goalKeywords
,
$maxObjects
)
),
]);
]);
$this
->
putParams
([
$this
->
putParams
([
'goalKeywords'
=>
$this
->
goalKeywords
->
slice
(
0
,
$maxObjects
),
'goalKeywords'
=>
array_values
(
array_slice
(
$this
->
goalKeywords
,
0
,
$maxObjects
)
),
]);
]);
return
$splinter
;
return
$splinter
;
...
@@ -70,7 +68,7 @@ class AddKeywords extends DirectRequest
...
@@ -70,7 +68,7 @@ class AddKeywords extends DirectRequest
$external_id
=
(
string
)
$add_result
[
'Id'
];
$external_id
=
(
string
)
$add_result
[
'Id'
];
$goalKeyword
=
$this
->
goalKeywords
->
get
(
$key
)
;
$goalKeyword
=
$this
->
goalKeywords
[
$key
]
;
$goalKeyword
->
update
([
$goalKeyword
->
update
([
'external_id'
=>
$external_id
,
'external_id'
=>
$external_id
,
...
@@ -100,44 +98,38 @@ class AddKeywords extends DirectRequest
...
@@ -100,44 +98,38 @@ class AddKeywords extends DirectRequest
$lists
=
[];
$lists
=
[];
$this
->
setParams
([
$this
->
setParams
([
'Keywords'
=>
$this
->
goalKeywords
->
map
(
function
(
GoalKeyword
$goalKeyword
)
use
(
$variables
,
$lists
)
{
'Keywords'
=>
array_map
(
function
(
array
$goalKeyword
)
use
(
$variables
,
$lists
)
{
if
(
!
isset
(
$lists
[
$goalKeyword
->
dictionary_campaign_id
]))
{
if
(
!
isset
(
$lists
[
$goalKeyword
[
'dictionary_campaign_id'
]
]))
{
$list
=
Variable
::
getListVariablesByDictionaryCampaign
(
$goalKeyword
->
dictionary_campaign_id
,
$variables
);
$list
=
Variable
::
getListVariablesByDictionaryCampaign
(
$goalKeyword
[
'dictionary_campaign_id'
]
,
$variables
);
$lists
[
$goalKeyword
->
dictionary_campaign_id
]
=
$list
;
$lists
[
$goalKeyword
[
'dictionary_campaign_id'
]
]
=
$list
;
}
else
{
}
else
{
$list
=
$lists
[
$goalKeyword
->
dictionary_campaign_id
];
$list
=
$lists
[
$goalKeyword
[
'dictionary_campaign_id'
]
];
}
}
$keyword
=
$goalKeyword
->
keyword
;
$data
=
[
$data
=
[
'Keyword'
=>
StrReplaceByVariables
::
getInstance
(
$
keyword
->
keyword
,
$list
)
->
get
(),
'Keyword'
=>
StrReplaceByVariables
::
getInstance
(
$
goalKeyword
[
'keyword'
]
,
$list
)
->
get
(),
'AdGroupId'
=>
$goalKeyword
->
goal_ad_group_external_id
,
'AdGroupId'
=>
$goalKeyword
[
'goal_ad_group_external_id'
]
,
];
];
if
(
$keyword
->
bid
)
{
if
(
$goalKeyword
[
'bid'
])
{
$data
[
'Bid'
]
=
$keyword
->
bid
;
$data
[
'Bid'
]
=
$goalKeyword
[
'bid'
];
}
if
(
$keyword
->
context_bid
)
{
$data
[
'ContextBid'
]
=
$keyword
->
context_bid
;
}
}
if
(
$
keyword
->
strategy_priority
)
{
if
(
$
goalKeyword
[
'context_bid'
]
)
{
$data
[
'
StrategyPriority'
]
=
$keyword
->
strategy_priority
;
$data
[
'
ContextBid'
]
=
$goalKeyword
[
'context_bid'
]
;
}
}
if
(
$
keyword
->
user_param_1
)
{
if
(
$
goalKeyword
[
'user_param_1'
]
)
{
$data
[
'UserParam1'
]
=
$
keyword
->
user_param_1
;
$data
[
'UserParam1'
]
=
$
goalKeyword
[
'user_param_1'
]
;
}
}
if
(
$
keyword
->
user_param_2
)
{
if
(
$
goalKeyword
[
'user_param_2'
]
)
{
$data
[
'UserParam2'
]
=
$
keyword
->
user_param_2
;
$data
[
'UserParam2'
]
=
$
goalKeyword
[
'user_param_2'
]
;
}
}
return
$data
;
return
$data
;
}
)
->
toArray
(
),
}
,
$this
->
goalKeywords
),
]);
]);
}
}
...
...
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