DashExport
This commit is contained in:
76
app/Console/Commands/SentScheduleNotification.php
Normal file
76
app/Console/Commands/SentScheduleNotification.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\IamPrincipal;
|
||||
use App\Models\NotificationDetails;
|
||||
use Illuminate\Console\Command;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use DateTime;
|
||||
use App\Helpers\onesignalhelper;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class SentScheduleNotification extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:sent-schedule-notification';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'It will send Recommendation to users Based on stored Data';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$getAllPushNotifications = NotificationDetails::where('is_schedule', 1)
|
||||
->where('is_active', 0)
|
||||
->orderByDesc('id')
|
||||
->get();
|
||||
|
||||
$currentDateTime = new DateTime();
|
||||
|
||||
foreach ($getAllPushNotifications as $inAppNotificationItem) {
|
||||
|
||||
$storedDateTime = new DateTime($inAppNotificationItem->delivery_schedule);
|
||||
|
||||
$currentTime = $currentDateTime->format('Y-m-d H:i');
|
||||
$storedTime = $storedDateTime->format('Y-m-d H:i');
|
||||
|
||||
if ($currentTime == $storedTime) {
|
||||
$title = $inAppNotificationItem->type;
|
||||
$description = $inAppNotificationItem->description;
|
||||
$imagePath = $inAppNotificationItem->image;
|
||||
|
||||
$principalData = IamPrincipal::find($inAppNotificationItem->principal_xid);
|
||||
|
||||
if ($principalData && $principalData->one_signal_player_id) {
|
||||
OneSignalHelper::sendNotificationApi(
|
||||
$principalData->one_signal_player_id,
|
||||
$title,
|
||||
$description,
|
||||
'Dashboard Notification',
|
||||
$imagePath,
|
||||
$id = null
|
||||
);
|
||||
|
||||
Log::info("INAPP scheduled notification sent successfully");
|
||||
|
||||
$inAppNotificationItem->is_active = 1;
|
||||
$inAppNotificationItem->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,10 +81,10 @@ class ManageNotificationsController extends Controller
|
||||
* Created at : 10 June 2024
|
||||
* Use : To add notification .
|
||||
*/
|
||||
|
||||
public function store_notificaton_data(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$request->validate([
|
||||
'image' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048',
|
||||
]);
|
||||
@@ -104,65 +104,144 @@ class ManageNotificationsController extends Controller
|
||||
|
||||
$states = $request->states;
|
||||
|
||||
// $dateTime = now();
|
||||
// $formattedDateTime = $dateTime->format('Y-m-d H:i:s');
|
||||
// $unsubscribe = Subscriptions::select('iam_principal_xid')->where('next_payment_date', '>=', $formattedDateTime)->get();
|
||||
$dateTime = now();
|
||||
$formattedDateTime = $dateTime->format('Y-m-d H:i:s');
|
||||
$iamPrincipals = Subscriptions::select('iam_principal_xid')
|
||||
->where('next_payment_date', '>=', $formattedDateTime)
|
||||
->get();
|
||||
|
||||
$userQuery = IamPrincipal::where('is_active', 1)
|
||||
$iamPrincipalIds = $iamPrincipals->pluck('iam_principal_xid');
|
||||
|
||||
$subscribe = IamPrincipal::whereIn('id', $iamPrincipalIds)
|
||||
->where('is_active', 1)
|
||||
->where('notification_status', 1)
|
||||
->where('principal_type_xid', 3)
|
||||
->whereIn('state_xid', $states);
|
||||
->whereIn('state_xid', $states)
|
||||
->get();
|
||||
|
||||
if ($request->user_type == 1) {
|
||||
$allCustomerOneSignalIds = $userQuery->pluck('id');
|
||||
$allCustomerOneSignalIds = $subscribe->pluck('id');
|
||||
$UserData = IamPrincipal::whereIn('id', $allCustomerOneSignalIds)->get();
|
||||
|
||||
foreach ($UserData as $customerIdItem) {
|
||||
if ($customerIdItem->one_signal_player_id) {
|
||||
onesignalhelper::sendNotificationApi(
|
||||
$customerIdItem->one_signal_player_id,
|
||||
$request->title,
|
||||
$request->description,
|
||||
'Dashboard Notification',
|
||||
$imagePath,
|
||||
$id = null
|
||||
);
|
||||
// user_type 1 = subscribed user
|
||||
if ($request->schedule_radio1 == 1 && $request->schedule_date) {
|
||||
// Scheduled Notification
|
||||
NotificationDetails::create([
|
||||
'principal_xid' => $customerIdItem->id,
|
||||
'description' => $request->description,
|
||||
'type' => $request->title,
|
||||
'image' => $imagePath,
|
||||
'date_added' => $request->schedule_date,
|
||||
'is_schedule' => 1,
|
||||
'delivery_schedule' => $request->schedule_date,
|
||||
'is_active' => 0,
|
||||
|
||||
]);
|
||||
} else {
|
||||
// Immediate Notification
|
||||
if ($customerIdItem->one_signal_player_id) {
|
||||
onesignalhelper::sendNotificationApi(
|
||||
$customerIdItem->one_signal_player_id,
|
||||
$request->title,
|
||||
$request->description,
|
||||
'Dashboard Notification',
|
||||
$imagePath,
|
||||
$id = null
|
||||
);
|
||||
}
|
||||
onesignalhelper::StoreNotificationDetails($customerIdItem->id, 'Notification', $request->title, $imagePath);
|
||||
}
|
||||
onesignalhelper::StoreNotificationDetails($customerIdItem->id, 'Notification', $request->title, $imagePath);
|
||||
}
|
||||
} elseif ($request->user_type == 2) {
|
||||
$allRestaurantOneSignalIds = $userQuery->pluck('id');
|
||||
//user_type 2 unsubscribed users
|
||||
$allPrincipalIds = IamPrincipal::where('principal_type_xid', 3)
|
||||
->pluck('id');
|
||||
|
||||
$subscribedIds = Subscriptions::select('iam_principal_xid')
|
||||
->where('next_payment_date', '>=', $formattedDateTime)
|
||||
->pluck('iam_principal_xid');
|
||||
|
||||
$unsubscribedIds = $allPrincipalIds->diff($subscribedIds);
|
||||
|
||||
$unsubscribedPrincipals = IamPrincipal::whereIn('id', $unsubscribedIds)
|
||||
->where('is_active', 1)
|
||||
->where('notification_status', 1)
|
||||
->whereIn('state_xid', $states)
|
||||
->get();
|
||||
|
||||
$allRestaurantOneSignalIds = $unsubscribedPrincipals->pluck('id');
|
||||
$restaurantData = IamPrincipal::whereIn('id', $allRestaurantOneSignalIds)->get();
|
||||
|
||||
foreach ($restaurantData as $restIdItem) {
|
||||
if ($restIdItem->one_signal_player_id) {
|
||||
onesignalhelper::sendNotificationApi(
|
||||
$restIdItem->one_signal_player_id,
|
||||
$request->title,
|
||||
$request->description,
|
||||
'Dashboard Notification',
|
||||
$imagePath,
|
||||
$id = null
|
||||
);
|
||||
foreach ($restaurantData as $restaurantsData) {
|
||||
if ($request->schedule_radio1 == 1 && $request->schedule_date) {
|
||||
// Scheduled Notification
|
||||
NotificationDetails::create([
|
||||
'principal_xid' => $restaurantsData->id,
|
||||
'description' => $request->description,
|
||||
'type' => $request->title,
|
||||
'image' => $imagePath,
|
||||
'date_added' => $request->schedule_date,
|
||||
'is_schedule' => 1,
|
||||
'delivery_schedule' => $request->schedule_date,
|
||||
'is_active' => 0,
|
||||
|
||||
|
||||
]);
|
||||
} else {
|
||||
// Immediate Notification
|
||||
if ($restaurantsData->one_signal_player_id) {
|
||||
onesignalhelper::sendNotificationApi(
|
||||
$restaurantsData->one_signal_player_id,
|
||||
$request->title,
|
||||
$request->description,
|
||||
$request->title,
|
||||
$imagePath,
|
||||
$id = null
|
||||
);
|
||||
}
|
||||
onesignalhelper::StoreNotificationDetails($restaurantsData->id, 'Notification', $request->title, $imagePath);
|
||||
}
|
||||
onesignalhelper::StoreNotificationDetails($restIdItem->id, 'Notification', $request->title, $imagePath);
|
||||
}
|
||||
} elseif ($request->user_type == 3) {
|
||||
// user_type 3 = subscribed and unsubscribed users
|
||||
$userQuery = IamPrincipal::where('is_active', 1)
|
||||
->where('notification_status', 1)
|
||||
->where('principal_type_xid', 3)
|
||||
->whereIn('state_xid', $states);
|
||||
|
||||
$allUserOneSignalIds = $userQuery->pluck('id');
|
||||
$UserData = IamPrincipal::whereIn('id', $allUserOneSignalIds)->get();
|
||||
|
||||
foreach ($UserData as $userItem) {
|
||||
if ($userItem->one_signal_player_id) {
|
||||
onesignalhelper::sendNotificationApi(
|
||||
$userItem->one_signal_player_id,
|
||||
$request->title,
|
||||
$request->description,
|
||||
'Dashboard Notification',
|
||||
$imagePath,
|
||||
$id = null
|
||||
);
|
||||
foreach ($UserData as $CustomerData) {
|
||||
if ($request->schedule_radio1 == 1 && $request->schedule_date) {
|
||||
// Scheduled Notification
|
||||
NotificationDetails::create([
|
||||
'principal_xid' => $CustomerData->id,
|
||||
'description' => $request->description,
|
||||
'type' => $request->title,
|
||||
'image' => $imagePath,
|
||||
'date_added' => $request->schedule_date,
|
||||
'is_schedule' => 1,
|
||||
'delivery_schedule' => $request->schedule_date,
|
||||
'is_active' => 0,
|
||||
|
||||
|
||||
]);
|
||||
} else {
|
||||
// Immediate Notification
|
||||
if ($CustomerData->one_signal_player_id) {
|
||||
onesignalhelper::sendNotificationApi(
|
||||
$CustomerData->one_signal_player_id,
|
||||
$request->title,
|
||||
$request->description,
|
||||
'Dashboard Notification',
|
||||
$imagePath,
|
||||
$id = null
|
||||
);
|
||||
}
|
||||
onesignalhelper::StoreNotificationDetails($CustomerData->id, 'Notification', $request->title, $imagePath);
|
||||
}
|
||||
onesignalhelper::StoreNotificationDetails($userItem->id, 'Notification', $request->title, $imagePath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,6 +257,7 @@ class ManageNotificationsController extends Controller
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Created By : Sayli Raut
|
||||
* Created at : 10 June 2024
|
||||
|
||||
@@ -27,13 +27,12 @@ class onesignalhelper
|
||||
],
|
||||
'big_picture' => $imageUrl,
|
||||
|
||||
'external_id' => [$playerId]
|
||||
// 'authorization' => env('ONE_SIGNAL_AUTHORIZE')
|
||||
'external_id' => [$playerId],
|
||||
'authorization' => env('ONE_SIGNAL_AUTHORIZE')
|
||||
];
|
||||
|
||||
$result = OneSignal::sendPush($fields, null ,env('ONE_SIGNAL_APP_ID'));
|
||||
// Log::info($result);
|
||||
|
||||
Log::info($result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
<div class="form-check form-check-sm form-check-custom form-check-solid me-3">
|
||||
<input class="form-check-input" type="radio" name="user_type"
|
||||
value="1" id="select-all-ids" />
|
||||
<label class="form-check-label" for="select-all-ids">Send to unsubscribed
|
||||
<label class="form-check-label" for="select-all-ids">Send to subscribed
|
||||
users who are in their respective states</label><br>
|
||||
<div id="dropdown-1"
|
||||
style="display: none; max-height: 200px; overflow-y: auto;">
|
||||
@@ -89,7 +89,8 @@
|
||||
</div>
|
||||
<input class="form-check-input" type="radio" name="user_type"
|
||||
id="select-popular-ids" value="2" />
|
||||
<label class="form-check-label" for="select-popular-ids">Send to subscribed
|
||||
<label class="form-check-label" for="select-popular-ids">Send to
|
||||
unsubscribed
|
||||
users who are in their respective states</label><br>
|
||||
<div id="dropdown-2"
|
||||
style="display: none; max-height: 200px; overflow-y: auto;">
|
||||
|
||||
Reference in New Issue
Block a user