Merge pull request #85 from WDI-Ideas/sayli

Sayli
This commit is contained in:
Sayli Raut
2024-06-06 14:44:35 +05:30
committed by GitHub
3 changed files with 47 additions and 69 deletions

View File

@@ -29,83 +29,60 @@ class ReinstateRestaurant extends Command
/**
* Execute the console command.
*/
public function handle()
{
try {
$recordsToUpdate = RedeemRestaurant::where('is_redeem', 1)->get();
foreach ($recordsToUpdate as $record) {
// Find restaurant
$managerestaurant = ManageRestaurant::where('id', $record->manage_restaurants_xid)->first();
public function handle()
{
try {
$recordsToUpdate = RedeemRestaurant::where('is_redeem', 1)->get();
// Fetch customer
$customerData = IamPrincipal::where('id', $record->iam_principal_xid)
->where('notification_status', 1)
->where('principal_type_xid', 3)
->first();
foreach ($recordsToUpdate as $record) {
//find restaurant
$managerestaurant = ManageRestaurant::where('id', $record->manage_restaurants_xid)->first();
if ($managerestaurant && $managerestaurant->is_active == 1) {
$redeemDate = Carbon::parse($record->redeem_date);
$fourHourPlusTimeOfRecord = $redeemDate->copy()->addHours(4);
$currentTime = Carbon::now();
$customerData = IamPrincipal::where('id', $record->iam_principal_xid)->where('notification_status', 1)->where('principal_type_xid',3)->first(); //fetch customer
if ($currentTime > $fourHourPlusTimeOfRecord) {
// Update record
$record->update([
'is_redeem' => 0,
'redeem_date' => null,
'count' => $record->count + 1,
'is_redeemption_undone' => 0,
'redeemption_undone_date' => null,
]);
if ($managerestaurant && $managerestaurant->is_active == 1) {
$redeemDate = Carbon::parse($record->redeem_date);
// Prepare notification details
$restImage = ListingImageUrl('restaurant_images', $managerestaurant->image);
$title = "Your " . $managerestaurant->name . " Reinstate successfully";
$message = "Your " . $managerestaurant->name . " Reinstate successfully";
$content_type = 'Restaurant_Reinstate';
$imageUrl = $restImage;
$fourHourPlusTimeOfRecord = $redeemDate->copy()->addHours(4);
// Send notification
$notificationSent = onesignalhelper::sendNotificationApi(
$customerData->one_signal_player_id,
$title,
$message,
$content_type,
$imageUrl,
$id = null
);
$currentTime = Carbon::now();
// Check if notification was sent successfully
if ($notificationSent) {
Log::info('Notification sent successfully to customer ID: ' . $customerData->id);
if ($currentTime > $fourHourPlusTimeOfRecord) {
$record->update([
'is_redeem' => 0,
'redeem_date' => null,
'count' => $record->count + 1,
'is_redeemption_undone' => 0,
'redeemption_undone_date' => null,
]);
$restImage = ListingImageUrl('restaurant_images', $managerestaurant->image);
$title = "Your " . $managerestaurant->name . " Reinstate successfully";
$message = "Your " . $managerestaurant->name . " Reinstate successfully";
$content_type = 'Restaurant Reinstate';
$imageUrl = $restImage;
// Store notification details
$notificationStored = onesignalhelper::StoreNotificationDetails(
$customerData->id,
$content_type,
$title,
$restImage
);
onesignalhelper::sendNotificationApi(
$customerData->one_signal_player_id,
$title,
$message,
$content_type,
$imageUrl,
$id = null
);
Log::info('Reinstate of record done at ' . now());
if ($notificationStored) {
Log::info('Notification details stored successfully for customer ID: ' . $customerData->id);
} else {
Log::warning('Failed to store notification details for customer ID: ' . $customerData->id);
}
} else {
Log::warning('Failed to send notification to customer ID: ' . $customerData->id);
}
onesignalhelper::StoreNotificationDetails($customerData->id, $content_type, $title, $restImage);
}
}
}
Log::info('Reinstate of record done at ' . now());
}
}
}
Log::info('Reinstate task ran successfully at ' . now());
} catch (\Exception $e) {
Log::error('Reinstate function failed: ' . $e->getMessage());
}
}
Log::info('Reinstate task ran successfully at ' . now());
} catch (\Exception $e) {
Log::error('Reinstate function failed: ' . $e->getMessage());
}
}
}

View File

@@ -94,7 +94,7 @@ class ManageRestrauntController extends Controller
$allCustomerOneSignalIds = IamPrincipal::select('id', 'one_signal_player_id')->where('is_active', 1)->where('notification_status', 1)->where('principal_type_xid', 3)->get();
$title = "New " . $restaurant->name . " is added";
$message = "New Restaurant is Now Live.";
$content_type = 'New_Restaurant_Added';
$content_type = 'New Restaurant Added';
$imageUrl = $imagePath;
foreach ($allCustomerOneSignalIds as $customerIdItem) {

View File

@@ -26,7 +26,8 @@ class onesignalhelper
'id' => $id,
],
'big_picture' => $imageUrl,
// 'app_id' => env('ONE_SIGNAL_APP_ID'),
'external_id' => [$playerId]
// 'authorization' => env('ONE_SIGNAL_AUTHORIZE')
];