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 9c40e9d5
authored
May 12, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19459 Вывод для основного аккаунта списка его РК из кеша
1 parent
91e43e51
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
101 additions
and
94 deletions
app/Http/Controllers/TokensController.php
app/Models/Campaigns.php
app/Models/Tokens.php
app/Service/Requests/Direct/GetCampaigns.php
database/migrations/2021_05_04_140851_create_limits_table.php
database/migrations/2021_05_11_084828_create_campaigns_table.php
resources/js/Pages/Tokens/Edit.vue
app/Http/Controllers/TokensController.php
View file @
9c40e9d
...
...
@@ -39,7 +39,11 @@ class TokensController extends Controller
'api'
=>
$token
->
api
,
'token'
=>
$token
->
token
,
'type'
=>
$token
->
type
,
'campaigns'
=>
(
$token
->
type
==
Tokens
::
MAIN
?
[]
:
null
),
'campaigns'
=>
(
$token
->
type
==
Tokens
::
MAIN
?
$token
->
campaigns
:
null
),
'cities'
=>
(
$token
->
type
==
Tokens
::
GOAL
?
[]
:
null
),
],
'types'
=>
$mainToken
->
count
()
&&
$token
->
type
!=
Tokens
::
MAIN
...
...
app/Models/Campaigns.php
View file @
9c40e9d
...
...
@@ -9,25 +9,6 @@ class Campaigns extends Model
{
use
HasFactory
;
protected
$fillable
=
[
'external_id'
,
'Name'
,
'token'
,
'TimeTargeting'
,
'NegativeKeywords'
,
'BlockedIps'
,
'ExcludedSites'
,
'DailyBudget'
,
'TextCampaignStrategySearch'
,
'TextCampaignStrategyNetwork'
,
'Settings'
,
'CounterIds'
,
'RelevantKeywordsSettingBudgetPercent'
,
'RelevantKeywordsSettingOptimizeGoalId'
,
'AttributionModel'
,
'updated'
];
public
function
scopeForUpdated
(
$query
)
{
$query
->
whereNotNull
(
'updated'
);
...
...
app/Models/Tokens.php
View file @
9c40e9d
...
...
@@ -27,4 +27,9 @@ class Tokens extends Model
{
return
$this
->
hasMany
(
Limits
::
class
,
'token'
,
'id'
)
->
orderBy
(
'updated_at'
,
'DESC'
);
}
public
function
campaigns
()
{
return
$this
->
hasMany
(
Campaigns
::
class
,
'token'
,
'id'
)
->
orderBy
(
'updated_at'
,
'DESC'
);
}
}
app/Service/Requests/Direct/GetCampaigns.php
View file @
9c40e9d
...
...
@@ -4,6 +4,7 @@ namespace App\Service\Requests\Direct;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Campaigns
;
use
App\Service\Requests\DirectRequest
;
use
Illuminate\Support\Facades\Log
;
class
GetCampaigns
extends
DirectRequest
{
protected
$timestamp
;
...
...
@@ -15,47 +16,51 @@ class GetCampaigns extends DirectRequest{
}
function
handle
(
$response
){
$data
=
[];
foreach
(
$response
[
'result'
][
'Campaigns'
]
as
$campaign
){
$data
[]
=
[
'external_id'
=>
$campaign
[
'Id'
],
'token'
=>
$this
->
getToken
()
->
id
,
'Name'
=>
$campaign
[
'Name'
],
'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'
]),
'updated'
=>
null
];
try
{
$data
=
[];
foreach
(
$response
[
'result'
][
'Campaigns'
]
as
$campaign
){
$data
[]
=
[
'external_id'
=>
$campaign
[
'Id'
],
'token'
=>
$this
->
getToken
()
->
id
,
'name'
=>
$campaign
[
'Name'
],
'time_targeting'
=>
json_encode
(
$campaign
[
'TimeTargeting'
]),
'negative_keywords'
=>
!
empty
(
$campaign
[
'NegativeKeywords'
][
'Items'
])
?
implode
(
"
\n
"
,
$campaign
[
'NegativeKeywords'
][
'Items'
])
:
''
,
'blocked_ips'
=>
!
empty
(
$campaign
[
'BlockedIps'
][
'Items'
])
?
implode
(
"
\n
"
,
$campaign
[
'BlockedIps'
][
'Items'
])
:
''
,
'excluded_sites'
=>
!
empty
(
$campaign
[
'ExcludedSites'
][
'Items'
])
?
implode
(
"
\n
"
,
$campaign
[
'ExcludedSites'
][
'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'
]),
'counter_ids'
=>
!
empty
(
$campaign
[
'TextCampaign'
][
'CounterIds'
][
'Items'
])
?
implode
(
"
\n
"
,
$campaign
[
'TextCampaign'
][
'CounterIds'
][
'Items'
])
:
''
,
'relevant_keywords_setting_budget_percent'
=>
$campaign
[
'TextCampaign'
][
'RelevantKeywords'
][
'BudgetPercent'
],
'relevant_keywords_setting_optimize_goal_id'
=>
$campaign
[
'TextCampaign'
][
'RelevantKeywords'
][
'OptimizeGoalId'
],
'attribution_model'
=>
$campaign
[
'TextCampaign'
][
'AttributionModel'
],
'priority_goals'
=>
json_encode
(
$campaign
[
'TextCampaign'
][
'PriorityGoals'
]),
'updated'
=>
null
];
}
Campaigns
::
upsert
(
$data
,
[
'external_id'
],[
'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'
,
'updated'
]);
}
catch
(
\Exception
$e
)
{
Log
::
debug
(
$e
);
}
Campaigns
::
upsert
(
$data
,
[
'external_id'
],[
'token'
,
'Name'
,
'TimeTargeting'
,
'NegativeKeywords'
,
'BlockedIps'
,
'ExcludedSites'
,
'DailyBudget'
,
'TextCampaignStrategySearch'
,
'TextCampaignStrategyNetwork'
,
'Settings'
,
'CounterIds'
,
'RelevantKeywordsSettingBudgetPercent'
,
'RelevantKeywordsSettingOptimizeGoalId'
,
'AttributionModel'
,
'updated'
]);
}
private
function
requestPrepare
(
$filter
){
...
...
@@ -63,12 +68,12 @@ class GetCampaigns extends DirectRequest{
$this
->
setMethod
(
'get'
);
$params
=
[
'SelectionCriteria'
=>
[
'Types'
=>
[
"TEXT_CAMPAIGN"
]
'Types'
=>
[
"TEXT_CAMPAIGN"
]
],
"FieldNames"
=>
[
"FieldNames"
=>
[
"Id"
,
"Name"
,
"TimeTargeting"
,
"TimeZone"
,
"NegativeKeywords"
,
"BlockedIps"
,
"ExcludedSites"
,
"DailyBudget"
],
"TextCampaignFieldNames"
=>
[
"TextCampaignFieldNames"
=>
[
"BiddingStrategy"
,
"Settings"
,
"CounterIds"
,
"RelevantKeywords"
,
"PriorityGoals"
,
"AttributionModel"
]
];
...
...
database/migrations/2021_05_04_140851_create_limits_table.php
View file @
9c40e9d
...
...
@@ -39,12 +39,6 @@ class CreateLimitsTable extends Migration
*/
public
function
down
()
{
Schema
::
table
(
'limits'
,
function
(
Blueprint
$table
)
{
$table
->
dropForeign
(
'limits_token_foreign'
);
});
Schema
::
table
(
'tokens'
,
function
(
Blueprint
$table
)
{
$table
->
dropColumn
(
'limit'
);
});
Schema
::
dropIfExists
(
'limits'
);
}
}
database/migrations/2021_05_11_084828_create_campaigns_table.php
View file @
9c40e9d
...
...
@@ -17,20 +17,20 @@ class CreateCampaignsTable extends Migration
$table
->
id
();
$table
->
bigInteger
(
'token'
);
$table
->
bigInteger
(
'external_id'
)
->
unique
();
$table
->
string
(
'
N
ame'
,
255
)
->
nullable
();
$table
->
json
(
'
TimeT
argeting'
)
->
nullable
();
$table
->
text
(
'
NegativeK
eywords'
)
->
nullable
();
$table
->
text
(
'
BlockedI
ps'
)
->
nullable
();
$table
->
text
(
'
ExcludedS
ites'
)
->
nullable
();
$table
->
json
(
'
DailyB
udget'
)
->
nullable
();
$table
->
string
(
'
TextCampaignStrategyS
earch'
)
->
nullable
();
$table
->
string
(
'
TextCampaignStrategyN
etwork'
)
->
nullable
();
$table
->
json
(
'
S
ettings'
)
->
nullable
();
$table
->
text
(
'
CounterI
ds'
)
->
nullable
();
$table
->
integer
(
'
RelevantKeywordsSettingBudgetP
ercent'
)
->
nullable
();
$table
->
bigInteger
(
'
RelevantKeywordsSettingOptimizeGoalI
d'
)
->
nullable
();
$table
->
string
(
'
AttributionM
odel'
,
4
)
->
nullable
();
$table
->
json
(
'
PriorityG
oals'
)
->
nullable
();
$table
->
string
(
'
n
ame'
,
255
)
->
nullable
();
$table
->
json
(
'
time_t
argeting'
)
->
nullable
();
$table
->
text
(
'
negative_k
eywords'
)
->
nullable
();
$table
->
text
(
'
blocked_i
ps'
)
->
nullable
();
$table
->
text
(
'
excluded_s
ites'
)
->
nullable
();
$table
->
json
(
'
daily_b
udget'
)
->
nullable
();
$table
->
string
(
'
text_campaign_strategy_s
earch'
)
->
nullable
();
$table
->
string
(
'
text_campaign_strategy_n
etwork'
)
->
nullable
();
$table
->
json
(
'
s
ettings'
)
->
nullable
();
$table
->
text
(
'
counter_i
ds'
)
->
nullable
();
$table
->
integer
(
'
relevant_keywords_setting_budget_p
ercent'
)
->
nullable
();
$table
->
bigInteger
(
'
relevant_keywords_setting_optimize_goal_i
d'
)
->
nullable
();
$table
->
string
(
'
attribution_m
odel'
,
4
)
->
nullable
();
$table
->
json
(
'
priority_g
oals'
)
->
nullable
();
$table
->
enum
(
'updated'
,
[
\App\Service\Requests\Direct\CheckCampaignsChange
::
CHILDREN
,
\App\Service\Requests\Direct\CheckCampaignsChange
::
SELF
,
...
...
@@ -49,9 +49,6 @@ class CreateCampaignsTable extends Migration
*/
public
function
down
()
{
Schema
::
table
(
'campaigns'
,
function
(
Blueprint
$table
)
{
$table
->
dropForeign
(
'campaigns_token_foreign'
);
});
Schema
::
dropIfExists
(
'campaigns'
);
}
}
resources/js/Pages/Tokens/Edit.vue
View file @
9c40e9d
...
...
@@ -6,7 +6,7 @@
{{
form
.
login
}}
</h1>
<div
class=
"bg-white rounded-md shadow overflow-hidden max-w-3xl"
>
<form
@
submit
.
prevent=
"
u
pdate"
>
<form
@
submit
.
prevent=
"
tokenU
pdate"
>
<div
class=
"p-8 -mr-6 -mb-8 flex flex-wrap"
>
<text-input
v-model=
"form.login"
:error=
"form.errors.login"
:readonly=
"true"
class=
"pr-6 pb-8 w-full lg:w-1/2"
label=
"Login"
/>
...
...
@@ -23,11 +23,15 @@
</select-input>
</div>
<div
class=
"px-8 py-4 bg-gray-50 border-t border-gray-100 flex items-center"
>
<button
class=
"text-red-600 hover:underline"
tabindex=
"-1"
type=
"button"
@
click=
"destroy"
>
Delete Token
<button
class=
"text-red-600 hover:underline"
tabindex=
"-1"
type=
"button"
@
click=
"tokenDestroy"
>
Delete Token
</button>
<loading-button
:loading=
"form.processing"
v-if=
"!this.token.type"
class=
"btn-indigo ml-auto"
type=
"submit"
>
Update
Token
<loading-button
:loading=
"form.processing"
v-if=
"!this.token.type"
class=
"btn-indigo ml-auto"
type=
"submit"
>
Update
Token
</loading-button>
</div>
</form>
...
...
@@ -38,12 +42,24 @@
<table
class=
"w-full whitespace-nowrap"
>
<tr
class=
"text-left font-bold"
>
<th
class=
"px-6 pt-6 pb-4"
>
Name
</th>
<th
class=
"px-6 pt-6 pb-4"
>
Action
</th>
</tr>
<tr
v-for=
"campaign in token.campaigns"
:key=
"campaign.id"
class=
"hover:bg-gray-100 focus-within:bg-gray-100"
>
<td
class=
"border-t"
>
<td
class=
"border-t
py-3
"
>
{{
campaign
.
name
}}
</td>
<td
class=
"border-t py-3"
>
<input
:id=
"'campaign-enabled-' + campaign.id"
type=
"checkbox"
>
<label
:for=
"'campaign-enabled-' + campaign.id"
>
Enabled
</label>
<button
class=
"text-red-600 hover:underline"
tabindex=
"-1"
type=
"button"
@
click=
"campaignDestroy"
>
Delete Campaign
</button>
</td>
</tr>
<tr
v-if=
"token.campaigns.length === 0"
>
<td
class=
"border-t px-6 py-4"
colspan=
"4"
>
No campaigns found.
</td>
...
...
@@ -112,10 +128,15 @@ export default {
}
},
methods
:
{
u
pdate
()
{
tokenU
pdate
()
{
this
.
form
.
post
(
this
.
route
(
'token.update'
,
this
.
token
.
id
))
},
destroy
()
{
tokenDestroy
()
{
if
(
confirm
(
'Are you sure you want to delete this token?'
))
{
this
.
$inertia
.
delete
(
this
.
route
(
'token.destroy'
,
this
.
token
.
id
))
}
},
campaignDestroy
()
{
if
(
confirm
(
'Are you sure you want to delete this token?'
))
{
this
.
$inertia
.
delete
(
this
.
route
(
'token.destroy'
,
this
.
token
.
id
))
}
...
...
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