migrate to gtea from bistbucket
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\RestaurantDelivery\Observers;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Modules\RestaurantDelivery\Models\DeliveryRating;
|
||||
|
||||
class DeliveryRatingObserver
|
||||
{
|
||||
/**
|
||||
* Handle the DeliveryRating "created" event.
|
||||
*/
|
||||
public function created(DeliveryRating $rating): void
|
||||
{
|
||||
Log::info('Delivery rating created', [
|
||||
'rating_id' => $rating->id,
|
||||
'delivery_id' => $rating->delivery_id,
|
||||
'rider_id' => $rating->rider_id,
|
||||
'overall_rating' => $rating->overall_rating,
|
||||
]);
|
||||
|
||||
// Auto-approve high ratings without review
|
||||
if ($rating->overall_rating >= 4 && ! $rating->review) {
|
||||
$rating->approve();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the DeliveryRating "updated" event.
|
||||
*/
|
||||
public function updated(DeliveryRating $rating): void
|
||||
{
|
||||
// Check if moderation status changed
|
||||
if ($rating->isDirty('moderation_status')) {
|
||||
Log::info('Rating moderation status changed', [
|
||||
'rating_id' => $rating->id,
|
||||
'from' => $rating->getOriginal('moderation_status'),
|
||||
'to' => $rating->moderation_status,
|
||||
]);
|
||||
|
||||
// Recalculate rider's rating if approved or rejected
|
||||
if (in_array($rating->moderation_status, ['approved', 'rejected'])) {
|
||||
$rating->rider?->recalculateRating();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the DeliveryRating "deleted" event.
|
||||
*/
|
||||
public function deleted(DeliveryRating $rating): void
|
||||
{
|
||||
Log::info('Delivery rating deleted', [
|
||||
'rating_id' => $rating->id,
|
||||
'rider_id' => $rating->rider_id,
|
||||
]);
|
||||
|
||||
// Recalculate rider's rating
|
||||
$rating->rider?->recalculateRating();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user