Commit 9c40e9d5 by Vladislav

#19459 Вывод для основного аккаунта списка его РК из кеша

1 parent 91e43e51
...@@ -39,7 +39,11 @@ class TokensController extends Controller ...@@ -39,7 +39,11 @@ class TokensController extends Controller
'api' => $token->api, 'api' => $token->api,
'token' => $token->token, 'token' => $token->token,
'type' => $token->type, 'type' => $token->type,
'campaigns' => ($token->type==Tokens::MAIN?[]:null), 'campaigns' => (
$token->type==Tokens::MAIN
? $token->campaigns
: null
),
'cities' => ($token->type==Tokens::GOAL?[]:null), 'cities' => ($token->type==Tokens::GOAL?[]:null),
], ],
'types' => $mainToken->count() && $token->type!=Tokens::MAIN 'types' => $mainToken->count() && $token->type!=Tokens::MAIN
......
...@@ -9,25 +9,6 @@ class Campaigns extends Model ...@@ -9,25 +9,6 @@ class Campaigns extends Model
{ {
use HasFactory; 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) public function scopeForUpdated($query)
{ {
$query->whereNotNull('updated'); $query->whereNotNull('updated');
......
...@@ -27,4 +27,9 @@ class Tokens extends Model ...@@ -27,4 +27,9 @@ class Tokens extends Model
{ {
return $this->hasMany(Limits::class, 'token', 'id')->orderBy('updated_at', 'DESC'); 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');
}
} }
...@@ -4,6 +4,7 @@ namespace App\Service\Requests\Direct; ...@@ -4,6 +4,7 @@ namespace App\Service\Requests\Direct;
use App\Jobs\ProcessCallLimitedAPI; use App\Jobs\ProcessCallLimitedAPI;
use App\Models\Campaigns; use App\Models\Campaigns;
use App\Service\Requests\DirectRequest; use App\Service\Requests\DirectRequest;
use Illuminate\Support\Facades\Log;
class GetCampaigns extends DirectRequest{ class GetCampaigns extends DirectRequest{
protected $timestamp; protected $timestamp;
...@@ -15,25 +16,26 @@ class GetCampaigns extends DirectRequest{ ...@@ -15,25 +16,26 @@ class GetCampaigns extends DirectRequest{
} }
function handle($response){ function handle($response){
try {
$data = []; $data = [];
foreach ($response['result']['Campaigns'] as $campaign){ foreach ($response['result']['Campaigns'] as $campaign){
$data[] = [ $data[] = [
'external_id' => $campaign['Id'], 'external_id' => $campaign['Id'],
'token' => $this->getToken()->id, 'token' => $this->getToken()->id,
'Name' => $campaign['Name'], 'name' => $campaign['Name'],
'TimeTargeting' => json_encode($campaign['TimeTargeting']), 'time_targeting' => json_encode($campaign['TimeTargeting']),
'NegativeKeywords' => !empty($campaign['NegativeKeywords']['Items']) ?implode("\n", $campaign['NegativeKeywords']['Items']):'', 'negative_keywords' => !empty($campaign['NegativeKeywords']['Items']) ?implode("\n", $campaign['NegativeKeywords']['Items']):'',
'BlockedIps' => !empty($campaign['BlockedIps']['Items']) ?implode("\n", $campaign['BlockedIps']['Items']):'', 'blocked_ips' => !empty($campaign['BlockedIps']['Items']) ?implode("\n", $campaign['BlockedIps']['Items']):'',
'ExcludedSites' => !empty($campaign['ExcludedSites']['Items']) ?implode("\n", $campaign['ExcludedSites']['Items']):'', 'excluded_sites' => !empty($campaign['ExcludedSites']['Items']) ?implode("\n", $campaign['ExcludedSites']['Items']):'',
'DailyBudget' => json_encode($campaign['DailyBudget']), 'daily_budget' => json_encode($campaign['DailyBudget']),
'TextCampaignStrategySearch' => $campaign['TextCampaign']['BiddingStrategy']['Search']['BiddingStrategyType'], 'text_campaign_strategy_search' => $campaign['TextCampaign']['BiddingStrategy']['Search']['BiddingStrategyType'],
'TextCampaignStrategyNetwork' => $campaign['TextCampaign']['BiddingStrategy']['Network']['BiddingStrategyType'], 'text_campaign_strategy_network' => $campaign['TextCampaign']['BiddingStrategy']['Network']['BiddingStrategyType'],
'Settings' => json_encode($campaign['TextCampaign']['Settings']), 'settings' => json_encode($campaign['TextCampaign']['Settings']),
'CounterIds' => !empty($campaign['TextCampaign']['CounterIds']['Items']) ? implode("\n", $campaign['TextCampaign']['CounterIds']['Items']): '', 'counter_ids' => !empty($campaign['TextCampaign']['CounterIds']['Items']) ? implode("\n", $campaign['TextCampaign']['CounterIds']['Items']): '',
'RelevantKeywordsSettingBudgetPercent' => $campaign['TextCampaign']['RelevantKeywords']['BudgetPercent'], 'relevant_keywords_setting_budget_percent' => $campaign['TextCampaign']['RelevantKeywords']['BudgetPercent'],
'RelevantKeywordsSettingOptimizeGoalId' => $campaign['TextCampaign']['RelevantKeywords']['OptimizeGoalId'], 'relevant_keywords_setting_optimize_goal_id' => $campaign['TextCampaign']['RelevantKeywords']['OptimizeGoalId'],
'AttributionModel' => $campaign['TextCampaign']['AttributionModel'], 'attribution_model' => $campaign['TextCampaign']['AttributionModel'],
'PriorityGoals' => json_encode($campaign['TextCampaign']['PriorityGoals']), 'priority_goals' => json_encode($campaign['TextCampaign']['PriorityGoals']),
'updated' => null 'updated' => null
]; ];
} }
...@@ -41,21 +43,24 @@ class GetCampaigns extends DirectRequest{ ...@@ -41,21 +43,24 @@ class GetCampaigns extends DirectRequest{
'external_id' 'external_id'
],[ ],[
'token', 'token',
'Name', 'name',
'TimeTargeting', 'time_targeting',
'NegativeKeywords', 'negative_keywords',
'BlockedIps', 'blocked_ips',
'ExcludedSites', 'excluded_sites',
'DailyBudget', 'daily_budget',
'TextCampaignStrategySearch', 'text_campaign_strategy_search',
'TextCampaignStrategyNetwork', 'text_campaign_strategy_network',
'Settings', 'settings',
'CounterIds', 'counter_ids',
'RelevantKeywordsSettingBudgetPercent', 'relevant_keywords_setting_budget_percent',
'RelevantKeywordsSettingOptimizeGoalId', 'relevant_keywords_setting_optimize_goal_id',
'AttributionModel', 'attribution_model',
'updated' 'updated'
]); ]);
} catch (\Exception $e) {
Log::debug($e);
}
} }
private function requestPrepare($filter){ private function requestPrepare($filter){
......
...@@ -39,12 +39,6 @@ class CreateLimitsTable extends Migration ...@@ -39,12 +39,6 @@ class CreateLimitsTable extends Migration
*/ */
public function down() 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'); Schema::dropIfExists('limits');
} }
} }
...@@ -17,20 +17,20 @@ class CreateCampaignsTable extends Migration ...@@ -17,20 +17,20 @@ class CreateCampaignsTable extends Migration
$table->id(); $table->id();
$table->bigInteger('token'); $table->bigInteger('token');
$table->bigInteger('external_id')->unique(); $table->bigInteger('external_id')->unique();
$table->string('Name', 255)->nullable(); $table->string('name', 255)->nullable();
$table->json('TimeTargeting')->nullable(); $table->json('time_targeting')->nullable();
$table->text('NegativeKeywords')->nullable(); $table->text('negative_keywords')->nullable();
$table->text('BlockedIps')->nullable(); $table->text('blocked_ips')->nullable();
$table->text('ExcludedSites')->nullable(); $table->text('excluded_sites')->nullable();
$table->json('DailyBudget')->nullable(); $table->json('daily_budget')->nullable();
$table->string('TextCampaignStrategySearch')->nullable(); $table->string('text_campaign_strategy_search')->nullable();
$table->string('TextCampaignStrategyNetwork')->nullable(); $table->string('text_campaign_strategy_network')->nullable();
$table->json('Settings')->nullable(); $table->json('settings')->nullable();
$table->text('CounterIds')->nullable(); $table->text('counter_ids')->nullable();
$table->integer('RelevantKeywordsSettingBudgetPercent')->nullable(); $table->integer('relevant_keywords_setting_budget_percent')->nullable();
$table->bigInteger('RelevantKeywordsSettingOptimizeGoalId')->nullable(); $table->bigInteger('relevant_keywords_setting_optimize_goal_id')->nullable();
$table->string('AttributionModel', 4)->nullable(); $table->string('attribution_model', 4)->nullable();
$table->json('PriorityGoals')->nullable(); $table->json('priority_goals')->nullable();
$table->enum('updated', [ $table->enum('updated', [
\App\Service\Requests\Direct\CheckCampaignsChange::CHILDREN, \App\Service\Requests\Direct\CheckCampaignsChange::CHILDREN,
\App\Service\Requests\Direct\CheckCampaignsChange::SELF, \App\Service\Requests\Direct\CheckCampaignsChange::SELF,
...@@ -49,9 +49,6 @@ class CreateCampaignsTable extends Migration ...@@ -49,9 +49,6 @@ class CreateCampaignsTable extends Migration
*/ */
public function down() public function down()
{ {
Schema::table('campaigns', function (Blueprint $table) {
$table->dropForeign('campaigns_token_foreign');
});
Schema::dropIfExists('campaigns'); Schema::dropIfExists('campaigns');
} }
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
{{ form.login }} {{ form.login }}
</h1> </h1>
<div class="bg-white rounded-md shadow overflow-hidden max-w-3xl"> <div class="bg-white rounded-md shadow overflow-hidden max-w-3xl">
<form @submit.prevent="update"> <form @submit.prevent="tokenUpdate">
<div class="p-8 -mr-6 -mb-8 flex flex-wrap"> <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" <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"/> label="Login"/>
...@@ -23,11 +23,15 @@ ...@@ -23,11 +23,15 @@
</select-input> </select-input>
</div> </div>
<div class="px-8 py-4 bg-gray-50 border-t border-gray-100 flex items-center"> <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" <button class="text-red-600 hover:underline"
type="button" @click="destroy">Delete Token tabindex="-1"
type="button"
@click="tokenDestroy"
>
Delete Token
</button> </button>
<loading-button :loading="form.processing" v-if="!this.token.type" class="btn-indigo ml-auto" type="submit">Update <loading-button :loading="form.processing" v-if="!this.token.type" class="btn-indigo ml-auto" type="submit">
Token Update Token
</loading-button> </loading-button>
</div> </div>
</form> </form>
...@@ -38,12 +42,24 @@ ...@@ -38,12 +42,24 @@
<table class="w-full whitespace-nowrap"> <table class="w-full whitespace-nowrap">
<tr class="text-left font-bold"> <tr class="text-left font-bold">
<th class="px-6 pt-6 pb-4">Name</th> <th class="px-6 pt-6 pb-4">Name</th>
<th class="px-6 pt-6 pb-4">Action</th>
</tr> </tr>
<tr v-for="campaign in token.campaigns" :key="campaign.id" <tr v-for="campaign in token.campaigns" :key="campaign.id"
class="hover:bg-gray-100 focus-within:bg-gray-100"> class="hover:bg-gray-100 focus-within:bg-gray-100">
<td class="border-t"> <td class="border-t py-3">
{{ campaign.name }} {{ campaign.name }}
</td> </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>
<tr v-if="token.campaigns.length === 0"> <tr v-if="token.campaigns.length === 0">
<td class="border-t px-6 py-4" colspan="4">No campaigns found.</td> <td class="border-t px-6 py-4" colspan="4">No campaigns found.</td>
...@@ -112,10 +128,15 @@ export default { ...@@ -112,10 +128,15 @@ export default {
} }
}, },
methods: { methods: {
update() { tokenUpdate() {
this.form.post(this.route('token.update', this.token.id)) 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?')) { if (confirm('Are you sure you want to delete this token?')) {
this.$inertia.delete(this.route('token.destroy', this.token.id)) this.$inertia.delete(this.route('token.destroy', this.token.id))
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!