commit 12.01

This commit is contained in:
Владимир
2026-01-12 14:25:15 +00:00
parent 36084ba590
commit ae5ab2554b
26 changed files with 1116 additions and 1083 deletions

View File

@@ -6,45 +6,21 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
public function up()
{
//таблица user
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->enum('role',['client','admin'])->default('client');
$table->enum('role', ['client', 'employee', 'admin'])->default('client');
$table->string('phone')->nullable();
$table->timestamps();
});
Schema::create('password_reset_tokens', function (Blueprint $table) {
$table->string('email')->primary();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->longText('payload');
$table->integer('last_activity')->index();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
public function down()
{
Schema::dropIfExists('users');
Schema::dropIfExists('password_reset_tokens');
Schema::dropIfExists('sessions');
}
};
};

View File

@@ -6,30 +6,21 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
public function up()
{
Schema::create('services', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->text('description')->nullable();
$table->decimal('price', 10, 2);
$table->integer('duration_minutes');
$table->unsignedBigInteger('category_id');
$table->string('image_url')->nullable();
$table->decimal('price', 10, 2);
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
public function down()
{
Schema::dropIfExists('services');
}
};
};

View File

@@ -1,24 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up() {
return new class extends Migration
{
public function up()
{
Schema::create('employee_availabilities', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('employee_id');
$table->date('date');
$table->time('starttime');
$table->time('endtime');
$table->boolean('isavailable')->default(true);
$table->timestamps(); // автоматическое создание created_at и updated_at
$table->time('start_time');
$table->time('end_time');
$table->boolean('is_available')->default(true);
$table->timestamps();
$table->foreign('employee_id')->references('id')->on('users');
});
}
public function down() {
public function down()
{
Schema::dropIfExists('employee_availabilities');
}
};
};

View File

@@ -1,35 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up() {
return new class extends Migration
{
public function up()
{
Schema::create('bookings', function (Blueprint $table) {
$table->id();
$table->string('bookingnumber');
$table->string('booking_number')->unique();
$table->unsignedBigInteger('client_id');
$table->unsignedBigInteger('employee_id');
$table->unsignedBigInteger('employee_id');
$table->unsignedBigInteger('service_id');
$table->date('bookingdate');
$table->time('starttime');
$table->time('endtime');
$table->date('booking_date');
$table->time('start_time');
$table->time('end_time');
$table->enum('status', ['confirmed', 'cancelled', 'completed'])->default('confirmed');
$table->enum('cancelledby', ['client', 'admin'])->nullable();
$table->text('cancelreason')->nullable();
$table->enum('cancelled_by', ['client', 'admin'])->nullable();
$table->text('cancel_reason')->nullable();
$table->timestamps();
// Внешние ключи
$table->foreign('client_id')->references('id')->on('users');
$table->foreign('employee_id')->references('id')->on('users');
$table->foreign('employee_id')->references('id')->on('users');
$table->foreign('service_id')->references('id')->on('services');
// УНИКАЛЬНЫЙ ИНДЕКС
$table->unique(['employee_id', 'bookingdate', 'starttime'], 'unique_booking_slot');
$table->unique(['employee_id', 'booking_date', 'start_time']);
});
}
public function down() {
public function down()
{
Schema::dropIfExists('bookings');
}
};
};

View File

@@ -2,24 +2,71 @@
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\User;
use App\Models\Service;
use App\Models\EmployeeAvailability;
use App\Models\Booking;
class DatabaseSeeder extends Seeder
{
use WithoutModelEvents;
/**
* Seed the application's database.
*/
public function run(): void
public function run()
{
// User::factory(10)->create();
// Создаём админа
User::create([
'name' => 'Админ',
'email' => 'admin@example.com',
'password' => bcrypt('123'),
'role' => 'admin'
]);
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
// Создаём сотрудника
User::create([
'name' => 'Иван Петров',
'email' => 'ivan@example.com',
'password' => bcrypt('2001'),
'role' => 'employee'
]);
// Создаём клиента
User::create([
'name' => 'Мария Иванова',
'email' => 'maria@example.com',
'password' => bcrypt('2002'),
'role' => 'client'
]);
// Создаём услугу
Service::create([
'name' => 'Генеральная уборка',
'description' => 'Полная уборка помещения.',
'duration_minutes' => 180,
'price' => 5000.00,
'is_active' => true
]);
// Создаём расписание для сотрудника
EmployeeAvailability::create([
'employee_id' => 2, // Иван Петров
'date' => '2026-02-10',
'start_time' => '09:00:00',
'end_time' => '18:00:00',
'is_available' => true
]);
// Создаём бронирование
Booking::create([
'booking_number' => 'CL-2026-0001',
'client_id' => 3, // Мария Иванова
'employee_id' => 2, // Иван Петров
'service_id' => 1, // Генеральная уборка
'booking_date' => '2026-01-15',
'start_time' => '10:00:00',
'end_time' => '13:00:00',
'status' => 'confirmed'
]);
}
}
}