TicketClosed.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Notifications;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Contracts\Queue\ShouldQueue;
  5. use Illuminate\Notifications\Messages\MailMessage;
  6. use Illuminate\Notifications\Notification;
  7. use NotificationChannels\Telegram\TelegramMessage;
  8. class TicketClosed extends Notification implements ShouldQueue
  9. {
  10. use Queueable;
  11. public function __construct(private readonly int $ticketId, private readonly string $title, private readonly string $url, private readonly ?string $reason, private readonly bool $is_user = false)
  12. {
  13. }
  14. public function via($notifiable)
  15. {
  16. return $this->is_user ? ['mail'] : sysConfig('ticket_closed_notification');
  17. }
  18. public function toMail($notifiable): MailMessage
  19. {
  20. return (new MailMessage)
  21. ->subject(trans('notification.close_ticket', ['id' => $this->ticketId, 'title' => $this->title]))
  22. ->line($this->reason)
  23. ->action(trans('notification.view_ticket'), $this->url)
  24. ->line(__('If your issue is not resolved, please create another ticket.'));
  25. }
  26. public function toCustom($notifiable): array
  27. {
  28. return [
  29. 'title' => trans('notification.close_ticket', ['id' => $this->ticketId, 'title' => $this->title]),
  30. 'content' => $this->reason,
  31. ];
  32. }
  33. public function toTelegram($notifiable): TelegramMessage
  34. {
  35. return TelegramMessage::create()
  36. ->token(sysConfig('telegram_token'))
  37. ->content($this->reason);
  38. }
  39. public function toBark($notifiable): array
  40. {
  41. return [
  42. 'title' => trans('notification.close_ticket', ['id' => $this->ticketId, 'title' => $this->title]),
  43. 'content' => $this->reason,
  44. 'group' => '工单',
  45. 'icon' => asset('assets/images/notification/ticket.png'),
  46. 'url' => $this->url,
  47. ];
  48. }
  49. }