- Gäste: Markierungen, Aufenthalte & Umsatz, Stammgast-/Einwilligungsfilter, CSV-Export, Anonymisierung (manuell + automatisch nach Aufbewahrungsfrist) - Werbe-Einwilligung per Double-Opt-in aus dem Anfrageformular, signierte Bestätigungs-/Abmeldelinks - Bewertungen: automatische Einladung nach Abreise, Bewertungsformular mit Kategorien und internem Feedback, Freigabe und öffentliche Antwort im Admin - Konzept: Rollen, Inhalte, Customer Voice, Architektur Portal-Sync/Buchungshoheit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Actions;
|
|
|
|
use App\Enums\BookingStatus;
|
|
use App\Enums\ReviewStatus;
|
|
use App\Mail\NewReview;
|
|
use App\Models\Booking;
|
|
use App\Models\Review;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use RuntimeException;
|
|
|
|
/**
|
|
* Stores a review written by a guest of a real, finished stay. It is published only after approval.
|
|
*/
|
|
class SubmitReview
|
|
{
|
|
/**
|
|
* @param array{rating: int, rating_cleanliness?: ?int, rating_equipment?: ?int, rating_location?: ?int, rating_host?: ?int, title?: ?string, body?: ?string, private_feedback?: ?string, display_name: string, publish_consent: bool} $data
|
|
*/
|
|
public function handle(Booking $booking, array $data): Review
|
|
{
|
|
if (! self::canReview($booking)) {
|
|
throw new RuntimeException('Für diese Buchung kann keine Bewertung abgegeben werden.');
|
|
}
|
|
|
|
$review = $booking->review()->create([
|
|
...$data,
|
|
'property_id' => $booking->property_id,
|
|
'status' => ReviewStatus::Pending,
|
|
'source' => 'website',
|
|
'stayed_on' => $booking->arrival,
|
|
]);
|
|
|
|
Mail::to(config('fewo.notification_email'))->send(new NewReview($review));
|
|
|
|
return $review;
|
|
}
|
|
|
|
public static function canReview(Booking $booking): bool
|
|
{
|
|
return in_array($booking->status, BookingStatus::occupying(), true)
|
|
&& $booking->departure->lessThanOrEqualTo(today())
|
|
&& ! $booking->review()->exists();
|
|
}
|
|
}
|