90 lines
3.5 KiB
PHP
90 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
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;
|
|
|
|
class SendGenerateMemberID 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 all users
|
|
$users = UserDeviceToken::with('user')->get();
|
|
|
|
$userIds = [];
|
|
$userArr = [];
|
|
foreach ($users as $user) {
|
|
if (!isset($userIds[$user->user_id])) {
|
|
$userIds[$user->user_id] = true;
|
|
|
|
$pushData = [];
|
|
$pushData['userToken'] = $user->token ?? [];
|
|
$pushData['title'] = trans('notifications.notification_title.generate_memberid');
|
|
$pushData['body'] = trans('notifications.memberid.generate_memberid');
|
|
$extraData = [];
|
|
$extraData['user_id'] = $user->user_id ?? '';
|
|
$extraData['user_name'] = $user->user->name ?? '';
|
|
$extraData['avatar'] = $user->user->avatar ?? '';
|
|
$extraData['url'] = env('NEW_APP_URL');
|
|
$extraData['type'] = trans('notifications.memberid_type.memberID');
|
|
$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.memberid.generate_memberid');
|
|
$notificationData['type'] = trans('notifications.memberid_type.memberID');
|
|
$notificationData['title'] = trans('notifications.notification_title.generate_memberid');
|
|
$notificationData['user_id'] = $user->user_id ?? '';
|
|
$extraNotificationData = [];
|
|
$extraNotificationData['user_id'] = $user->user_id ?? '';
|
|
$extraNotificationData['name'] = $user->user->name ?? '';
|
|
$extraNotificationData['avatar'] = $user->user->avatar ?? '';
|
|
$extraNotificationData['created_at'] = date('Y/m/d H:i:s');
|
|
$notificationData['extraNotificationData'] = $extraNotificationData ?? [];
|
|
|
|
// $this->storeNotification($notificationData);
|
|
// //Unread count increament
|
|
// unreadNotificationCounter($user->user_id);
|
|
|
|
if (!in_array($this->user_id, $userArr)) {
|
|
$userArr[$this->user_id] = $this->user_id;
|
|
$this->storeNotification($notificationData);
|
|
unreadNotificationCounter($user->user_id);
|
|
}
|
|
}
|
|
}
|
|
} catch (\Exception $ex) {
|
|
Log::error($ex);
|
|
}
|
|
}
|
|
}
|