first&last
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\ActivityLog;
|
||||
use App\Models\Equipment;
|
||||
use App\Models\Priority;
|
||||
use App\Models\RequestComment;
|
||||
use App\Models\RequestType;
|
||||
use App\Models\ServiceRequest;
|
||||
use App\Models\Status;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class ServiceRequestSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$types = RequestType::query()->get();
|
||||
$priorities = Priority::query()->orderBy('level')->get();
|
||||
$statuses = Status::query()->get();
|
||||
$clients = User::query()->where('role', 'client')->get();
|
||||
$techs = User::query()->where('role', 'technician')->get();
|
||||
$equipment = Equipment::query()->get();
|
||||
|
||||
for ($i = 1; $i <= 25; $i++) {
|
||||
$type = $types->random();
|
||||
$priority = $priorities->random();
|
||||
$status = $statuses->random();
|
||||
$client = $clients->random();
|
||||
$assignee = $techs->random();
|
||||
$createdAt = now()->subDays(rand(0, 20))->subHours(rand(0, 23));
|
||||
$deadlineAt = (clone $createdAt)->addHours($type->sla_hours);
|
||||
|
||||
$request = ServiceRequest::query()->create([
|
||||
'ticket_number' => sprintf('SRV-%04d', $i),
|
||||
'title' => fake()->randomElement([
|
||||
'Не включается рабочая станция',
|
||||
'Проблема с печатью документов',
|
||||
'Нет доступа к корпоративной сети',
|
||||
'Требуется установка ПО',
|
||||
'Сильный шум вентилятора',
|
||||
]),
|
||||
'description' => fake()->paragraph(3),
|
||||
'type_id' => $type->id,
|
||||
'priority_id' => $priority->id,
|
||||
'status_id' => $status->id,
|
||||
'client_id' => $client->id,
|
||||
'assigned_to' => $assignee->id,
|
||||
'equipment_id' => rand(0, 100) > 20 ? $equipment->random()?->id : null,
|
||||
'location' => fake()->randomElement(['Офис 101', 'Офис 204', 'Склад', 'Переговорная 2']),
|
||||
'planned_at' => rand(0, 100) > 50 ? $createdAt->copy()->addHours(rand(2, 24)) : null,
|
||||
'deadline_at' => $deadlineAt,
|
||||
'started_at' => rand(0, 100) > 40 ? $createdAt->copy()->addHours(rand(1, 8)) : null,
|
||||
'completed_at' => $status->is_final ? $deadlineAt->copy()->subHours(rand(0, 6)) : null,
|
||||
'resolution_notes' => $status->slug === 'resolved' || $status->slug === 'closed'
|
||||
? fake()->sentence(12)
|
||||
: null,
|
||||
'client_rating' => $status->slug === 'closed' ? rand(3, 5) : null,
|
||||
'client_comment' => $status->slug === 'closed' ? fake()->sentence() : null,
|
||||
'created_at' => $createdAt,
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
for ($commentIndex = 1; $commentIndex <= rand(1, 3); $commentIndex++) {
|
||||
$author = rand(0, 1) ? $client : $assignee;
|
||||
RequestComment::query()->create([
|
||||
'request_id' => $request->id,
|
||||
'user_id' => $author->id,
|
||||
'body' => fake()->sentence(rand(10, 20)),
|
||||
'is_internal' => $author->role !== 'client' && rand(0, 100) > 60,
|
||||
'created_at' => $createdAt->copy()->addHours($commentIndex),
|
||||
'updated_at' => $createdAt->copy()->addHours($commentIndex),
|
||||
]);
|
||||
}
|
||||
|
||||
ActivityLog::query()->create([
|
||||
'user_id' => $assignee->id,
|
||||
'model_type' => ServiceRequest::class,
|
||||
'model_id' => $request->id,
|
||||
'action' => 'created',
|
||||
'description' => "Создана заявка {$request->ticket_number}",
|
||||
'ip_address' => '127.0.0.1',
|
||||
'created_at' => $createdAt,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user