NodeDailyReport.php 1.7 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 NodeDailyReport extends Notification implements ShouldQueue
  9. {
  10. use Queueable;
  11. private $data;
  12. public function __construct($data)
  13. {
  14. $this->data = $data;
  15. }
  16. public function via($notifiable)
  17. {
  18. return sysConfig('node_daily_notification');
  19. }
  20. public function toMail($notifiable)
  21. {
  22. return (new MailMessage)
  23. ->subject(__('Nodes Daily Report'))
  24. ->markdown('mail.simpleMarkdown', ['title' => __('Nodes Daily Report'), 'content' => $this->markdownMessage(), 'url' => route('admin.node.index')]);
  25. }
  26. private function markdownMessage()
  27. {
  28. $content = '| '.trans('user.attribute.node').' | '.trans('notification.node.upload').' | '.trans('notification.node.download').' | '.trans('notification.node.total')." |\r\n| ------ | :------: | :------: | ------: |\r\n";
  29. foreach ($this->data as $node) {
  30. $content .= "| {$node['name']} | {$node['upload']} | {$node['download']} | {$node['total']} |\r\n";
  31. }
  32. return $content;
  33. }
  34. public function toCustom($notifiable)
  35. {
  36. return [
  37. 'title' => __('Nodes Daily Report'),
  38. 'content' => $this->markdownMessage(),
  39. ];
  40. }
  41. public function toTelegram($notifiable)
  42. {
  43. return TelegramMessage::create()
  44. ->token(sysConfig('telegram_token'))
  45. ->content($this->markdownMessage());
  46. }
  47. }