Update: 2026-08-02 17:52:28

This commit is contained in:
Hamza-Ayed
2026-08-02 17:52:28 +03:00
parent b78a6797d5
commit 4620e84d34
96 changed files with 6250 additions and 476 deletions
+34
View File
@@ -0,0 +1,34 @@
<?php
// food/order/rate.php — تقييم الطلب بعد التسليم (يحدّث متوسط تقييم المطعم)
require_once __DIR__ . '/../connect_app.php';
$orderId = filterRequest('order_id', 'int');
$rating = filterRequest('rating', 'int');
$comment = filterRequest('comment');
if (!$orderId || !$rating || $rating < 1 || $rating > 5) jsonError('order_id and rating (1-5) are required');
$order = foodAssertOrderOwnership($orderId, 'customer', $food_passenger_id);
if ($order['status'] !== 'delivered') jsonError('Only delivered orders can be rated', 409);
if ($order['rating'] !== null) jsonError('Order already rated', 409);
$food_con->beginTransaction();
try {
$food_con->prepare("UPDATE food_orders SET rating=?, rating_comment=? WHERE id=?")
->execute([$rating, $comment, $orderId]);
$food_con->prepare(
"UPDATE food_merchants SET
rating_avg = ((rating_avg * rating_count) + ?) / (rating_count + 1),
rating_count = rating_count + 1
WHERE id=?"
)->execute([$rating, $order['merchant_id']]);
$food_con->commit();
} catch (Throwable $e) {
$food_con->rollBack();
appLog('[FOOD][ORDER][rate] ' . $e->getMessage(), 'ERROR');
jsonError('Failed to save rating', 500);
}
jsonSuccess(['order_id' => $orderId, 'rating' => $rating]);