NodeBlocked.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Notifications;
  3. use Arr;
  4. use Illuminate\Bus\Queueable;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Notifications\Messages\MailMessage;
  7. use Illuminate\Notifications\Notification;
  8. class NodeBlocked 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_blocked_notification');
  19. }
  20. public function toMail($notifiable)
  21. {
  22. return (new MailMessage)
  23. ->subject(trans('notification.node_block'))
  24. ->markdown('mail.simpleMarkdown', ['title' => trans('notification.block_report'), 'content' => $this->markdownMessage(), 'url' => route('admin.node.index')]);
  25. }
  26. private function markdownMessage()
  27. {
  28. $content = '| '.trans('user.attribute.node').' | ICMP | TCP'." |\r\n| ------ | :------: | :------: |\r\n";
  29. $tail = '';
  30. foreach ($this->data as $node) {
  31. if (Arr::hasAny($node, ['icmp', 'tcp'])) {
  32. $content .= "| {$node['name']} | ".($node['icmp'] ?? '✔️').' | '.($node['tcp'] ?? '✔️')." |\r\n";
  33. }
  34. if (Arr::hasAny($node, ['message'])) {
  35. $tail .= "- {$node['name']}: {$node['message']}\r\n";
  36. }
  37. }
  38. return $content.$tail;
  39. }
  40. public function toCustom($notifiable)
  41. {
  42. return [
  43. 'title' => trans('notification.node_block'),
  44. 'content' => $this->markdownMessage(),
  45. ];
  46. }
  47. }