269 lines
6.9 KiB
PHP
Executable File
269 lines
6.9 KiB
PHP
Executable File
<?php
|
|
|
|
/**
|
|
* Annunk Application Installer
|
|
*
|
|
* This script creates the complete Annunk application structure including:
|
|
* - Models with relationships
|
|
* - Controllers for Admin and SuperAdmin
|
|
* - Routes
|
|
* - Views with Tailwind CSS
|
|
* - Language files
|
|
* - Seeders
|
|
* - Services for OpenRouter and Telegram
|
|
*/
|
|
|
|
$basePath = __DIR__;
|
|
|
|
function ensureDirectory(string $path): void
|
|
{
|
|
if (!is_dir($path)) {
|
|
mkdir($path, 0755, true);
|
|
}
|
|
}
|
|
|
|
function writeFile(string $path, string $content): void
|
|
{
|
|
file_put_contents($path, $content);
|
|
echo "Created: {$path}\n";
|
|
}
|
|
|
|
// Create directories
|
|
$directories = [
|
|
'app/Http/Controllers/Admin',
|
|
'app/Http/Controllers/SuperAdmin',
|
|
'app/Http/Controllers/Api',
|
|
'app/Http/Livewire',
|
|
'app/Services',
|
|
'app/Console/Commands',
|
|
'resources/views/admin',
|
|
'resources/views/superadmin',
|
|
'resources/views/dashboard',
|
|
'resources/views/auth',
|
|
'resources/views/layouts',
|
|
'resources/views/components',
|
|
'database/seeders',
|
|
'lang/en',
|
|
'lang/pt_BR',
|
|
'lang/es',
|
|
'routes',
|
|
];
|
|
|
|
foreach ($directories as $dir) {
|
|
ensureDirectory($basePath . '/' . $dir);
|
|
}
|
|
|
|
echo "Directory structure created.\n";
|
|
|
|
// Update User model
|
|
$userModel = <<<'PHP'
|
|
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property string $name
|
|
* @property string $email
|
|
* @property \Illuminate\Support\Carbon|null $email_verified_at
|
|
* @property string $password
|
|
* @property string|null $remember_token
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @property string|null $phone
|
|
* @property string|null $locale
|
|
* @property bool $is_active
|
|
* @property bool $is_approved
|
|
* @property-read Collection<int, UserSubject> $userSubjects
|
|
* @property-read Collection<int, Insight> $insights
|
|
* @property-read Collection<int, InsightSchedule> $insightSchedules
|
|
* @property-read Collection<int, TelegramUser> $telegramUsers
|
|
* @property-read Collection<int, TokenUsage> $tokenUsages
|
|
* @property-read Collection<int, Subject> $subjects
|
|
*/
|
|
class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<\Database\Factories\UserFactory> */
|
|
use HasFactory, Notifiable, HasRoles;
|
|
|
|
/** @var array<int, string> */
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'password',
|
|
'phone',
|
|
'locale',
|
|
'is_active',
|
|
'is_approved',
|
|
];
|
|
|
|
/** @var array<string, string> */
|
|
protected $casts = [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'is_active' => 'boolean',
|
|
'is_approved' => 'boolean',
|
|
];
|
|
|
|
/** @var array<int, string> */
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
/**
|
|
* Get the user subjects for the user.
|
|
*/
|
|
public function userSubjects(): HasMany
|
|
{
|
|
return $this->hasMany(UserSubject::class);
|
|
}
|
|
|
|
/**
|
|
* Get the insights for the user.
|
|
*/
|
|
public function insights(): HasMany
|
|
{
|
|
return $this->hasMany(Insight::class);
|
|
}
|
|
|
|
/**
|
|
* Get the insight schedules for the user.
|
|
*/
|
|
public function insightSchedules(): HasMany
|
|
{
|
|
return $this->hasMany(InsightSchedule::class);
|
|
}
|
|
|
|
/**
|
|
* Get the telegram users for the user.
|
|
*/
|
|
public function telegramUsers(): HasMany
|
|
{
|
|
return $this->hasMany(TelegramUser::class);
|
|
}
|
|
|
|
/**
|
|
* Get the token usages for the user.
|
|
*/
|
|
public function tokenUsages(): HasMany
|
|
{
|
|
return $this->hasMany(TokenUsage::class);
|
|
}
|
|
|
|
/**
|
|
* Get the subjects created by the user.
|
|
*/
|
|
public function subjects(): HasMany
|
|
{
|
|
return $this->hasMany(Subject::class);
|
|
}
|
|
}
|
|
PHP;
|
|
|
|
writeFile($basePath . '/app/Models/User.php', $userModel);
|
|
|
|
// Create remaining migration files
|
|
$migrations = [
|
|
'2026_08_03_115629_create_telegram_users_table.php' => <<<'PHP'
|
|
<?php
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
return new class extends Migration
|
|
{
|
|
public function up(): void
|
|
{
|
|
Schema::create('telegram_users', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
|
$table->string('telegram_user_id')->unique();
|
|
$table->string('telegram_username')->nullable();
|
|
$table->string('telegram_first_name')->nullable();
|
|
$table->string('telegram_last_name')->nullable();
|
|
$table->boolean('is_active')->default(true);
|
|
$table->timestamps();
|
|
});
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
Schema::dropIfExists('telegram_users');
|
|
}
|
|
};
|
|
PHP,
|
|
'2026_08_03_115630_create_token_usages_table.php' => <<<'PHP'
|
|
<?php
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
return new class extends Migration
|
|
{
|
|
public function up(): void
|
|
{
|
|
Schema::create('token_usages', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
|
$table->integer('input_tokens')->default(0);
|
|
$table->integer('output_tokens')->default(0);
|
|
$table->integer('total_tokens')->default(0);
|
|
$table->string('model')->nullable();
|
|
$table->string('provider')->nullable();
|
|
$table->timestamps();
|
|
|
|
$table->index(['user_id', 'created_at']);
|
|
});
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
Schema::dropIfExists('token_usages');
|
|
}
|
|
};
|
|
PHP,
|
|
'2026_08_03_115631_add_profile_fields_to_users_table.php' => <<<'PHP'
|
|
<?php
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
return new class extends Migration
|
|
{
|
|
public function up(): void
|
|
{
|
|
Schema::table('users', function (Blueprint $table) {
|
|
$table->string('phone')->nullable()->after('email');
|
|
$table->string('locale')->default('pt_BR')->after('phone');
|
|
$table->boolean('is_active')->default(true)->after('locale');
|
|
$table->boolean('is_approved')->default(false)->after('is_active');
|
|
});
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
Schema::table('users', function (Blueprint $table) {
|
|
$table->dropColumn(['phone', 'locale', 'is_active', 'is_approved']);
|
|
});
|
|
}
|
|
};
|
|
PHP,
|
|
];
|
|
|
|
foreach ($migrations as $file => $content) {
|
|
writeFile($basePath . '/database/migrations/' . $file, $content);
|
|
}
|
|
|
|
echo "All migration files created.\n";
|