TicketClosed.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 $ticketId;
  12. private $title;
  13. private $url;
  14. private $reason;
  15. private $is_user;
  16. public function __construct($ticketId, $title, $url, $reason, $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)
  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)
  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)
  44. {
  45. return TelegramMessage::create()
  46. ->token(sysConfig('telegram_token'))
  47. ->content($this->reason);
  48. }
  49. public function toBark($notifiable)
  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. }