NodeBlocked.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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').' | IP | ICMP | TCP'." |\r\n| ------ | :------: | :------: |\r\n";
  29. $tail = '';
  30. foreach ($this->data as $node) {
  31. $case = $node;
  32. Arr::forget($case, ['message', 'name']);
  33. foreach ($case as $ip => $info) {
  34. $content .= "| {$node['name']} | {$ip} | ".($info['icmp'] ?? '✔️').' | '.($info['tcp'] ?? '✔️')." |\r\n";
  35. }
  36. if (Arr::hasAny($node, ['message'])) {
  37. $tail .= "- {$node['name']}: {$node['message']}\r\n";
  38. }
  39. }
  40. return $content.$tail;
  41. }
  42. public function toCustom($notifiable)
  43. {
  44. return [
  45. 'title' => trans('notification.node_block'),
  46. 'content' => $this->markdownMessage(),
  47. ];
  48. }
  49. }