DataAnomaly.php 1.8 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 DataAnomaly extends Notification implements ShouldQueue
  9. {
  10. use Queueable;
  11. private $userId;
  12. private $upload;
  13. private $download;
  14. private $total;
  15. public function __construct($userId, $upload, $download, $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)
  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)
  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. /**
  40. * @param $notifiable
  41. * @return TelegramMessage|\NotificationChannels\Telegram\Traits\HasSharedLogic
  42. */
  43. public function toTelegram($notifiable)
  44. {
  45. return TelegramMessage::create()
  46. ->token(sysConfig('telegram_token'))
  47. ->content(trans('notification.data_anomaly_content', ['id' => $this->userId, 'upload' => $this->upload, 'download' => $this->download, 'total' => $this->total]));
  48. }
  49. }