Files
Global-Jain/app/Jobs/Notifications/NewApp/SendDownloadNewApp.php

80 lines
3.1 KiB
PHP
Raw Normal View History

2025-11-05 10:37:10 +05:30
<?php
namespace App\Jobs\Notifications\NewApp;
use App\Constant\Constant;
use App\Models\UserDeviceToken;
use App\Traits\PushNotificationTraits;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class SendDownloadNewApp implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, PushNotificationTraits;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
//Push Notification to shravak who added
$users = UserDeviceToken::with('user')->whereHas('user', function ($query) {
$query->where('app_version', Constant::STATUS_ZERO);
})->get();
$pushData = [];
foreach ($users as $user) {
$pushData['userToken'] = $user->token ?? [];
$pushData['title'] = trans('notifications.notification_title.new_app');
$pushData['body'] = trans('notifications.new_application.download_app', ['url' => 'https://play.google.com/store/apps/details?id=com.globaljain.android']);
$extraData = [];
$extraData['user_id'] = $user->user_id ?? '';
$extraData['user_name'] = $user->user->name ?? '';
$extraData['url'] = env('NEW_APP_URL');
$extraData['type'] = trans('notifications.app_notification_type.new-app');
$extraData['created_at'] = date('Y/m/d H:i:s');
$extraData['os'] = $user->os ? getPlatform($user->os) : [];
$pushData['extraData'] = $extraData ?? [];
$this->pushNotification($pushData, $extraData);
//Store notification for send back sant
$notificationData = [];
$notificationData['body'] = trans('notifications.new_application.download_app', ['url' => 'https://play.google.com/store/apps/details?id=com.globaljain.android']);
$notificationData['type'] = trans('notifications.app_notification_type.new-app');
$notificationData['title'] = trans('notifications.notification_title.new_app');
$notificationData['user_id'] = $user->user_id ?? '';;
$extraNotificationData = [];
$extraNotificationData['user_id'] = $user->user_id ?? '';
$extraNotificationData['name'] = $user->user->name ?? '';
$extraNotificationData['created_at'] = date('Y/m/d H:i:s');
$notificationData['extraNotificationData'] = $extraNotificationData ?? [];
$this->storeNotification($notificationData);
//Unread count increament
unreadNotificationCounter($user->user_id);
}
} catch (\Exception $ex) {
Log::error($ex);
}
}
}