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 44836271
authored
Jun 21, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Резервирование записи создания фраз
1 parent
4463a059
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
91 additions
and
17 deletions
app/Console/Commands/KeywordsAdd.php
app/Jobs/ProcessCallAPI.php
app/Models/Pivots/GoalKeyword.php
app/Service/Contract/APIRequest.php
app/Service/Requests/APIRequest.php
app/Service/Requests/Direct/AddKeywords.php
database/migrations/2021_06_21_073613_add_goal_keywords_reserve_create_at_column.php
app/Console/Commands/KeywordsAdd.php
View file @
4483627
...
@@ -2,9 +2,11 @@
...
@@ -2,9 +2,11 @@
namespace
App\Console\Commands
;
namespace
App\Console\Commands
;
use
App\Models\Pivots\GoalKeyword
;
use
App\Models\Tokens
;
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
Carbon\Carbon
;
use
Illuminate\Console\Command
;
use
Illuminate\Console\Command
;
use
Illuminate\Database\Eloquent\Relations\HasManyThrough
;
use
Illuminate\Database\Eloquent\Relations\HasManyThrough
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\DB
;
...
@@ -57,24 +59,34 @@ class KeywordsAdd extends Command
...
@@ -57,24 +59,34 @@ class KeywordsAdd extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
setToken
(
$token
);
$goalKeywords
=
DB
::
table
(
'goal_keywords'
)
->
join
(
'keywords'
,
'goal_keywords.keyword_id'
,
'='
,
'keywords.id'
)
->
whereNull
(
'keywords.deleted_at'
)
->
whereNull
(
'goal_keywords.external_id'
)
->
whereNull
(
'goal_keywords.reserve_create_at'
)
->
whereNotNull
(
'goal_keywords.goal_ad_group_external_id'
)
->
whereNotNull
(
'goal_keywords.dictionary_campaign_external_id'
)
->
whereIn
(
'goal_keywords.dictionary_campaign_id'
,
$token
->
dictionaryCampaignsEnabledForExternalSynchronized
->
pluck
(
'id'
))
->
select
([
'goal_keywords.id as id'
,
'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
();
GoalKeyword
::
whereIn
(
'id'
,
$goalKeywords
->
pluck
(
'id'
)
->
toArray
())
->
update
([
'reserve_create_at'
=>
Carbon
::
now
(),
]);
$factory
->
getRequest
(
'Keywords'
,
'add'
)
$factory
->
getRequest
(
'Keywords'
,
'add'
)
->
call
([
->
call
([
'goalKeywords'
=>
DB
::
table
(
'goal_keywords'
)
'goalKeywords'
=>
$goalKeywords
,
->
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.id as id'
,
'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/Jobs/ProcessCallAPI.php
View file @
4483627
...
@@ -73,4 +73,10 @@ class ProcessCallAPI implements ShouldQueue
...
@@ -73,4 +73,10 @@ class ProcessCallAPI implements ShouldQueue
throw
$e
;
throw
$e
;
}
}
}
}
public
function
failed
()
{
$this
->
api
->
failed
();
}
}
}
app/Models/Pivots/GoalKeyword.php
View file @
4483627
...
@@ -59,12 +59,14 @@ class GoalKeyword extends Pivot
...
@@ -59,12 +59,14 @@ class GoalKeyword extends Pivot
'external_upload_at'
,
'external_upload_at'
,
'external_updated_at'
,
'external_updated_at'
,
'updated_need'
,
'updated_need'
,
'reserve_create_at'
,
];
];
protected
$casts
=
[
protected
$casts
=
[
'external_upload_at'
=>
'datetime'
,
'external_upload_at'
=>
'datetime'
,
'external_updated_at'
=>
'datetime'
,
'external_updated_at'
=>
'datetime'
,
'updated_need'
=>
'datetime'
,
'updated_need'
=>
'datetime'
,
'reserve_create_at'
=>
'datetime'
,
];
];
public
$incrementing
=
true
;
public
$incrementing
=
true
;
...
@@ -131,6 +133,15 @@ class GoalKeyword extends Pivot
...
@@ -131,6 +133,15 @@ class GoalKeyword extends Pivot
];
];
}
}
public
static
function
boot
()
{
parent
::
boot
();
static
::
deleted
(
function
(
GoalKeyword
$goalKeyword
)
{
GoalKeywordDelete
::
updateOrCreateByMain
(
$goalKeyword
);
});
}
/**
/**
* @param Builder $query
* @param Builder $query
* @return Builder
* @return Builder
...
...
app/Service/Contract/APIRequest.php
View file @
4483627
...
@@ -19,6 +19,7 @@ interface APIRequest{
...
@@ -19,6 +19,7 @@ interface APIRequest{
function
call
(
$params
=
null
);
function
call
(
$params
=
null
);
function
handle
(
$response
);
function
handle
(
$response
);
function
failed
();
function
getObjectsCount
();
function
getObjectsCount
();
function
getMaxCount
();
function
getMaxCount
();
...
...
app/Service/Requests/APIRequest.php
View file @
4483627
...
@@ -131,6 +131,11 @@ class APIRequest implements \App\Service\Contract\APIRequest
...
@@ -131,6 +131,11 @@ class APIRequest implements \App\Service\Contract\APIRequest
}
}
function
failed
()
{
}
function
getObjectsCount
()
function
getObjectsCount
()
{
{
throw
new
\Exception
(
'Не задано сколько объектов обрабатывается'
);
throw
new
\Exception
(
'Не задано сколько объектов обрабатывается'
);
...
...
app/Service/Requests/Direct/AddKeywords.php
View file @
4483627
...
@@ -9,8 +9,8 @@ use App\Service\Contract\APIRequest;
...
@@ -9,8 +9,8 @@ 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\Support\Collection
;
use
Illuminate\Support\Facades\Log
;
use
Illuminate\Support\Facades\Log
;
use
Ramsey\Collection\Collection
;
class
AddKeywords
extends
DirectRequest
class
AddKeywords
extends
DirectRequest
{
{
...
@@ -78,6 +78,7 @@ class AddKeywords extends DirectRequest
...
@@ -78,6 +78,7 @@ class AddKeywords extends DirectRequest
$goalKeyword
->
update
([
$goalKeyword
->
update
([
'external_id'
=>
$external_id
,
'external_id'
=>
$external_id
,
'external_upload_at'
=>
Carbon
::
now
(),
'external_upload_at'
=>
Carbon
::
now
(),
'reserve_create_at'
=>
null
,
]);
]);
}
}
...
@@ -93,6 +94,14 @@ class AddKeywords extends DirectRequest
...
@@ -93,6 +94,14 @@ class AddKeywords extends DirectRequest
$this
->
goalKeywords
=
$params
[
'goalKeywords'
];
$this
->
goalKeywords
=
$params
[
'goalKeywords'
];
}
}
public
function
failed
()
{
GoalKeyword
::
whereIn
(
'id'
,
$this
->
goalKeywords
->
pluck
(
'id'
)
->
toArray
())
->
update
([
'reserve_create_at'
=>
null
,
]);
}
private
function
requestPrepare
(
$params
)
private
function
requestPrepare
(
$params
)
{
{
$this
->
setService
(
'Keywords'
);
$this
->
setService
(
'Keywords'
);
...
...
database/migrations/2021_06_21_073613_add_goal_keywords_reserve_create_at_column.php
0 → 100644
View file @
4483627
<?php
use
Illuminate\Database\Migrations\Migration
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
class
AddGoalKeywordsReserveCreateAtColumn
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
table
(
'goal_keywords'
,
function
(
Blueprint
$table
)
{
$table
->
timestamp
(
'reserve_create_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