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 a74e801f
authored
May 31, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19465 Реализация синхронизации данных по РК.
1 parent
a5d3b5fa
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
134 additions
and
117 deletions
app/Console/Commands/AdGroupsLoadUpdated.php
app/Console/Commands/CampaignsAdd.php
app/Console/Commands/CampaignsLoadUpdated.php
app/Console/Commands/CampaignsLoadUpdatedChildrenAdGroups.php
app/Http/Controllers/CampaignVariablesController.php
app/Models/AdGroup.php
app/Models/Campaigns.php
app/Models/Tokens.php
app/Service/Requests/Direct/AddCampaigns.php
app/Service/Requests/Direct/CheckCampaignsChange.php
app/Service/Requests/Direct/CheckChanges.php
app/Service/Requests/Direct/CheckDictionariesChange.php
app/Service/Requests/Direct/GetCampaigns.php
app/Service/Requests/Direct/ResumeCampaigns.php
app/Service/Requests/Direct/SuspendCampaigns.php
app/Service/Requests/Direct/UpdateCampaigns.php
database/migrations/2021_04_29_142844_create_tokens_table.php
database/migrations/2021_05_11_084828_create_campaigns_table.php
tests/Unit/CheckChangesAdGroupsTest.php
tests/Unit/GetCampaignsTest.php
app/Console/Commands/AdGroupsLoadUpdated.php
View file @
a74e801
...
@@ -47,11 +47,12 @@ class AdGroupsLoadUpdated extends Command
...
@@ -47,11 +47,12 @@ class AdGroupsLoadUpdated extends Command
'campaignsAdGroupsForUpdatedSelf'
=>
function
(
HasManyThrough
$query
)
{
'campaignsAdGroupsForUpdatedSelf'
=>
function
(
HasManyThrough
$query
)
{
return
$query
->
limit
(
10
);
return
$query
->
limit
(
10
);
},
},
])
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
])
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
first
();
->
first
();
if
(
!
$token
)
{
if
(
!
$token
)
{
throw
new
\Exception
(
'Не найден токен блин'
)
;
return
0
;
}
}
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
...
...
app/Console/Commands/CampaignsAdd.php
View file @
a74e801
...
@@ -48,7 +48,8 @@ class CampaignsAdd extends Command
...
@@ -48,7 +48,8 @@ class CampaignsAdd extends Command
return
$query
->
limit
(
10
);
return
$query
->
limit
(
10
);
},
},
'dictionaryCampaignsEnabledForNotExternal.campaign'
'dictionaryCampaignsEnabledForNotExternal.campaign'
])
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
])
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
->
get
();
foreach
(
$tokens
as
$token
)
{
foreach
(
$tokens
as
$token
)
{
...
...
app/Console/Commands/CampaignsLoadUpdated.php
View file @
a74e801
...
@@ -60,11 +60,6 @@ class CampaignsLoadUpdated extends Command
...
@@ -60,11 +60,6 @@ class CampaignsLoadUpdated extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
setToken
(
$token
);
$ids
=
[];
foreach
(
$campaigns
as
$campaign
)
{
$ids
[]
=
$campaign
[
'external_id'
];
}
$factory
->
getRequest
(
'campaigns'
,
'get'
)
->
call
([
$factory
->
getRequest
(
'campaigns'
,
'get'
)
->
call
([
'ids'
=>
$campaigns
->
pluck
(
'external_id'
)
->
all
(),
'ids'
=>
$campaigns
->
pluck
(
'external_id'
)
->
all
(),
]);
]);
...
...
app/Console/Commands/CampaignsLoadUpdatedChildrenAdGroups.php
View file @
a74e801
...
@@ -65,7 +65,7 @@ class CampaignsLoadUpdatedChildrenAdGroups extends Command
...
@@ -65,7 +65,7 @@ class CampaignsLoadUpdatedChildrenAdGroups extends Command
'FieldNames'
=>
[
'FieldNames'
=>
[
'AdGroupIds'
,
'AdGroupIds'
,
],
],
"Timestamp"
=>
$token
->
check_changes_ad_group_at
->
toIso8601ZuluString
(),
'Timestamp'
=>
$token
->
check_changes_ad_group_at
->
toIso8601ZuluString
(),
]);
]);
$tokens
=
Tokens
::
has
(
'dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren'
)
$tokens
=
Tokens
::
has
(
'dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren'
)
...
@@ -87,7 +87,6 @@ class CampaignsLoadUpdatedChildrenAdGroups extends Command
...
@@ -87,7 +87,6 @@ class CampaignsLoadUpdatedChildrenAdGroups extends Command
'FieldNames'
=>
[
'FieldNames'
=>
[
'AdGroupIds'
,
'AdGroupIds'
,
],
],
"Timestamp"
=>
$token
->
check_changes_at
->
toIso8601ZuluString
(),
]);
]);
}
}
...
...
app/Http/Controllers/CampaignVariablesController.php
View file @
a74e801
...
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
...
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Tokens
;
use
App\Models\Tokens
;
use
App\Models\Variable
;
use
App\Models\Variable
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Redirect
;
use
Illuminate\Support\Facades\Redirect
;
use
Illuminate\Support\Facades\Request
;
use
Illuminate\Support\Facades\Request
;
use
Inertia\Inertia
;
use
Inertia\Inertia
;
...
@@ -176,6 +177,11 @@ class CampaignVariablesController extends Controller
...
@@ -176,6 +177,11 @@ class CampaignVariablesController extends Controller
if
(
is_null
(
$value
))
{
if
(
is_null
(
$value
))
{
$dictionary_campaign
->
dictionaryCampaignVariables
()
->
where
(
'variable_id'
,
$variable_id
)
$dictionary_campaign
->
dictionaryCampaignVariables
()
->
where
(
'variable_id'
,
$variable_id
)
->
delete
();
->
delete
();
$dictionary_campaign
->
update
([
'updated_need'
=>
Carbon
::
now
(),
]);
}
else
{
}
else
{
$dictionary_campaign_variable
=
$dictionary_campaign
->
dictionaryCampaignVariables
()
->
firstWhere
(
'variable_id'
,
$variable_id
);
$dictionary_campaign_variable
=
$dictionary_campaign
->
dictionaryCampaignVariables
()
->
firstWhere
(
'variable_id'
,
$variable_id
);
...
@@ -190,6 +196,10 @@ class CampaignVariablesController extends Controller
...
@@ -190,6 +196,10 @@ class CampaignVariablesController extends Controller
]);
]);
}
}
$dictionary_campaign
->
update
([
'updated_need'
=>
Carbon
::
now
(),
]);
}
}
}
}
...
...
app/Models/AdGroup.php
View file @
a74e801
...
@@ -114,7 +114,7 @@ class AdGroup extends Model
...
@@ -114,7 +114,7 @@ class AdGroup extends Model
public
function
scopeForUpdatedSelf
(
Builder
$query
)
public
function
scopeForUpdatedSelf
(
Builder
$query
)
{
{
$query
->
whereNotNull
(
'updated_self'
);
$query
->
whereNotNull
(
"
{
$query
->
getModel
()
->
getTable
()
}
.updated_self"
);
}
}
}
}
app/Models/Campaigns.php
View file @
a74e801
...
@@ -22,12 +22,10 @@ use Illuminate\Support\Collection;
...
@@ -22,12 +22,10 @@ use Illuminate\Support\Collection;
* @property array|null $blocked_ips
* @property array|null $blocked_ips
* @property array|null $excluded_sites
* @property array|null $excluded_sites
* @property array|null $daily_budget
* @property array|null $daily_budget
* @property string|null $text_campaign_strategy_search
* @property array|null $bidding_strategy
* @property string|null $text_campaign_strategy_network
* @property array|null $settings
* @property array|null $settings
* @property array|null $counter_ids
* @property array|null $counter_ids
* @property int|null $relevant_keywords_setting_budget_percent
* @property array|null $relevant_keywords
* @property int|null $relevant_keywords_setting_optimize_goal_id
* @property string|null $attribution_model
* @property string|null $attribution_model
* @property array|null $priority_goals
* @property array|null $priority_goals
* @property string|null $updated_self
* @property string|null $updated_self
...
@@ -94,12 +92,10 @@ class Campaigns extends Model
...
@@ -94,12 +92,10 @@ class Campaigns extends Model
'blocked_ips'
,
'blocked_ips'
,
'excluded_sites'
,
'excluded_sites'
,
'daily_budget'
,
'daily_budget'
,
'text_campaign_strategy_search'
,
'bidding_strategy'
,
'text_campaign_strategy_network'
,
'settings'
,
'settings'
,
'counter_ids'
,
'counter_ids'
,
'relevant_keywords_setting_budget_percent'
,
'relevant_keywords'
,
'relevant_keywords_setting_optimize_goal_id'
,
'attribution_model'
,
'attribution_model'
,
'priority_goals'
,
'priority_goals'
,
'updated_self'
,
'updated_self'
,
...
@@ -114,8 +110,10 @@ class Campaigns extends Model
...
@@ -114,8 +110,10 @@ class Campaigns extends Model
'time_targeting'
=>
'array'
,
'time_targeting'
=>
'array'
,
'negative_keywords'
=>
'array'
,
'negative_keywords'
=>
'array'
,
'blocked_ips'
=>
'array'
,
'blocked_ips'
=>
'array'
,
'bidding_strategy'
=>
'json'
,
'settings'
=>
'array'
,
'settings'
=>
'array'
,
'counter_ids'
=>
'array'
,
'counter_ids'
=>
'array'
,
'relevant_keywords'
=>
'json'
,
'excluded_sites'
=>
'array'
,
'excluded_sites'
=>
'array'
,
'daily_budget'
=>
'array'
,
'daily_budget'
=>
'array'
,
'priority_goals'
=>
'array'
,
'priority_goals'
=>
'array'
,
...
@@ -138,12 +136,10 @@ class Campaigns extends Model
...
@@ -138,12 +136,10 @@ class Campaigns extends Model
'blocked_ips'
,
'blocked_ips'
,
'excluded_sites'
,
'excluded_sites'
,
'daily_budget'
,
'daily_budget'
,
'text_campaign_strategy_search'
,
'bidding_strategy'
,
'text_campaign_strategy_network'
,
'settings'
,
'settings'
,
'counter_ids'
,
'counter_ids'
,
'relevant_keywords_setting_budget_percent'
,
'relevant_keywords'
,
'relevant_keywords_setting_optimize_goal_id'
,
'attribution_model'
,
'attribution_model'
,
'priority_goals'
,
'priority_goals'
,
]);
]);
...
...
app/Models/Tokens.php
View file @
a74e801
...
@@ -15,9 +15,12 @@ use Illuminate\Database\Eloquent\Model;
...
@@ -15,9 +15,12 @@ use Illuminate\Database\Eloquent\Model;
* @property string $api
* @property string $api
* @property string|null $type
* @property string|null $type
* @property int $created_by
* @property int $created_by
* @property string|null $timestamp
* @property \Illuminate\Support\Carbon|null $check_changes
* @property \Illuminate\Support\Carbon $check_changes_at
* @property \Illuminate\Support\Carbon|null $check_changes_campaign
* @property \Illuminate\Support\Carbon $check_changes_campaign_at
* @property \Illuminate\Support\Carbon|null $check_changes_ad_group
* @property \Illuminate\Support\Carbon|null $check_changes_ad_group
* @property \Illuminate\Support\Carbon
|null
$check_changes_ad_group_at
* @property \Illuminate\Support\Carbon $check_changes_ad_group_at
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property int $limit
* @property int $limit
...
@@ -54,7 +57,9 @@ use Illuminate\Database\Eloquent\Model;
...
@@ -54,7 +57,9 @@ use Illuminate\Database\Eloquent\Model;
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereLimit($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereLimit($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereLogin($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereLogin($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereTimestamp($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereCheckChanges($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereCheckCampaign($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereCheckAdGroup($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereType($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereType($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Tokens whereUpdatedAt($value)
...
@@ -69,14 +74,31 @@ class Tokens extends Model
...
@@ -69,14 +74,31 @@ class Tokens extends Model
'token'
,
'token'
,
'login'
,
'login'
,
'type'
,
'type'
,
'timestamp'
,
'check_changes'
,
'check_changes_campaign'
,
'check_changes_ad_group'
,
'check_changes_ad_group'
,
];
];
protected
$casts
=
[
protected
$casts
=
[
'check_changes'
=>
'datetime'
,
'check_changes_campaign'
=>
'datetime'
,
'check_changes_ad_group'
=>
'datetime'
,
'check_changes_ad_group'
=>
'datetime'
,
];
];
public
function
getCheckChangesAtAttribute
()
{
return
$this
->
check_changes
?
$this
->
check_changes
:
Carbon
::
now
()
->
addDays
(
-
1
);
}
public
function
getCheckChangesCampaignAtAttribute
()
{
return
$this
->
check_changes_campaign
?
$this
->
check_changes_campaign
:
Carbon
::
now
()
->
addDays
(
-
1
);
}
public
function
getCheckChangesAdGroupAtAttribute
()
public
function
getCheckChangesAdGroupAtAttribute
()
{
{
return
$this
->
check_changes_ad_group
return
$this
->
check_changes_ad_group
...
@@ -114,7 +136,7 @@ class Tokens extends Model
...
@@ -114,7 +136,7 @@ class Tokens extends Model
public
function
campaignsAdGroups
()
public
function
campaignsAdGroups
()
{
{
return
$this
->
hasManyThrough
(
Campaigns
::
class
,
AdGroup
::
class
,
'token'
,
'campaign_id'
);
return
$this
->
hasManyThrough
(
AdGroup
::
class
,
Campaigns
::
class
,
'token'
,
'campaign_id'
);
}
}
public
function
campaignsAdGroupsForUpdatedSelf
()
public
function
campaignsAdGroupsForUpdatedSelf
()
...
...
app/Service/Requests/Direct/AddCampaigns.php
View file @
a74e801
...
@@ -30,11 +30,16 @@ class AddCampaigns extends DirectRequest
...
@@ -30,11 +30,16 @@ class AddCampaigns extends DirectRequest
public
function
handle
(
$response
)
public
function
handle
(
$response
)
{
{
try
{
try
{
if
(
!
isset
(
$response
[
'result'
]))
{
Log
::
debug
(
$response
);
}
foreach
(
$response
[
'result'
][
'AddResults'
]
as
$key
=>
$add_result
)
{
foreach
(
$response
[
'result'
][
'AddResults'
]
as
$key
=>
$add_result
)
{
$id
=
$add_result
[
'Id'
]
??
''
;
$id
=
$add_result
[
'Id'
]
??
''
;
if
(
!
$id
)
{
if
(
!
$id
)
{
Log
::
debug
(
"AddCampaigns, empty Id, [dictionary_campaigns.id =
{
$this
->
dictionaryCampaigns
->
get
(
$key
)
->
getKey
()
}
]"
,
$add_result
);
Log
::
debug
(
"AddCampaigns, empty Id, [dictionary_campaigns.id =
{
$this
->
dictionaryCampaigns
->
get
(
$key
)
->
getKey
()
}
]"
);
Log
::
debug
(
$add_result
);
continue
;
continue
;
}
}
...
@@ -67,18 +72,41 @@ class AddCampaigns extends DirectRequest
...
@@ -67,18 +72,41 @@ class AddCampaigns extends DirectRequest
$list
=
Variable
::
getListVariablesByDictionaryCampaign
(
$dictionaryCampaign
);
$list
=
Variable
::
getListVariablesByDictionaryCampaign
(
$dictionaryCampaign
);
$bidding_strategy
=
$dictionaryCampaign
->
campaign
->
bidding_strategy
;
if
(
isset
(
$bidding_strategy
[
'Network'
][
'NetworkDefault'
])
&&
is_null
(
$bidding_strategy
[
'Network'
][
'NetworkDefault'
][
'LimitPercent'
]))
{
unset
(
$bidding_strategy
[
'Network'
][
'NetworkDefault'
]);
}
if
(
isset
(
$bidding_strategy
[
'Network'
][
'WbMaximumClicks'
])
&&
is_null
(
$bidding_strategy
[
'Network'
][
'WbMaximumClicks'
][
'BidCeiling'
]))
{
unset
(
$bidding_strategy
[
'Network'
][
'WbMaximumClicks'
][
'BidCeiling'
]);
}
if
(
isset
(
$bidding_strategy
[
'Network'
][
'WbMaximumConversionRate'
])
&&
is_null
(
$bidding_strategy
[
'Network'
][
'WbMaximumConversionRate'
][
'BidCeiling'
]))
{
unset
(
$bidding_strategy
[
'Network'
][
'WbMaximumConversionRate'
][
'BidCeiling'
]);
}
if
(
isset
(
$bidding_strategy
[
'Network'
][
'AverageCpc'
])
&&
is_null
(
$bidding_strategy
[
'Network'
][
'AverageCpc'
][
'BidCeiling'
]))
{
unset
(
$bidding_strategy
[
'Network'
][
'AverageCpc'
][
'BidCeiling'
]);
}
if
(
isset
(
$bidding_strategy
[
'Network'
][
'WeeklyClickPackage'
])
&&
is_null
(
$bidding_strategy
[
'Network'
][
'WeeklyClickPackage'
][
'BidCeiling'
]))
{
unset
(
$bidding_strategy
[
'Network'
][
'WeeklyClickPackage'
][
'BidCeiling'
]);
}
if
(
isset
(
$bidding_strategy
[
'Network'
][
'AverageRoi'
])
&&
is_null
(
$bidding_strategy
[
'Network'
][
'AverageRoi'
][
'BidCeiling'
]))
{
unset
(
$bidding_strategy
[
'Network'
][
'AverageRoi'
][
'BidCeiling'
]);
}
if
(
isset
(
$bidding_strategy
[
'Network'
][
'PayForConversion'
])
&&
is_null
(
$bidding_strategy
[
'Network'
][
'PayForConversion'
][
'WeeklySpendLimit'
]))
{
unset
(
$bidding_strategy
[
'Network'
][
'PayForConversion'
][
'WeeklySpendLimit'
]);
}
$data
=
[
$data
=
[
'Name'
=>
StrReplaceByVariables
::
getInstance
(
$dictionaryCampaign
->
name
,
$list
)
->
get
(),
'Name'
=>
StrReplaceByVariables
::
getInstance
(
$dictionaryCampaign
->
name
,
$list
)
->
get
(),
'StartDate'
=>
Carbon
::
now
()
->
format
(
'Y-m-d'
),
'StartDate'
=>
Carbon
::
now
()
->
format
(
'Y-m-d'
),
'TextCampaign'
=>
[
'TextCampaign'
=>
[
'BiddingStrategy'
=>
[
'BiddingStrategy'
=>
$bidding_strategy
,
'Search'
=>
[
'BiddingStrategyType'
=>
$dictionaryCampaign
->
campaign
->
text_campaign_strategy_search
,
],
'Network'
=>
[
'BiddingStrategyType'
=>
$dictionaryCampaign
->
campaign
->
text_campaign_strategy_network
,
],
],
],
],
];
];
...
@@ -112,11 +140,8 @@ class AddCampaigns extends DirectRequest
...
@@ -112,11 +140,8 @@ class AddCampaigns extends DirectRequest
];
];
}
}
if
(
$dictionaryCampaign
->
campaign
->
relevant_keywords_setting_budget_percent
)
{
if
(
$dictionaryCampaign
->
campaign
->
relevant_keywords
)
{
$data
[
'TextCampaign'
][
'RelevantKeywords'
]
=
[
$data
[
'TextCampaign'
][
'RelevantKeywords'
]
=
$dictionaryCampaign
->
campaign
->
relevant_keywords
;
'BudgetPercent'
=>
$dictionaryCampaign
->
campaign
->
relevant_keywords_setting_budget_percent
,
'OptimizeGoalId'
=>
$dictionaryCampaign
->
campaign
->
relevant_keywords_setting_optimize_goal_id
,
];
}
}
if
(
$dictionaryCampaign
->
campaign
->
attribution_model
)
{
if
(
$dictionaryCampaign
->
campaign
->
attribution_model
)
{
...
...
app/Service/Requests/Direct/CheckCampaignsChange.php
View file @
a74e801
...
@@ -58,11 +58,10 @@ class CheckCampaignsChange extends DirectRequest
...
@@ -58,11 +58,10 @@ class CheckCampaignsChange extends DirectRequest
}
}
}
}
\Log
::
debug
(
$data
);
}
}
}
}
$this
->
getToken
()
->
update
([
$this
->
getToken
()
->
update
([
'
timestamp'
=>
$response
[
'result'
][
'Timestamp'
]
,
'
check_changes_campaign'
=>
Carbon
::
createFromTimestamp
(
$response
[
'result'
][
'Timestamp'
])
,
]);
]);
$this
->
setToken
(
$this
->
getToken
()
->
refresh
());
$this
->
setToken
(
$this
->
getToken
()
->
refresh
());
}
}
...
@@ -72,7 +71,7 @@ class CheckCampaignsChange extends DirectRequest
...
@@ -72,7 +71,7 @@ class CheckCampaignsChange extends DirectRequest
$this
->
setService
(
'changes'
);
$this
->
setService
(
'changes'
);
$this
->
setMethod
(
'checkCampaigns'
);
$this
->
setMethod
(
'checkCampaigns'
);
$this
->
setParams
([
$this
->
setParams
([
"Timestamp"
=>
$this
->
getToken
()
->
timestamp
'Timestamp'
=>
$this
->
getToken
()
->
check_changes_campaign_at
->
toIso8601ZuluString
(),
]);
]);
}
}
}
}
app/Service/Requests/Direct/CheckChanges.php
View file @
a74e801
...
@@ -52,6 +52,7 @@ class CheckChanges extends DirectRequest
...
@@ -52,6 +52,7 @@ class CheckChanges extends DirectRequest
}
}
if
(
isset
(
$this
->
getParams
()[
'CampaignIds'
]))
{
if
(
isset
(
$this
->
getParams
()[
'CampaignIds'
]))
{
if
(
$this
->
getToken
()
->
isMain
())
{
if
(
$this
->
getToken
()
->
isMain
())
{
Campaigns
::
whereIn
(
'external_id'
,
$this
->
getParams
()[
'CampaignIds'
])
->
update
([
Campaigns
::
whereIn
(
'external_id'
,
$this
->
getParams
()[
'CampaignIds'
])
->
update
([
'updated_children'
=>
null
,
'updated_children'
=>
null
,
...
@@ -61,17 +62,17 @@ class CheckChanges extends DirectRequest
...
@@ -61,17 +62,17 @@ class CheckChanges extends DirectRequest
'updated_children'
=>
null
,
'updated_children'
=>
null
,
]);
]);
}
}
}
$this
->
getToken
()
->
update
([
$this
->
getToken
()
->
update
([
'check_changes'
=>
[
'check_changes_ad_group'
=>
Carbon
::
createFromTimestamp
(
$response
[
'result'
][
'Timestamp'
]),
Carbon
::
createFromTimestamp
(
$response
[
'result'
][
'Timestamp'
]),
]
]);
]);
}
else
{
$this
->
getToken
()
->
update
([
$this
->
getToken
()
->
update
([
'timestamp'
=>
$response
[
'result'
][
'Timestamp'
]
,
'check_changes'
=>
Carbon
::
createFromTimestamp
(
$response
[
'result'
][
'Timestamp'
])
,
]);
]);
}
$this
->
setToken
(
$this
->
getToken
()
->
refresh
());
$this
->
setToken
(
$this
->
getToken
()
->
refresh
());
}
}
...
...
app/Service/Requests/Direct/CheckDictionariesChange.php
View file @
a74e801
...
@@ -2,8 +2,6 @@
...
@@ -2,8 +2,6 @@
namespace
App\Service\Requests\Direct
;
namespace
App\Service\Requests\Direct
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Service\API\API
;
use
App\Service\Requests\APIRequest
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\Requests\DirectRequest
;
class
CheckDictionariesChange
extends
DirectRequest
{
class
CheckDictionariesChange
extends
DirectRequest
{
...
@@ -14,8 +12,6 @@ class CheckDictionariesChange extends DirectRequest {
...
@@ -14,8 +12,6 @@ class CheckDictionariesChange extends DirectRequest {
}
}
function
handle
(
$response
){
function
handle
(
$response
){
$this
->
token
->
timestamp
=
$response
[
'result'
][
'Timestamp'
]
??
''
;
$this
->
token
->
save
();
}
}
private
function
requestPrepare
(
$params
){
private
function
requestPrepare
(
$params
){
...
...
app/Service/Requests/Direct/GetCampaigns.php
View file @
a74e801
...
@@ -22,56 +22,35 @@ class GetCampaigns extends DirectRequest
...
@@ -22,56 +22,35 @@ class GetCampaigns extends DirectRequest
function
handle
(
$response
)
function
handle
(
$response
)
{
{
try
{
try
{
$campaigns_data
=
[];
foreach
(
$response
[
'result'
][
'Campaigns'
]
as
$campaign_data
)
{
foreach
(
$response
[
'result'
][
'Campaigns'
]
as
$campaign_data
)
{
$external_id
=
$campaign_data
[
'Id'
];
$data
=
[
$data
=
[
'external_id'
=>
$
campaign_data
[
'Id'
]
,
'external_id'
=>
$
external_id
,
'token'
=>
$this
->
getToken
()
->
id
,
'token'
=>
$this
->
getToken
()
->
id
,
'name'
=>
$campaign_data
[
'Name'
],
'name'
=>
$campaign_data
[
'Name'
],
'time_targeting'
=>
json_encode
(
$campaign_data
[
'TimeTargeting'
]),
'time_targeting'
=>
$campaign_data
[
'TimeTargeting'
],
'negative_keywords'
=>
json_encode
(
$campaign_data
[
'NegativeKeywords'
][
'Items'
]
??
[]),
'negative_keywords'
=>
$campaign_data
[
'NegativeKeywords'
][
'Items'
]
??
[],
'blocked_ips'
=>
json_encode
(
$campaign_data
[
'BlockedIps'
][
'Items'
]
??
[]),
'blocked_ips'
=>
$campaign_data
[
'BlockedIps'
][
'Items'
]
??
[],
'excluded_sites'
=>
json_encode
(
$campaign_data
[
'ExcludedSites'
][
'Items'
]
??
[]),
'excluded_sites'
=>
$campaign_data
[
'ExcludedSites'
][
'Items'
]
??
[],
'daily_budget'
=>
json_encode
(
$campaign_data
[
'DailyBudget'
]
??
[]),
'daily_budget'
=>
$campaign_data
[
'DailyBudget'
],
'text_campaign_strategy_search'
=>
$campaign_data
[
'TextCampaign'
][
'BiddingStrategy'
][
'Search'
][
'BiddingStrategyType'
],
'bidding_strategy'
=>
$campaign_data
[
'TextCampaign'
][
'BiddingStrategy'
],
'text_campaign_strategy_network'
=>
$campaign_data
[
'TextCampaign'
][
'BiddingStrategy'
][
'Network'
][
'BiddingStrategyType'
],
'settings'
=>
$campaign_data
[
'TextCampaign'
][
'Settings'
],
'settings'
=>
json_encode
(
$campaign_data
[
'TextCampaign'
][
'Settings'
]
??
[]),
'counter_ids'
=>
$campaign_data
[
'TextCampaign'
][
'CounterIds'
][
'Items'
]
??
[],
'counter_ids'
=>
json_encode
(
$campaign_data
[
'TextCampaign'
][
'CounterIds'
][
'Items'
]
??
[]),
'relevant_keywords'
=>
$campaign_data
[
'TextCampaign'
][
'RelevantKeywords'
],
'relevant_keywords_setting_budget_percent'
=>
$campaign_data
[
'TextCampaign'
][
'RelevantKeywords'
][
'BudgetPercent'
]
??
null
,
'relevant_keywords_setting_optimize_goal_id'
=>
$campaign_data
[
'TextCampaign'
][
'RelevantKeywords'
][
'OptimizeGoalId'
]
??
null
,
'attribution_model'
=>
$campaign_data
[
'TextCampaign'
][
'AttributionModel'
],
'attribution_model'
=>
$campaign_data
[
'TextCampaign'
][
'AttributionModel'
],
'priority_goals'
=>
json_encode
(
$campaign_data
[
'TextCampaign'
][
'PriorityGoals'
]
??
[])
,
'priority_goals'
=>
$campaign_data
[
'TextCampaign'
][
'PriorityGoals'
]
,
'updated_self'
=>
null
,
'updated_self'
=>
null
,
'updated_children'
=>
null
,
];
];
$campaigns_data
[]
=
$data
;
}
if
(
$this
->
getToken
()
->
isMain
())
{
if
(
$this
->
getToken
()
->
isMain
())
{
Campaigns
::
upsert
(
$campaigns_data
,
[
Campaigns
::
updateOrCreate
([
'external_id'
'external_id'
=>
$external_id
],
[
],
$data
);
'token'
,
'name'
,
'time_targeting'
,
'negative_keywords'
,
'blocked_ips'
,
'excluded_sites'
,
'daily_budget'
,
'text_campaign_strategy_search'
,
'text_campaign_strategy_network'
,
'settings'
,
'counter_ids'
,
'relevant_keywords_setting_budget_percent'
,
'relevant_keywords_setting_optimize_goal_id'
,
'attribution_model'
,
'priority_goals'
,
'updated_self'
,
'updated_children'
,
]);
}
else
{
}
else
{
foreach
(
$campaigns_data
as
$campaign_data
)
{
$dictionaryCampaign
=
DictionaryCampaign
::
synchronized
()
$dictionaryCampaign
=
DictionaryCampaign
::
synchronized
()
->
find
(
$
campaign_data
[
'external_id'
]
);
->
find
(
$
external_id
);
if
(
!
$dictionaryCampaign
)
if
(
!
$dictionaryCampaign
)
continue
;
continue
;
...
@@ -80,6 +59,7 @@ class GetCampaigns extends DirectRequest
...
@@ -80,6 +59,7 @@ class GetCampaigns extends DirectRequest
$dictionaryCampaign
::
copyPropertyInCampaign
(
$campaign_data
)
$dictionaryCampaign
::
copyPropertyInCampaign
(
$campaign_data
)
);
);
}
}
}
}
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
Log
::
debug
(
$e
);
Log
::
debug
(
$e
);
...
...
app/Service/Requests/Direct/ResumeCampaigns.php
View file @
a74e801
...
@@ -24,7 +24,8 @@ class ResumeCampaigns extends DirectRequest
...
@@ -24,7 +24,8 @@ class ResumeCampaigns extends DirectRequest
$external_id
=
$resume_result
[
'Id'
]
??
''
;
$external_id
=
$resume_result
[
'Id'
]
??
''
;
if
(
!
$external_id
)
{
if
(
!
$external_id
)
{
Log
::
debug
(
"resumeCampaigns, empty Id"
,
$resume_result
);
Log
::
debug
(
"resumeCampaigns, empty Id"
);
Log
::
debug
(
$resume_result
);
continue
;
continue
;
}
}
...
...
app/Service/Requests/Direct/SuspendCampaigns.php
View file @
a74e801
...
@@ -25,7 +25,8 @@ class SuspendCampaigns extends DirectRequest
...
@@ -25,7 +25,8 @@ class SuspendCampaigns extends DirectRequest
$external_id
=
$suspend_result
[
'Id'
]
??
''
;
$external_id
=
$suspend_result
[
'Id'
]
??
''
;
if
(
!
$external_id
)
{
if
(
!
$external_id
)
{
Log
::
debug
(
"SuspendCampaigns, empty Id"
,
$suspend_result
);
Log
::
debug
(
"SuspendCampaigns, empty Id"
);
Log
::
debug
(
$suspend_result
);
continue
;
continue
;
}
}
...
...
app/Service/Requests/Direct/UpdateCampaigns.php
View file @
a74e801
...
@@ -74,18 +74,8 @@ class UpdateCampaigns extends DirectRequest
...
@@ -74,18 +74,8 @@ class UpdateCampaigns extends DirectRequest
'Name'
=>
StrReplaceByVariables
::
getInstance
(
$dictionaryCampaign
->
name
,
$list
)
->
get
(),
'Name'
=>
StrReplaceByVariables
::
getInstance
(
$dictionaryCampaign
->
name
,
$list
)
->
get
(),
'StartDate'
=>
Carbon
::
now
()
->
format
(
'Y-m-d'
),
'StartDate'
=>
Carbon
::
now
()
->
format
(
'Y-m-d'
),
'TextCampaign'
=>
[
'TextCampaign'
=>
[
'BiddingStrategy'
=>
[
'BiddingStrategy'
=>
$dictionaryCampaign
->
campaign
->
bidding_strategy
,
'Search'
=>
[
'RelevantKeywords'
=>
$dictionaryCampaign
->
campaign
->
relevant_keywords
,
'BiddingStrategyType'
=>
$dictionaryCampaign
->
campaign
->
text_campaign_strategy_search
,
],
'Network'
=>
[
'BiddingStrategyType'
=>
$dictionaryCampaign
->
campaign
->
text_campaign_strategy_network
,
],
],
'RelevantKeywords'
=>
[
'BudgetPercent'
=>
$dictionaryCampaign
->
campaign
->
relevant_keywords_setting_budget_percent
,
'OptimizeGoalId'
=>
$dictionaryCampaign
->
campaign
->
relevant_keywords_setting_optimize_goal_id
,
],
'AttributionModel'
=>
$dictionaryCampaign
->
campaign
->
attribution_model
,
'AttributionModel'
=>
$dictionaryCampaign
->
campaign
->
attribution_model
,
],
],
];
];
...
...
database/migrations/2021_04_29_142844_create_tokens_table.php
View file @
a74e801
...
@@ -21,6 +21,8 @@ class CreateTokensTable extends Migration
...
@@ -21,6 +21,8 @@ class CreateTokensTable extends Migration
$table
->
enum
(
'type'
,
[
'main'
,
'goal'
])
->
nullable
();
$table
->
enum
(
'type'
,
[
'main'
,
'goal'
])
->
nullable
();
$table
->
integer
(
'created_by'
);
$table
->
integer
(
'created_by'
);
$table
->
string
(
'timestamp'
)
->
nullable
();
$table
->
string
(
'timestamp'
)
->
nullable
();
$table
->
timestamp
(
'check_changes'
)
->
nullable
();
$table
->
timestamp
(
'check_changes_campaign'
)
->
nullable
();
$table
->
timestamp
(
'check_changes_ad_group'
)
->
nullable
();
$table
->
timestamp
(
'check_changes_ad_group'
)
->
nullable
();
$table
->
timestamps
();
$table
->
timestamps
();
...
...
database/migrations/2021_05_11_084828_create_campaigns_table.php
View file @
a74e801
...
@@ -23,12 +23,10 @@ class CreateCampaignsTable extends Migration
...
@@ -23,12 +23,10 @@ class CreateCampaignsTable extends Migration
$table
->
json
(
'blocked_ips'
)
->
nullable
();
$table
->
json
(
'blocked_ips'
)
->
nullable
();
$table
->
json
(
'excluded_sites'
)
->
nullable
();
$table
->
json
(
'excluded_sites'
)
->
nullable
();
$table
->
json
(
'daily_budget'
)
->
nullable
();
$table
->
json
(
'daily_budget'
)
->
nullable
();
$table
->
string
(
'text_campaign_strategy_search'
)
->
nullable
();
$table
->
json
(
'bidding_strategy'
)
->
nullable
();
$table
->
string
(
'text_campaign_strategy_network'
)
->
nullable
();
$table
->
json
(
'settings'
)
->
nullable
();
$table
->
json
(
'settings'
)
->
nullable
();
$table
->
json
(
'counter_ids'
)
->
nullable
();
$table
->
json
(
'counter_ids'
)
->
nullable
();
$table
->
integer
(
'relevant_keywords_setting_budget_percent'
)
->
nullable
();
$table
->
json
(
'relevant_keywords'
)
->
nullable
();
$table
->
bigInteger
(
'relevant_keywords_setting_optimize_goal_id'
)
->
nullable
();
$table
->
string
(
'attribution_model'
,
4
)
->
nullable
();
$table
->
string
(
'attribution_model'
,
4
)
->
nullable
();
$table
->
json
(
'priority_goals'
)
->
nullable
();
$table
->
json
(
'priority_goals'
)
->
nullable
();
$table
->
timestamp
(
'updated_self'
)
->
nullable
();
$table
->
timestamp
(
'updated_self'
)
->
nullable
();
...
...
tests/Unit/CheckChangesAdGroupsTest.php
View file @
a74e801
...
@@ -77,7 +77,7 @@ class CheckChangesAdGroupsTest extends TestCase
...
@@ -77,7 +77,7 @@ class CheckChangesAdGroupsTest extends TestCase
'FieldNames'
=>
[
'FieldNames'
=>
[
'AdGroupIds'
,
'AdGroupIds'
,
],
],
"Timestamp"
=>
$this
->
token_main
->
check_changes_ad_group_at
->
toIso8601ZuluString
(),
'Timestamp'
=>
$this
->
token_main
->
check_changes_ad_group_at
->
toIso8601ZuluString
(),
];
];
$this
->
request
=
APIRequest
::
getInstance
(
API
::
YANDEX
)
$this
->
request
=
APIRequest
::
getInstance
(
API
::
YANDEX
)
...
...
tests/Unit/GetCampaignsTest.php
View file @
a74e801
...
@@ -110,12 +110,12 @@ class GetCampaignsTest extends TestCase
...
@@ -110,12 +110,12 @@ class GetCampaignsTest extends TestCase
$this
->
assertEquals
(
$campaign
->
blocked_ips
,
$data_campaign
[
'BlockedIps'
][
'Items'
]);
$this
->
assertEquals
(
$campaign
->
blocked_ips
,
$data_campaign
[
'BlockedIps'
][
'Items'
]);
$this
->
assertEquals
(
$campaign
->
excluded_sites
,
$data_campaign
[
'ExcludedSites'
][
'Items'
]);
$this
->
assertEquals
(
$campaign
->
excluded_sites
,
$data_campaign
[
'ExcludedSites'
][
'Items'
]);
$this
->
assertEquals
(
$campaign
->
daily_budget
,
$data_campaign
[
'DailyBudget'
]);
$this
->
assertEquals
(
$campaign
->
daily_budget
,
$data_campaign
[
'DailyBudget'
]);
$this
->
assertEquals
(
$campaign
->
text_campaign_strategy_search
,
$data_campaign
[
'TextCampaign'
][
'BiddingStrategy'
][
'Search'
][
'BiddingStrategyType'
]);
$this
->
assertEquals
(
$campaign
->
bidding_strategy
[
'Search'
][
'BiddingStrategyType'
]
,
$data_campaign
[
'TextCampaign'
][
'BiddingStrategy'
][
'Search'
][
'BiddingStrategyType'
]);
$this
->
assertEquals
(
$campaign
->
text_campaign_strategy_network
,
$data_campaign
[
'TextCampaign'
][
'BiddingStrategy'
][
'Network'
][
'BiddingStrategyType'
]);
$this
->
assertEquals
(
$campaign
->
bidding_strategy
[
'Network'
][
'BiddingStrategyType'
]
,
$data_campaign
[
'TextCampaign'
][
'BiddingStrategy'
][
'Network'
][
'BiddingStrategyType'
]);
$this
->
assertEquals
(
$campaign
->
settings
,
$data_campaign
[
'TextCampaign'
][
'Settings'
]);
$this
->
assertEquals
(
$campaign
->
settings
,
$data_campaign
[
'TextCampaign'
][
'Settings'
]);
$this
->
assertEquals
(
$campaign
->
counter_ids
,
$data_campaign
[
'TextCampaign'
][
'CounterIds'
][
'Items'
]);
$this
->
assertEquals
(
$campaign
->
counter_ids
,
$data_campaign
[
'TextCampaign'
][
'CounterIds'
][
'Items'
]);
$this
->
assertEquals
(
$campaign
->
relevant_keywords
_setting_budget_percent
,
$data_campaign
[
'TextCampaign'
][
'RelevantKeywords'
][
'BudgetPercent'
]);
$this
->
assertEquals
(
$campaign
->
relevant_keywords
[
'BudgetPercent'
]
,
$data_campaign
[
'TextCampaign'
][
'RelevantKeywords'
][
'BudgetPercent'
]);
$this
->
assertEquals
(
$campaign
->
relevant_keywords
_setting_optimize_goal_id
,
$data_campaign
[
'TextCampaign'
][
'RelevantKeywords'
][
'OptimizeGoalId'
]);
$this
->
assertEquals
(
$campaign
->
relevant_keywords
[
'OptimizeGoalId'
]
,
$data_campaign
[
'TextCampaign'
][
'RelevantKeywords'
][
'OptimizeGoalId'
]);
$this
->
assertEquals
(
$campaign
->
attribution_model
,
$data_campaign
[
'TextCampaign'
][
'AttributionModel'
]);
$this
->
assertEquals
(
$campaign
->
attribution_model
,
$data_campaign
[
'TextCampaign'
][
'AttributionModel'
]);
$this
->
assertEquals
(
$campaign
->
priority_goals
,
$data_campaign
[
'TextCampaign'
][
'PriorityGoals'
]);
$this
->
assertEquals
(
$campaign
->
priority_goals
,
$data_campaign
[
'TextCampaign'
][
'PriorityGoals'
]);
$this
->
assertEquals
(
$campaign
->
updated_self
,
null
);
$this
->
assertEquals
(
$campaign
->
updated_self
,
null
);
...
...
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