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 31f199e9
authored
May 11, 2021
by
Евгений
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Улучшение #19453
Первоначальная загрузка всех РК аккаунтов.
1 parent
2b598c91
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
146 additions
and
4 deletions
app/Models/Campaigns.php
app/Service/Requests/Direct/CheckDictionariesChange.php
app/Service/Requests/Direct/GetCampaigns.php
database/migrations/2021_05_11_084828_create_campaigns_table.php
app/Models/Campaigns.php
0 → 100644
View file @
31f199e
<?php
namespace
App\Models
;
use
Illuminate\Database\Eloquent\Factories\HasFactory
;
use
Illuminate\Database\Eloquent\Model
;
class
Campaigns
extends
Model
{
use
HasFactory
;
protected
$fillable
=
[
'external_id'
,
'Name'
,
'TimeTargeting'
,
'NegativeKeywords'
,
'BlockedIps'
,
'ExcludedSites'
,
'DailyBudget'
,
'TextCampaignStrategySearch'
,
'TextCampaignStrategyNetwork'
,
'Settings'
,
'CounterIds'
,
'RelevantKeywordsSettingBudgetPercent'
,
'RelevantKeywordsSettingOptimizeGoalId'
,
'AttributionModel'
,
];
}
app/Service/Requests/Direct/CheckDictionariesChange.php
View file @
31f199e
...
@@ -13,7 +13,7 @@ class CheckDictionariesChange extends DirectRequest {
...
@@ -13,7 +13,7 @@ class CheckDictionariesChange extends DirectRequest {
$this
->
next
=
$next
;
$this
->
next
=
$next
;
$this
->
requestPrepare
(
$response
);
$this
->
requestPrepare
(
$response
);
$process
=
new
ProcessCallLimitedAPI
(
$this
);
$process
=
new
ProcessCallLimitedAPI
(
$this
);
dispatch
(
$process
)
->
onQueue
(
'
api
'
);
dispatch
(
$process
)
->
onQueue
(
'
limits
'
);
}
}
function
handle
(
$response
){
function
handle
(
$response
){
...
...
app/Service/Requests/Direct/GetCampaigns.php
View file @
31f199e
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
App\Service\Requests\Direct
;
namespace
App\Service\Requests\Direct
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Campaigns
;
use
App\Service\API\API
;
use
App\Service\API\API
;
use
App\Service\Requests\APIRequest
;
use
App\Service\Requests\APIRequest
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\Requests\DirectRequest
;
...
@@ -14,18 +15,85 @@ class GetCampaigns extends DirectRequest{
...
@@ -14,18 +15,85 @@ class GetCampaigns extends DirectRequest{
$this
->
next
=
$next
;
$this
->
next
=
$next
;
$this
->
requestPrepare
(
$response
);
$this
->
requestPrepare
(
$response
);
$process
=
new
ProcessCallLimitedAPI
(
$this
);
$process
=
new
ProcessCallLimitedAPI
(
$this
);
dispatch
(
$process
)
->
onQueue
(
'
api
'
);
dispatch
(
$process
)
->
onQueue
(
'
limits
'
);
}
}
function
handle
(
$response
){
function
handle
(
$response
){
echo
'get campaigns'
;
$data
=
[];
print_r
(
$response
);
foreach
(
$response
[
'result'
][
'Campaigns'
]
as
$campaign
){
$data
[]
=
[
'external_id'
=>
$campaign
[
'Id'
],
'TimeTargeting'
=>
json_encode
(
$campaign
[
'TimeTargeting'
]),
'NegativeKeywords'
=>
!
empty
(
$campaign
[
'NegativeKeywords'
][
'Items'
])
?
implode
(
"
\n
"
,
$campaign
[
'NegativeKeywords'
][
'Items'
])
:
''
,
'BlockedIps'
=>
!
empty
(
$campaign
[
'BlockedIps'
][
'Items'
])
?
implode
(
"
\n
"
,
$campaign
[
'BlockedIps'
][
'Items'
])
:
''
,
'ExcludedSites'
=>
!
empty
(
$campaign
[
'ExcludedSites'
][
'Items'
])
?
implode
(
"
\n
"
,
$campaign
[
'ExcludedSites'
][
'Items'
])
:
''
,
'DailyBudget'
=>
json_encode
(
$campaign
[
'DailyBudget'
]),
'TextCampaignStrategySearch'
=>
$campaign
[
'TextCampaign'
][
'BiddingStrategy'
][
'Search'
][
'BiddingStrategyType'
],
'TextCampaignStrategyNetwork'
=>
$campaign
[
'TextCampaign'
][
'BiddingStrategy'
][
'Network'
][
'BiddingStrategyType'
],
'Settings'
=>
json_encode
(
$campaign
[
'TextCampaign'
][
'Settings'
]),
'CounterIds'
=>
!
empty
(
$campaign
[
'TextCampaign'
][
'CounterIds'
][
'Items'
])
?
implode
(
"
\n
"
,
$campaign
[
'TextCampaign'
][
'CounterIds'
][
'Items'
])
:
''
,
'RelevantKeywordsSettingBudgetPercent'
=>
$campaign
[
'TextCampaign'
][
'RelevantKeywords'
][
'BudgetPercent'
],
'RelevantKeywordsSettingOptimizeGoalId'
=>
$campaign
[
'TextCampaign'
][
'RelevantKeywords'
][
'OptimizeGoalId'
],
'AttributionModel'
=>
$campaign
[
'TextCampaign'
][
'AttributionModel'
],
'PriorityGoals'
=>
json_encode
(
$campaign
[
'TextCampaign'
][
'PriorityGoals'
]),
];
print_r
(
$campaign
[
'Name'
]);
$camp
=
Campaigns
::
firstOrCreate
([
'external_id'
=>
$campaign
[
'Id'
]
],[
'Name'
=>
$campaign
[
'Name'
],
// 'TimeTargeting' => json_encode($campaign['TimeTargeting']),
// 'NegativeKeywords' => implode("\n", $campaign['NegativeKeywords']['Items']),
// 'BlockedIps' => implode("\n", $campaign['BlockedIps']['Items']),
// 'ExcludedSites' => implode("\n", $campaign['BlockedIps']['Items']),
// 'DailyBudget' => json_encode($campaign['DailyBudget']),
// 'TextCampaignStrategySearch' => $campaign['TextCampaign']['BiddingStrategy']['Search']['BiddingStrategyType'],
// 'TextCampaignStrategyNetwork' => $campaign['TextCampaign']['BiddingStrategy']['[Network']['BiddingStrategyType'],
// 'Settings' => json_encode($campaign['TextCampaign']['Settings']),
// 'CounterIds' => implode("\n", $campaign['TextCampaign']['CounterIds']['Items']),
// 'RelevantKeywordsSettingBudgetPercent' => $campaign['TextCampaign']['RelevantKeywords']['BudgetPercent'],
// 'RelevantKeywordsSettingOptimizeGoalId' => $campaign['TextCampaign']['RelevantKeywords']['OptimizeGoalId'],
// 'AttributionModel' => $campaign['TextCampaign']['AttributionModel'],
// 'PriorityGoals' => json_encode($campaign['TextCampaign']['PriorityGoals']),
]);
$camp
->
Name
=
$campaign
[
'Name'
];
$camp
->
save
();
}
Campaigns
::
upsert
(
$data
,
[
'external_id'
],[
'Name'
,
// 'TimeTargeting',
// 'NegativeKeywords',
// 'BlockedIps',
// 'ExcludedSites',
// 'DailyBudget',
// 'TextCampaignStrategySearch',
// 'TextCampaignStrategyNetwork',
// 'Settings',
// 'CounterIds',
// 'RelevantKeywordsSettingBudgetPercent',
// 'RelevantKeywordsSettingOptimizeGoalId',
// 'AttributionModel',
]);
}
}
private
function
requestPrepare
(
$response
){
private
function
requestPrepare
(
$response
){
$this
->
setService
(
'campaigns'
);
$this
->
setService
(
'campaigns'
);
$this
->
setMethod
(
'get'
);
$this
->
setMethod
(
'get'
);
$this
->
setTimestamp
(
$response
);
$this
->
setTimestamp
(
$response
);
$params
=
[
'SelectionCriteria'
=>
[
'Types'
=>
[
"TEXT_CAMPAIGN"
]
],
"FieldNames"
=>
[
"Id"
,
"Name"
,
"TimeTargeting"
,
"TimeZone"
,
"NegativeKeywords"
,
"BlockedIps"
,
"ExcludedSites"
,
"DailyBudget"
],
"TextCampaignFieldNames"
=>
[
"BiddingStrategy"
,
"Settings"
,
"CounterIds"
,
"RelevantKeywords"
,
"PriorityGoals"
,
"AttributionModel"
]
];
$this
->
setParams
(
$params
);
}
}
private
function
setTimestamp
(
$response
){
private
function
setTimestamp
(
$response
){
...
...
database/migrations/2021_05_11_084828_create_campaigns_table.php
0 → 100644
View file @
31f199e
<?php
use
Illuminate\Database\Migrations\Migration
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
class
CreateCampaignsTable
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
create
(
'campaigns'
,
function
(
Blueprint
$table
)
{
$table
->
id
();
$table
->
bigInteger
(
'external_id'
)
->
unique
();
$table
->
string
(
'Name'
,
255
);
$table
->
json
(
'TimeTargeting'
);
$table
->
text
(
'NegativeKeywords'
);
$table
->
text
(
'BlockedIps'
);
$table
->
text
(
'ExcludedSites'
);
$table
->
json
(
'DailyBudget'
);
$table
->
string
(
'TextCampaignStrategySearch'
);
$table
->
string
(
'TextCampaignStrategyNetwork'
);
$table
->
json
(
'Settings'
);
$table
->
text
(
'CounterIds'
);
$table
->
integer
(
'RelevantKeywordsSettingBudgetPercent'
);
$table
->
bigInteger
(
'RelevantKeywordsSettingOptimizeGoalId'
);
$table
->
string
(
'AttributionModel'
,
4
);
$table
->
json
(
'PriorityGoals'
);
$table
->
timestamps
();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
Schema
::
dropIfExists
(
'campaigns'
);
}
}
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