Viewing File: /home/ubuntu/vedadeals-backend-base/app/Jobs/OrderNotificationJob.php
<?php
namespace App\Jobs;
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 App\Models\{ User, Order, BellNotification };
use App\Notifications\{ BellNotification as BellNotify};
use App\Services\{EmailService};
use DB, Setting, Exception, stdClass, Notification;
class OrderNotificationJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $order_unique_id;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($order_unique_id)
{
$this->order_unique_id = $order_unique_id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
$order = Order::with(['user'])->firstWhere(['unique_id' => $this->order_unique_id]);
throw_if(!$order, new Exception(tr('order_not_found')));
$user = $order->user;
if (Setting::get('is_push_notification') && $user) {
$data = new stdClass;
$data->title = $data->body = get_order_push_notification_content($order->status, $order->order_unique_id);
if($user->push_notification && $user->is_logged_in && $user->device_token && in_array($user->device_type, [DEVICE_ANDROID, DEVICE_IOS]) ) {
$data->push_data = [
'content_id' =>$order->id ? : '',
'notification_type' => BELL_NOTIFICATION_ORDER,
'content_unique_id' => $order->unique_id ? : '',
];
$data->device_token = $user->device_token;
$data->action = BELL_NOTIFICATION_ORDER;
Notification::send($user, new BellNotify($data));
}
BellNotification::Create([
'title' => $data->title,
'description' => $data->body,
'to_user_id' => $user->id,
'action' => BELL_NOTIFICATION_ORDER,
'model_unique_id' => $order->unique_id ? : '',
]);
}
if (Setting::get('is_email_notification') && $user) {
EmailService::order_status_email($order->unique_id);
}
return true;
} catch (Exception $e) {
info("OrderNotificationJob Error : ".$e->getMessage());
}
}
}
Back to Directory
File Manager