loadMissing(['service.product', 'customer']); $service = $request->service; $customer = $request->customer; $serviceName = $service->server_name ?: ($service->product?->name ?? 'Dịch vụ'); Notification::notifyAdmins([ 'type' => 'service_cancellation_request', 'title' => 'Khách hàng yêu cầu hủy dịch vụ', 'body' => "{$customer->fullname} yêu cầu hủy dịch vụ {$serviceName}. Lý do: {$request->reason}", 'link' => '/services/' . $service->id, 'data' => ['service_id' => $service->id, 'request_id' => $request->id], ]); $adminEmail = json_decode((string) Setting::where('key', 'setting')->value('value'), true)['admin_email'] ?? null; if (! $adminEmail || ! AutoEmailGate::allows('admin_service_cancellation_request')) { return; } try { Mail::to($adminEmail)->queue(new ServiceCancellationRequestMail([ 'customer_name' => (string) $customer->fullname, 'customer_email' => (string) $customer->email, 'product_name' => (string) ($service->product?->name ?? 'Dịch vụ'), 'server_name' => (string) $service->server_name, 'expires_at' => $service->expires_at?->format('d/m/Y') ?? 'N/A', 'cancel_reason' => $request->reason, 'client_ip' => (string) $clientIp, 'created_at' => $request->created_at->format('d/m/Y H:i:s'), 'admin_url' => rtrim(env('ADMIN_URL', config('app.url')), '/') . '/services/' . $service->id, ])); } catch (\Throwable $e) { Log::error('Không gửi được email yêu cầu hủy dịch vụ', ['service_id' => $service->id, 'error' => $e->getMessage()]); } } }