update vm ticket
This commit is contained in:
@@ -5,6 +5,10 @@ namespace App\Http\Controllers\Api\Client\Ticket;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Api\Ticket\TicketResource;
|
||||
use App\Http\Resources\Api\Ticket\TicketReplyResource;
|
||||
use App\Jobs\Ticket\TicketJobs;
|
||||
use App\Mail\TicketCreated;
|
||||
use App\Mail\Admin\TicketAdminNotification;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\Notification;
|
||||
use App\Models\TicketReply;
|
||||
@@ -12,6 +16,8 @@ use App\Events\TicketReplyCreated;
|
||||
use App\Repositories\Ticket\TicketRepositoryInterface;
|
||||
use App\Repositories\TicketReply\TicketReplyRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class TicketController extends Controller
|
||||
@@ -60,22 +66,41 @@ class TicketController extends Controller
|
||||
'description' => ['required', 'string', 'min:20'],
|
||||
'room' => ['nullable', 'string'],
|
||||
'data' => ['nullable', 'array'],
|
||||
'images' => ['nullable', 'array', 'max:5'],
|
||||
'images.*' => ['image', 'mimes:jpg,jpeg,png,gif,webp', 'max:5120'],
|
||||
]);
|
||||
|
||||
$customer = auth('client')->user();
|
||||
|
||||
$ticketNum = 'TKT-' . now()->format('Ymd') . '-' . strtoupper(Str::random(5));
|
||||
|
||||
$gallery = [];
|
||||
foreach ($request->file('images', []) as $image) {
|
||||
$path = $image->store('tickets', 'public');
|
||||
$gallery[] = Storage::disk('public')->url($path);
|
||||
}
|
||||
|
||||
$ticket = $this->ticketRepository->create([
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'ticket_num' => $ticketNum,
|
||||
'subject' => $request->input('subject'),
|
||||
'description' => $request->input('description'),
|
||||
'status' => 'open',
|
||||
'room' => $request->input('room'),
|
||||
'data' => $request->input('data') ? json_encode($request->input('data')) : null,
|
||||
'gallery' => $gallery ?: null,
|
||||
'customer_id' => $customer->id,
|
||||
]);
|
||||
|
||||
TicketJobs::dispatch($ticket, $customer);
|
||||
Mail::to($customer->email)->queue(new TicketCreated($ticket, $customer));
|
||||
|
||||
$setting = Setting::where('key', 'setting')->first();
|
||||
$adminEmail = $setting ? (json_decode((string) $setting->value)?->admin_email ?? null) : null;
|
||||
if ($adminEmail) {
|
||||
Mail::to($adminEmail)->queue(new TicketAdminNotification($ticket, $customer));
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Ticket đã được tạo thành công.',
|
||||
@@ -115,7 +140,7 @@ class TicketController extends Controller
|
||||
public function reply(Request $request, string $ticket_num)
|
||||
{
|
||||
$request->validate([
|
||||
'message' => ['required', 'string', 'max:2000'],
|
||||
'message' => ['required', 'string'],
|
||||
]);
|
||||
|
||||
$customer = auth('client')->user();
|
||||
|
||||
Reference in New Issue
Block a user