NodeDailyReport.php 1.4 KB

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