NotifyOrderInScheduleJob.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Jobs;
  3. use App\Helpers\DateHelper;
  4. use App\Models\Order;
  5. use App\Models\Schedule;
  6. use App\Notifications\FireBaseNotification;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. use Illuminate\Foundation\Queue\Queueable;
  9. class NotifyOrderInScheduleJob implements ShouldQueue
  10. {
  11. use Queueable;
  12. /**
  13. * Create a new job instance.
  14. */
  15. public function __construct(
  16. private readonly Schedule $schedule,
  17. )
  18. {}
  19. /**
  20. * Execute the job.
  21. */
  22. public function handle(): void
  23. {
  24. $title = 'График монтажа';
  25. $body = 'Адрес ' . $this->schedule->object_address . ' поставлен на монтаж с ' . DateHelper::getHumanDate($this->schedule->installation_date, true);
  26. if(!is_null($this->schedule->brigadier->token_fcm)) {
  27. $this->schedule->brigadier->notify(new FireBaseNotification($title, $body));
  28. }
  29. if(!is_null($this->schedule->order_id)) {
  30. $order = Order::query()->where('id', $this->schedule->order_id)->first();
  31. if(!is_null($order->user->token_fcm)) {
  32. $order->user->notify(new FireBaseNotification($title, $body));
  33. }
  34. }
  35. }
  36. }