DataAnomaly.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 DataAnomaly extends Notification implements ShouldQueue
  9. {
  10. use Queueable;
  11. private int $userId;
  12. private string $upload;
  13. private string $download;
  14. private string $total;
  15. public function __construct(int $userId, string $upload, string $download, string $total)
  16. {
  17. $this->userId = $userId;
  18. $this->upload = $upload;
  19. $this->download = $download;
  20. $this->total = $total;
  21. }
  22. public function via($notifiable)
  23. {
  24. return sysConfig('data_anomaly_notification');
  25. }
  26. public function toMail($notifiable): MailMessage
  27. {
  28. return (new MailMessage)
  29. ->subject(trans('notification.data_anomaly'))
  30. ->line(trans('notification.data_anomaly_content', ['id' => $this->userId, 'upload' => $this->upload, 'download' => $this->download, 'total' => $this->total]));
  31. }
  32. public function toCustom($notifiable): array
  33. {
  34. return [
  35. 'title' => trans('notification.data_anomaly'),
  36. 'content' => trans('notification.data_anomaly_content', ['id' => $this->userId, 'upload' => $this->upload, 'download' => $this->download, 'total' => $this->total]),
  37. ];
  38. }
  39. public function toTelegram($notifiable): TelegramMessage
  40. {
  41. return TelegramMessage::create()
  42. ->token(sysConfig('telegram_token'))
  43. ->content(trans('notification.data_anomaly_content', ['id' => $this->userId, 'upload' => $this->upload, 'download' => $this->download, 'total' => $this->total]));
  44. }
  45. }