Commit 054d90ff by Vladislav

#23510 Тестирование основного и целевого аккаунта

1 parent a70c06c9
...@@ -44,6 +44,84 @@ class TokensController extends Controller ...@@ -44,6 +44,84 @@ class TokensController extends Controller
]); ]);
} }
function goalCopy(Tokens $token)
{
if ($token->type !== $token::MAIN) {
abort(404);
}
$tokenGoal = Tokens::where('type', $token::GOAL)->where('token', $token->token)->first();
if ($tokenGoal) {
return Redirect::route('token.edit', $tokenGoal->getKey());
}
$tokenGoal = $token->replicate();
$tokenGoal->type = $token::GOAL;
$tokenGoal->save();
return Redirect::route('token.edit', $tokenGoal->getKey())->with('success', 'Token added.');
$variables = Variable::all();
$lists = [];
return Inertia::render('Tokens/Edit', [
'token' => [
'id' => $token->getKey(),
'login' => $token->login,
'api' => $token->api,
'token' => $token->token,
'type' => $token->type,
'main' => $token->isMain(),
'limit_to_run' => $token->limit_to_run,
'allow_retargeting_load' => $token->allow_retargeting_load,
'errors_count' => $token->errors_count,
'campaigns' => (
$token->isMain()
? $token->campaignsForManaged
: []
),
'cities' => (
!$token->isMain()
? $token->load('cities.dictionaryCampaigns')->cities->transform(function ($city) use ($variables, &$lists) {
$city->dictionaryCampaigns->transform(function ($dictionaryCampaign) use ($variables, &$lists) {
if (!isset($lists[$dictionaryCampaign->getKey()])) {
$list = Variable::getListVariablesByDictionaryCampaign($dictionaryCampaign->getKey(), $variables);
$lists[$dictionaryCampaign->getKey()] = $list;
} else {
$list = $lists[$dictionaryCampaign->getKey()];
}
$dictionaryCampaign->name = StrReplaceByVariables::getInstance($dictionaryCampaign->name, $list)->get();
return $dictionaryCampaign;
});
return $city;
})
: []
),
],
'cities' => (
!$token->isMain()
? Dictionary::where('type', Dictionary::CITY)->defaultOrderBy()->get()
: []
),
'campaigns' => $token->campaigns,
'main_token_campaigns' => (
$mainToken
? $mainToken->campaignsForManaged
: []
),
'types' => $mainToken && !$token->type === Tokens::GOAL
? [Tokens::GOAL => 'Целевой аккаунт'] :
[Tokens::MAIN => 'Основной аккаунт', Tokens::GOAL => 'Целевой аккаунт'],
]);
}
function edit(Tokens $token) function edit(Tokens $token)
{ {
$token->loadCount('errors'); $token->loadCount('errors');
......
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class ChangeTokensColumnToken extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('tokens', function (Blueprint $table) {
$table->dropUnique('tokens_token_unique');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('tokens', function (Blueprint $table) {
$table->unique('token');
});
}
}
...@@ -43,6 +43,14 @@ ...@@ -43,6 +43,14 @@
> >
Delete Token Delete Token
</button> </button>
<inertia-link v-if="form.type === 'main'"
class="hover:underline ml-28"
tabindex="-1"
type="button"
:href="route('token.goal.copy', token.id)"
>
Копировать целевой токен
</inertia-link>
<loading-button :loading="form.processing" class="btn-indigo ml-auto" type="submit"> <loading-button :loading="form.processing" class="btn-indigo ml-auto" type="submit">
Update Token Update Token
</loading-button> </loading-button>
......
...@@ -164,6 +164,9 @@ Route::group(['middleware' => 'auth'], function () { ...@@ -164,6 +164,9 @@ Route::group(['middleware' => 'auth'], function () {
Route::post('tokens', [TokensController::class, 'cronSyncUpdate']) Route::post('tokens', [TokensController::class, 'cronSyncUpdate'])
->name('cron_sync_update'); ->name('cron_sync_update');
Route::get('token/goal/copy/{token}', [TokensController::class, 'goalCopy'])
->name('token.goal.copy');
Route::get('token/edit/{token}', [TokensController::class, 'edit']) Route::get('token/edit/{token}', [TokensController::class, 'edit'])
->name('token.edit'); ->name('token.edit');
Route::get('token/errors/{token}', [TokensController::class, 'errors']) Route::get('token/errors/{token}', [TokensController::class, 'errors'])
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!