TicketClosed.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. private int $ticketId;
  12. private string $title;
  13. private string $url;
  14. private string $reason;
  15. private bool $is_user;
  16. public function __construct(int $ticketId, string $title, string $url, string $reason, bool $is_user = false)
  17. {
  18. $this->ticketId = $ticketId;
  19. $this->title = $title;
  20. $this->url = $url;
  21. $this->reason = $reason;
  22. $this->is_user = $is_user;
  23. }
  24. public function via($notifiable)
  25. {
  26. return $this->is_user ? ['mail'] : sysConfig('ticket_closed_notification');
  27. }
  28. public function toMail($notifiable): MailMessage
  29. {
  30. return (new MailMessage)
  31. ->subject(trans('notification.close_ticket', ['id' => $this->ticketId, 'title' => $this->title]))
  32. ->line($this->reason)
  33. ->action(trans('notification.view_ticket'), $this->url)
  34. ->line(__('If your issue is not resolved, please create another ticket.'));
  35. }
  36. public function toCustom($notifiable): array
  37. {
  38. return [
  39. 'title' => trans('notification.close_ticket', ['id' => $this->ticketId, 'title' => $this->title]),
  40. 'content' => $this->reason,
  41. ];
  42. }
  43. public function toTelegram($notifiable): TelegramMessage
  44. {
  45. return TelegramMessage::create()
  46. ->token(sysConfig('telegram_token'))
  47. ->content($this->reason);
  48. }
  49. public function toBark($notifiable): array
  50. {
  51. return [
  52. 'title' => trans('notification.close_ticket', ['id' => $this->ticketId, 'title' => $this->title]),
  53. 'content' => $this->reason,
  54. 'group' => '工单',
  55. 'icon' => asset('assets/images/notification/ticket.png'),
  56. 'url' => $this->url,
  57. ];
  58. }
  59. }