send notification

This commit is contained in:
sayliraut
2024-06-11 16:03:19 +05:30
parent 811dcfbb1a
commit 78444f3b16
2 changed files with 73 additions and 80 deletions

View File

@@ -3,8 +3,13 @@
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\IamPrincipal;
use App\Models\NotificationDetails;
use Illuminate\Http\Request;
use Exception;
use Illuminate\Support\Facades\Log;
use App\Helpers\onesignalhelper;
use Illuminate\Support\Facades\DB;
class ManageNotificationsController extends Controller
{
@@ -68,7 +73,7 @@ class ManageNotificationsController extends Controller
return view('Admin.pages.manage_notification.manage_notifications_add');
}
/**
/**
* Created By : Sayli Raut
* Created at : 10 June 2024
* Use : To add notification .
@@ -91,37 +96,30 @@ class ManageNotificationsController extends Controller
}
$tnormalImage = saveSingleImageWithoutCrop($image, 'notification_images', $image_db);
$imagePath = ListingImageUrl('notification_images', $tnormalImage);
$allOrders = Order::pluck('iam_principal_xid');
$passportId = $request->passport;
$passportUserIds = OrderedPassport::where('passport_xid', $passportId)
->whereHas('iamPrincipal', function ($query) {
$query->where('notification_status', 1)
->where('principal_type_xid', 3);
})
->pluck('iam_principal_xid');
$passportUserIdsToArray = $passportUserIds->toArray();
$allCustomerOneSignalIds = IamPrincipal::where('is_active', 1)
->where('notification_status', 1)
->where('principal_type_xid', 3)
->pluck('id');
$allRestaurantOneSignalIds = IamPrincipal::where('is_active', 1)
->where('notification_status', 1)
->where('principal_type_xid', 4)
->pluck('id');
// Find the remaining user IDs
$remainingUserIds = $allCustomerOneSignalIds->diff($allOrders);
$remainingUserIdsArray = $remainingUserIds->toArray();
// Find the remaining user data
$remainingUserData = IamPrincipal::whereIn('id', $remainingUserIdsArray)->get();
$parchasePassportUserData = IamPrincipal::whereIn('id', $passportUserIdsToArray)->get();
$UserData = IamPrincipal::whereIn('id', $allCustomerOneSignalIds)->get();
$title = $request->title;
$message = $request->description;
$content_type = 'Notification';
$imageUrl = $imagePath;
// FOR all User
if ($request->user_type == 1) {
foreach ($remainingUserData as $customerIdItem) {
// FOR all customer
if ($request->recipients == 'customer') {
foreach ($UserData as $customerIdItem) {
if ($customerIdItem->one_signal_player_id) {
onesignalhelper::sendNotificationApi(
$customerIdItem->one_signal_player_id,
@@ -134,11 +132,14 @@ class ManageNotificationsController extends Controller
}
onesignalhelper::StoreNotificationDetails($customerIdItem->id, $content_type, $title, $imagePath);
}
} elseif ($request->user_type == 2) {
foreach ($parchasePassportUserData as $customerIdItem) {
if ($customerIdItem->one_signal_player_id) {
} elseif ($request->recipients == 'restaurant') {
$restaurantData = IamPrincipal::whereIn('id', $allRestaurantOneSignalIds)->get();
foreach ($restaurantData as $restIdItem) {
if ($restIdItem->one_signal_player_id) {
onesignalhelper::sendNotificationApi(
$customerIdItem->one_signal_player_id,
$restIdItem->one_signal_player_id,
$title,
$message,
$content_type,
@@ -146,21 +147,15 @@ class ManageNotificationsController extends Controller
$id = null
);
}
onesignalhelper::StoreNotificationDetails($customerIdItem->id, $content_type, $title, $imagePath);
onesignalhelper::StoreNotificationDetails($restIdItem->id, $content_type, $title, $imagePath);
}
}
// FOR All passport user
DB::commit();
return jsonResponseWithSuccessMessage(__('success.save_data'));
// return $voucher_data;
} catch (Exception $e) {
DB::rollBack();
Log::error("Coupon Store Page Load Failed " . $e->getMessage());
Log::error("Notification send Failed " . $e->getMessage());
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
}
}