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 e92049f3
authored
May 20, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19465 Реализация синхронизации данных по РК
1 parent
381b24ea
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
14 deletions
app/Models/Pivots/DictionaryCampaign.php
app/Service/Requests/Direct/AddCampaigns.php
app/Service/Requests/Direct/GetCampaigns.php
tests/Unit/GetCampaignsTest.php
app/Models/Pivots/DictionaryCampaign.php
View file @
e92049f
...
...
@@ -22,8 +22,8 @@ use Illuminate\Database\Eloquent\Relations\Pivot;
* @property int $campaign_id
* @property int $dictionary_id
* @property string|null $name
* @property
string
|null $negative_keywords
* @property
string
|null $excluded_sites
* @property
array
|null $negative_keywords
* @property
array
|null $excluded_sites
* @property int $updated
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
...
...
@@ -63,7 +63,7 @@ class DictionaryCampaign extends Pivot
'external_upload_at'
,
];
protected
$cast
=
[
protected
$cast
s
=
[
'external_id'
=>
'int'
,
'campaign_id'
=>
'int'
,
'dictionary_id'
=>
'int'
,
...
...
app/Service/Requests/Direct/AddCampaigns.php
View file @
e92049f
...
...
@@ -29,6 +29,7 @@ class AddCampaigns extends DirectRequest
public
function
handle
(
$response
)
{
try
{
dd
(
$response
);
foreach
(
$response
[
'result'
][
'AddResults'
]
as
$key
=>
$add_result
)
{
$id
=
$add_result
[
'Id'
]
??
''
;
...
...
@@ -52,11 +53,6 @@ class AddCampaigns extends DirectRequest
{
$this
->
dictionaryCampaigns
=
$params
[
'dictionaryCampaigns'
];
$this
->
variables
=
$params
[
'variables'
];
$this
->
assertEquals
(
'String "custom var value"'
,
StrReplaceByVariables
::
getInstance
(
'String "%var%"'
,
$variable_list
)
->
get
());
}
private
function
requestPrepare
(
$params
)
...
...
@@ -84,11 +80,10 @@ class AddCampaigns extends DirectRequest
$variable_list
[
$variable
->
name
]
=
$value
;
}
return
[
$data
=
[
'Name'
=>
StrReplaceByVariables
::
getInstance
(
$dictionaryCampaign
->
name
,
$variable_list
)
->
get
(),
'StartDate'
=>
Carbon
::
now
()
->
format
(
'Y-m-d'
),
'
NegativeKeywords'
=>
StrReplaceByVariables
::
getInstance
(
$dictionaryCampaign
->
campaign
->
negative_keywords
,
$variable_list
)
->
get
()
,
'
DailyBudget'
=>
$dictionaryCampaign
->
campaign
->
daily_budget
,
'TextCampaign'
=>
[
'BiddingStrategy'
=>
[
'Search'
=>
[
...
...
@@ -98,8 +93,45 @@ class AddCampaigns extends DirectRequest
'BiddingStrategyType'
=>
$dictionaryCampaign
->
campaign
->
text_campaign_strategy_network
,
],
],
'Settings'
=>
$dictionaryCampaign
->
campaign
->
settings
,
'RelevantKeywords'
=>
[
'BudgetPercent'
=>
$dictionaryCampaign
->
campaign
->
relevant_keywords_setting_budget_percent
,
'OptimizeGoalId'
=>
$dictionaryCampaign
->
campaign
->
relevant_keywords_setting_optimize_goal_id
,
],
'AttributionModel'
=>
$dictionaryCampaign
->
campaign
->
attribution_model
,
'PriorityGoals'
=>
$dictionaryCampaign
->
campaign
->
priority_goals
,
],
];
if
(
count
(
$dictionaryCampaign
->
negative_keywords
))
{
$data
[
'NegativeKeywords'
]
=
[
'Items'
=>
array_map
(
function
(
$value
)
use
(
$variable_list
)
{
return
StrReplaceByVariables
::
getInstance
(
$value
,
$variable_list
)
->
get
();
},
$dictionaryCampaign
->
negative_keywords
),
];
}
if
(
count
(
$dictionaryCampaign
->
campaign
->
blocked_ips
))
{
$data
[
'BlockedIps'
]
=
[
'Items'
=>
$dictionaryCampaign
->
campaign
->
blocked_ips
,
];
}
if
(
count
(
$dictionaryCampaign
->
excluded_sites
))
{
$data
[
'ExcludedSites'
]
=
[
'Items'
=>
array_map
(
function
(
$value
)
use
(
$variable_list
)
{
return
StrReplaceByVariables
::
getInstance
(
$value
,
$variable_list
)
->
get
();
},
$dictionaryCampaign
->
excluded_sites
),
];
}
if
(
count
(
$dictionaryCampaign
->
campaign
->
counter_ids
))
{
$data
[
'TextCampaign'
][
'CounterIds'
]
=
[
'Items'
=>
$dictionaryCampaign
->
campaign
->
counter_ids
,
];
}
return
$data
;
}),
]);
}
...
...
app/Service/Requests/Direct/GetCampaigns.php
View file @
e92049f
...
...
@@ -31,7 +31,7 @@ class GetCampaigns extends DirectRequest
'negative_keywords'
=>
json_encode
(
$campaign
[
'NegativeKeywords'
][
'Items'
]
??
[]),
'blocked_ips'
=>
json_encode
(
$campaign
[
'BlockedIps'
][
'Items'
]
??
[]),
'excluded_sites'
=>
json_encode
(
$campaign
[
'ExcludedSites'
][
'Items'
]
??
[]),
'daily_budget'
=>
json_encode
(
$campaign
[
'DailyBudget'
]
[
'Items'
]
??
[]),
'daily_budget'
=>
json_encode
(
$campaign
[
'DailyBudget'
]
??
[]),
'text_campaign_strategy_search'
=>
$campaign
[
'TextCampaign'
][
'BiddingStrategy'
][
'Search'
][
'BiddingStrategyType'
],
'text_campaign_strategy_network'
=>
$campaign
[
'TextCampaign'
][
'BiddingStrategy'
][
'Network'
][
'BiddingStrategyType'
],
'settings'
=>
json_encode
(
$campaign
[
'TextCampaign'
][
'Settings'
]),
...
...
tests/Unit/GetCampaignsTest.php
View file @
e92049f
...
...
@@ -65,7 +65,10 @@ class GetCampaignsTest extends TestCase
'NegativeKeywords'
=>
[
'Items'
=>
[
1
,
2
,
3
]],
'BlockedIps'
=>
[
'Items'
=>
[
1
,
2
,
3
]],
'ExcludedSites'
=>
[
'Items'
=>
[
1
,
2
,
3
]],
'DailyBudget'
=>
[
'Items'
=>
[
1
,
2
,
3
]],
'DailyBudget'
=>
[
'Amount'
=>
123
,
'Mode'
=>
'STANDARD'
,
],
'TextCampaign'
=>
[
'BiddingStrategy'
=>
[
'Search'
=>
[
...
...
@@ -103,7 +106,7 @@ class GetCampaignsTest extends TestCase
$this
->
assertEquals
(
$campaign
->
negative_keywords
,
$data_campaign
[
'NegativeKeywords'
][
'Items'
]);
$this
->
assertEquals
(
$campaign
->
blocked_ips
,
$data_campaign
[
'BlockedIps'
][
'Items'
]);
$this
->
assertEquals
(
$campaign
->
excluded_sites
,
$data_campaign
[
'ExcludedSites'
][
'Items'
]);
$this
->
assertEquals
(
$campaign
->
daily_budget
,
$data_campaign
[
'DailyBudget'
]
[
'Items'
]
);
$this
->
assertEquals
(
$campaign
->
daily_budget
,
$data_campaign
[
'DailyBudget'
]);
$this
->
assertEquals
(
$campaign
->
text_campaign_strategy_search
,
$data_campaign
[
'TextCampaign'
][
'BiddingStrategy'
][
'Search'
][
'BiddingStrategyType'
]);
$this
->
assertEquals
(
$campaign
->
text_campaign_strategy_network
,
$data_campaign
[
'TextCampaign'
][
'BiddingStrategy'
][
'Network'
][
'BiddingStrategyType'
]);
$this
->
assertEquals
(
$campaign
->
settings
,
$data_campaign
[
'TextCampaign'
][
'Settings'
]);
...
...
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