Commit 9c40e9d5 by Vladislav

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

1 parent 91e43e51
......@@ -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
......
......@@ -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');
......
......@@ -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');
}
}
......@@ -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,25 +16,26 @@ class GetCampaigns extends DirectRequest{
}
function handle($response){
try {
$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']),
'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
];
}
......@@ -41,21 +43,24 @@ class GetCampaigns extends DirectRequest{
'external_id'
],[
'token',
'Name',
'TimeTargeting',
'NegativeKeywords',
'BlockedIps',
'ExcludedSites',
'DailyBudget',
'TextCampaignStrategySearch',
'TextCampaignStrategyNetwork',
'Settings',
'CounterIds',
'RelevantKeywordsSettingBudgetPercent',
'RelevantKeywordsSettingOptimizeGoalId',
'AttributionModel',
'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);
}
}
private function requestPrepare($filter){
......
......@@ -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');
}
}
......@@ -17,20 +17,20 @@ class CreateCampaignsTable extends Migration
$table->id();
$table->bigInteger('token');
$table->bigInteger('external_id')->unique();
$table->string('Name', 255)->nullable();
$table->json('TimeTargeting')->nullable();
$table->text('NegativeKeywords')->nullable();
$table->text('BlockedIps')->nullable();
$table->text('ExcludedSites')->nullable();
$table->json('DailyBudget')->nullable();
$table->string('TextCampaignStrategySearch')->nullable();
$table->string('TextCampaignStrategyNetwork')->nullable();
$table->json('Settings')->nullable();
$table->text('CounterIds')->nullable();
$table->integer('RelevantKeywordsSettingBudgetPercent')->nullable();
$table->bigInteger('RelevantKeywordsSettingOptimizeGoalId')->nullable();
$table->string('AttributionModel', 4)->nullable();
$table->json('PriorityGoals')->nullable();
$table->string('name', 255)->nullable();
$table->json('time_targeting')->nullable();
$table->text('negative_keywords')->nullable();
$table->text('blocked_ips')->nullable();
$table->text('excluded_sites')->nullable();
$table->json('daily_budget')->nullable();
$table->string('text_campaign_strategy_search')->nullable();
$table->string('text_campaign_strategy_network')->nullable();
$table->json('settings')->nullable();
$table->text('counter_ids')->nullable();
$table->integer('relevant_keywords_setting_budget_percent')->nullable();
$table->bigInteger('relevant_keywords_setting_optimize_goal_id')->nullable();
$table->string('attribution_model', 4)->nullable();
$table->json('priority_goals')->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');
}
}
......@@ -6,7 +6,7 @@
{{ form.login }}
</h1>
<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">
<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: {
update() {
tokenUpdate() {
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))
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!