This commit is contained in:
Mark Gregory
2026-06-15 17:55:36 +01:00
parent 578a977c59
commit 0a9746fa77
25 changed files with 844 additions and 106 deletions
+17 -2
View File
@@ -7,6 +7,7 @@ namespace Modules\Helpdesk\Services;
use App\Models\User;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Modules\Helpdesk\Models\Comment;
use Modules\Helpdesk\Models\Status;
use Modules\Helpdesk\Models\Ticket;
@@ -33,7 +34,17 @@ final class TicketService
{
return DB::transaction(function () use ($user, $data, $files): Ticket {
$defaultStatusSlug = (string) config('helpdesk.default_status_slug', 'new');
$status = Status::query()->where('slug', $defaultStatusSlug)->first();
$status = ! empty($data['status_id'])
? Status::query()->whereKey((int) $data['status_id'])->first()
: null;
if (! $status && Schema::hasTable('helpdesk_statuses') && Schema::hasColumn('helpdesk_statuses', 'is_default')) {
$status = Status::query()->where('is_default', true)->orderBy('sort_order')->first();
}
if (! $status) {
$status = Status::query()->where('slug', $defaultStatusSlug)->first();
}
if (! $status) {
$status = Status::query()->create([
@@ -63,12 +74,16 @@ final class TicketService
'last_activity_at' => now(),
]);
if (! empty($data['tag_ids']) && is_array($data['tag_ids'])) {
$ticket->tags()->sync(array_values(array_unique(array_map('intval', $data['tag_ids']))));
}
$ticket = $this->automation->apply($ticket, $data);
$ticket = $this->sla->applyPolicy($ticket);
$this->checklists->applyTemplates($ticket);
$this->attachments->storeMany($ticket, $files, (int) $user->id);
$ticket = $ticket->fresh(['owner', 'agent', 'status', 'priority', 'category', 'project', 'team', 'product', 'attachments', 'checklistItems']) ?? $ticket;
$ticket = $ticket->fresh(['owner', 'agent', 'status', 'priority', 'category', 'project', 'team', 'product', 'tags', 'attachments', 'checklistItems']) ?? $ticket;
$this->workflow->dispatch($ticket, 'ticket.created', $user);
return $ticket;