diff --git a/03_WordPress/wp-content/plugins/ifnex-bridge/includes/user-bridge.php b/03_WordPress/wp-content/plugins/ifnex-bridge/includes/user-bridge.php index af25023..5ffcfe1 100644 --- a/03_WordPress/wp-content/plugins/ifnex-bridge/includes/user-bridge.php +++ b/03_WordPress/wp-content/plugins/ifnex-bridge/includes/user-bridge.php @@ -308,7 +308,7 @@ class IFNEX_User_Bridge { return $result; } - /** + /** * لغو سفارش */ public function cancel_customer_order($user_id, $shipment_id) { @@ -320,7 +320,6 @@ class IFNEX_User_Bridge { return $result; } -} /** * دریافت نوتیفیکیشن‌های کاربر @@ -344,6 +343,7 @@ class IFNEX_User_Bridge { $result = $this->authenticated_request($user_id, "/customer/notifications/{$notification_id}/read", 'POST'); return $result; } +} // ══════════════════════════════════════════════════════════════ // AJAX Handler برای لغو سفارش diff --git a/04_Laravel/app/Http/Controllers/Api/Customer/CustomerOrderController.php b/04_Laravel/app/Http/Controllers/Api/Customer/CustomerOrderController.php index bb79f2d..33b25c9 100644 --- a/04_Laravel/app/Http/Controllers/Api/Customer/CustomerOrderController.php +++ b/04_Laravel/app/Http/Controllers/Api/Customer/CustomerOrderController.php @@ -464,6 +464,62 @@ class CustomerOrderController extends Controller return $data; } + /** + * نوتیفیکیشن‌های کاربر + * GET /api/v1/customer/notifications + */ + public function notifications(Request $request): JsonResponse + { + $user = Auth::user(); + + $notifications = $user->notifications() + ->orderBy('created_at', 'desc') + ->paginate($request->per_page ?? 20); + + return response()->json([ + 'success' => true, + 'data' => collect($notifications->items())->map(function ($notification) { + $data = $notification->data; + return [ + 'id' => $notification->id, + 'type' => $notification->type, + 'title' => $data['title'] ?? 'اعلان', + 'body' => $data['message'] ?? '', + 'data' => $data, + 'read_at' => $notification->read_at?->toIso8601String(), + 'created_at' => $notification->created_at->toIso8601String(), + 'created_at_jalali' => $this->toJalali($notification->created_at), + ]; + }), + 'unread_count' => $user->unreadNotifications()->count(), + ]); + } + + /** + * خواندن نوتیفیکیشن + * POST /api/v1/customer/notifications/{notification}/read + */ + public function markNotificationRead(Request $request, $notification): JsonResponse + { + $user = Auth::user(); + + $notif = $user->notifications()->where('id', $notification)->first(); + + if (!$notif) { + return response()->json([ + 'success' => false, + 'message' => 'نوتیفیکیشن یافت نشد.', + ], 404); + } + + $notif->markAsRead(); + + return response()->json([ + 'success' => true, + 'message' => 'خوانده شد.', + ]); + } + /** * تولید شماره AWB */ diff --git a/04_Laravel/routes/api.php b/04_Laravel/routes/api.php index 6b4ca97..8303a9d 100644 --- a/04_Laravel/routes/api.php +++ b/04_Laravel/routes/api.php @@ -65,6 +65,11 @@ Route::middleware(['auth:sanctum'])->prefix('v1')->group(function () { Route::get('/orders/{shipment}', [CustomerOrderController::class, 'show']); Route::post('/orders/{shipment}/cancel', [CustomerOrderController::class, 'cancel']); + + // نوتیفیکیشن‌ها + Route::get('/notifications', [CustomerOrderController::class, 'notifications']); + Route::post('/notifications/{notification}/read', [CustomerOrderController::class, 'markNotificationRead']); + // پرداخت سفارش Route::post('/orders/{shipment}/pay-wallet', [CustomerOrderController::class, 'payFromWallet']);