浏览代码

完善并规范通知系统信息数据&翻译

兔姬桑 4 年之前
父节点
当前提交
b2798413b7

+ 6 - 1
app/Channels/BarkChannel.php

@@ -11,7 +11,12 @@ class BarkChannel
 {
 {
     public function send($notifiable, Notification $notification)
     public function send($notifiable, Notification $notification)
     {
     {
-        $message = $notification->toCustom($notifiable);
+        if (method_exists($notification, 'toBark')) {
+            $message = $notification->toBark($notifiable);
+        } else {
+            $message = $notification->toCustom($notifiable);
+        }
+
         $response = Http::timeout(15)->get('https://api.day.app/'.sysConfig('bark_key').'/'.$message['title'].'/'.$message['content']);
         $response = Http::timeout(15)->get('https://api.day.app/'.sysConfig('bark_key').'/'.$message['title'].'/'.$message['content']);
 
 
         if ($response->ok()) {
         if ($response->ok()) {

+ 4 - 4
app/Components/NetworkDetection.php

@@ -145,7 +145,7 @@ class NetworkDetection
                 return '国内阻断'; // 被墙
                 return '国内阻断'; // 被墙
             }
             }
 
 
-            return '机器宕机'; // 服务器宕机
+            return '断连'; // 服务器宕机
         }
         }
 
 
         return false;
         return false;
@@ -182,7 +182,7 @@ class NetworkDetection
                 return '国内阻断'; // 被墙
                 return '国内阻断'; // 被墙
             }
             }
 
 
-            return '机器宕机'; // 服务器宕机
+            return '断连'; // 服务器宕机
         }
         }
 
 
         return false;
         return false;
@@ -221,7 +221,7 @@ class NetworkDetection
                 return '国内阻断'; // 被墙
                 return '国内阻断'; // 被墙
             }
             }
 
 
-            return '机器宕机'; // 服务器宕机
+            return '断连'; // 服务器宕机
         }
         }
 
 
         return false;
         return false;
@@ -263,7 +263,7 @@ class NetworkDetection
                 return '国内阻断'; // 被墙
                 return '国内阻断'; // 被墙
             }
             }
 
 
-            return '机器宕机'; // 服务器宕机
+            return '断连'; // 服务器宕机
         }
         }
 
 
         return false;
         return false;

+ 15 - 17
app/Console/Commands/NodeStatusDetection.php

@@ -62,7 +62,7 @@ class NodeStatusDetection extends Command
             }
             }
             $data[] = [
             $data[] = [
                 'name' => $node->name,
                 'name' => $node->name,
-                'ip'   => $node->ip,
+                'host' => $node->host,
             ];
             ];
         }
         }
 
 
@@ -74,11 +74,8 @@ class NodeStatusDetection extends Command
     private function checkNodeNetwork(): void
     private function checkNodeNetwork(): void
     {
     {
         $detectionCheckTimes = sysConfig('detection_check_times');
         $detectionCheckTimes = sysConfig('detection_check_times');
-        $sendText = false;
-        $message = "| 线路 | 协议 | 状态 |\r\n| ------ | ------ | ------ |\r\n";
-        $additionalMessage = '';
+        $data = [];
         foreach (Node::whereIsRelay(0)->whereStatus(1)->where('detection_type', '>', 0)->get() as $node) {
         foreach (Node::whereIsRelay(0)->whereStatus(1)->where('detection_type', '>', 0)->get() as $node) {
-            $info = false;
             if ($node->detection_type === 0) {
             if ($node->detection_type === 0) {
                 continue;
                 continue;
             }
             }
@@ -94,23 +91,18 @@ class NodeStatusDetection extends Command
             if ($node->detection_type !== 1) {
             if ($node->detection_type !== 1) {
                 $icmpCheck = (new NetworkDetection)->networkCheck($node->ip, true);
                 $icmpCheck = (new NetworkDetection)->networkCheck($node->ip, true);
                 if ($icmpCheck !== false && $icmpCheck !== '通讯正常') {
                 if ($icmpCheck !== false && $icmpCheck !== '通讯正常') {
-                    $message .= '| '.$node->name.' | ICMP | '.$icmpCheck." |\r\n";
-                    $sendText = true;
-                    $info = true;
+                    $data[$node->id]['icmp'] = $icmpCheck;
                 }
                 }
             }
             }
             if ($node->detection_type !== 2) {
             if ($node->detection_type !== 2) {
                 $tcpCheck = (new NetworkDetection)->networkCheck($node->ip, false, $node->single ? $node->port : 22);
                 $tcpCheck = (new NetworkDetection)->networkCheck($node->ip, false, $node->single ? $node->port : 22);
                 if ($tcpCheck !== false && $tcpCheck !== '通讯正常') {
                 if ($tcpCheck !== false && $tcpCheck !== '通讯正常') {
-                    $message .= '| '.$node->name.' | TCP | '.$tcpCheck." |\r\n";
-                    $sendText = true;
-                    $info = true;
+                    $data[$node->id]['tcp'] = $tcpCheck;
                 }
                 }
             }
             }
-            sleep(5);
 
 
             // 节点检测次数
             // 节点检测次数
-            if ($info && $detectionCheckTimes) {
+            if ($data[$node->id] && $detectionCheckTimes) {
                 // 已通知次数
                 // 已通知次数
                 $cacheKey = 'detection_check_times'.$node->id;
                 $cacheKey = 'detection_check_times'.$node->id;
                 if (Cache::has($cacheKey)) {
                 if (Cache::has($cacheKey)) {
@@ -126,15 +118,21 @@ class NodeStatusDetection extends Command
                 } else {
                 } else {
                     Cache::forget($cacheKey);
                     Cache::forget($cacheKey);
                     $node->update(['status' => 0]);
                     $node->update(['status' => 0]);
-                    $additionalMessage .= "\r\n节点【{$node->name}】自动进入维护状态\r\n";
+                    $data[$node->id]['message'] = '自动进入维护状态';
                 }
                 }
             }
             }
+
+            if ($data[$node->id]) {
+                $data[$node->id]['name'] = $node->name;
+            }
+
+            sleep(5);
         }
         }
 
 
-        if ($sendText) {//只有在出现阻断线路时,才会发出警报
-            Notification::send(User::find(1), new NodeBlocked($message.$additionalMessage));
+        if ($data) { //只有在出现阻断线路时,才会发出警报
+            Notification::send(User::find(1), new NodeBlocked($data));
 
 
-            Log::info("阻断日志: \r\n".$message.$additionalMessage);
+            Log::info("节点状态日志: \r\n".var_export($data, true));
         }
         }
 
 
         Cache::put('LastCheckTime', time() + random_int(3000, Hour), 3700); // 随机生成下次检测时间
         Cache::put('LastCheckTime', time() + random_int(3000, Hour), 3700); // 随机生成下次检测时间

+ 6 - 1
app/Models/Node.php

@@ -107,7 +107,7 @@ class Node extends Model
         $config = [
         $config = [
             'id'    => $this->id,
             'id'    => $this->id,
             'name'  => $this->name,
             'name'  => $this->name,
-            'host'  => $this->is_relay ? $this->relay_server : ($this->server ?: $this->ip),
+            'host'  => $this->host,
             'group' => sysConfig('website_name'),
             'group' => sysConfig('website_name'),
         ];
         ];
         switch ($this->type) {
         switch ($this->type) {
@@ -186,4 +186,9 @@ class Node extends Model
             4 => 'VNet',
             4 => 'VNet',
         ][$this->attributes['type']] ?? 'UnKnown';
         ][$this->attributes['type']] ?? 'UnKnown';
     }
     }
+
+    public function getHostAttribute(): string
+    {
+        return $this->is_relay ? $this->relay_server : ($this->server ?: $this->ip);
+    }
 }
 }

+ 2 - 2
app/Notifications/DataAnomaly.php

@@ -32,14 +32,14 @@ class DataAnomaly extends Notification implements ShouldQueue
     {
     {
         return (new MailMessage)
         return (new MailMessage)
             ->subject(trans('notification.data_anomaly'))
             ->subject(trans('notification.data_anomaly'))
-            ->line(trans('notification.data_anomaly', ['id' => $this->id, 'upload' => $this->upload, 'download' => $this->download, 'total' => $this->total]));
+            ->line(trans('notification.data_anomaly_content', ['id' => $this->id, 'upload' => $this->upload, 'download' => $this->download, 'total' => $this->total]));
     }
     }
 
 
     public function toCustom($notifiable)
     public function toCustom($notifiable)
     {
     {
         return [
         return [
             'title'   => trans('notification.data_anomaly'),
             'title'   => trans('notification.data_anomaly'),
-            'content' => trans('notification.data_anomaly', ['id' => $this->id, 'upload' => $this->upload, 'download' => $this->download, 'total' => $this->total]),
+            'content' => trans('notification.data_anomaly_content', ['id' => $this->id, 'upload' => $this->upload, 'download' => $this->download, 'total' => $this->total]),
         ];
         ];
     }
     }
 }
 }

+ 22 - 6
app/Notifications/NodeBlocked.php

@@ -2,6 +2,7 @@
 
 
 namespace App\Notifications;
 namespace App\Notifications;
 
 
+use Arr;
 use Illuminate\Bus\Queueable;
 use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Notifications\Messages\MailMessage;
 use Illuminate\Notifications\Messages\MailMessage;
@@ -11,11 +12,11 @@ class NodeBlocked extends Notification implements ShouldQueue
 {
 {
     use Queueable;
     use Queueable;
 
 
-    private $content;
+    private $data;
 
 
-    public function __construct($content)
+    public function __construct($data)
     {
     {
-        $this->content = $content;
+        $this->data = $data;
     }
     }
 
 
     public function via($notifiable)
     public function via($notifiable)
@@ -27,15 +28,30 @@ class NodeBlocked extends Notification implements ShouldQueue
     {
     {
         return (new MailMessage)
         return (new MailMessage)
             ->subject(trans('notification.node_block'))
             ->subject(trans('notification.node_block'))
-            ->line(trans('notification.block_report'))
-            ->line($this->content);
+            ->markdown('mail.simpleMarkdown', ['title' => trans('notification.block_report'), 'content' => $this->markdownMessage(), 'url' => route('admin.node.index')]);
+    }
+
+    private function markdownMessage()
+    {
+        $content = '| '.trans('user.attribute.node').' | ICMP | TCP'." |\r\n| ------ | :------: | :------: |\r\n";
+        $tail = '';
+        foreach ($this->data as $node) {
+            if (Arr::hasAny($node, ['icmp', 'tcp'])) {
+                $content .= "| {$node['name']} | ".($node['icmp'] ?? '✔️').' | '.($node['tcp'] ?? '✔️')." |\r\n";
+            }
+            if (Arr::hasAny($node, ['message'])) {
+                $tail .= "- {$node['name']}: {$node['message']}\r\n";
+            }
+        }
+
+        return $content.$tail;
     }
     }
 
 
     public function toCustom($notifiable)
     public function toCustom($notifiable)
     {
     {
         return [
         return [
             'title'   => trans('notification.node_block'),
             'title'   => trans('notification.node_block'),
-            'content' => $this->content,
+            'content' => $this->markdownMessage(),
         ];
         ];
     }
     }
 }
 }

+ 15 - 9
app/Notifications/NodeDailyReport.php

@@ -11,15 +11,11 @@ class NodeDailyReport extends Notification implements ShouldQueue
 {
 {
     use Queueable;
     use Queueable;
 
 
-    private $content;
+    private $data;
 
 
-    public function __construct($nodes)
+    public function __construct($data)
     {
     {
-        $content = '| '.trans('user.attribute.node').' | '.trans('notification.node.upload').' | '.trans('notification.node.download').' | '.trans('notification.node.total')." |\r\n| ------ | :------: | :------: | ------: |\r\n";
-        foreach ($nodes as $node) {
-            $content .= "| {$node['name']} | {$node['upload']} | {$node['download']} | {$node['total']} |\r\n";
-        }
-        $this->content = $content;
+        $this->data = $data;
     }
     }
 
 
     public function via($notifiable)
     public function via($notifiable)
@@ -31,14 +27,24 @@ class NodeDailyReport extends Notification implements ShouldQueue
     {
     {
         return (new MailMessage)
         return (new MailMessage)
             ->subject(__('Nodes Daily Report'))
             ->subject(__('Nodes Daily Report'))
-            ->markdown('mail.node.dailyReport', ['content' => $this->content]);
+            ->markdown('mail.simpleMarkdown', ['title' => __('Nodes Daily Report'), 'content' => $this->markdownMessage(), 'url' => route('admin.node.index')]);
+    }
+
+    private function markdownMessage()
+    {
+        $content = '| '.trans('user.attribute.node').' | '.trans('notification.node.upload').' | '.trans('notification.node.download').' | '.trans('notification.node.total')." |\r\n| ------ | :------: | :------: | ------: |\r\n";
+        foreach ($this->data as $node) {
+            $content .= "| {$node['name']} | {$node['upload']} | {$node['download']} | {$node['total']} |\r\n";
+        }
+
+        return $content;
     }
     }
 
 
     public function toCustom($notifiable)
     public function toCustom($notifiable)
     {
     {
         return [
         return [
             'title'   => __('Nodes Daily Report'),
             'title'   => __('Nodes Daily Report'),
-            'content' => $this->content,
+            'content' => $this->markdownMessage(),
         ];
         ];
     }
     }
 }
 }

+ 33 - 9
app/Notifications/NodeOffline.php

@@ -11,15 +11,11 @@ class NodeOffline extends Notification implements ShouldQueue
 {
 {
     use Queueable;
     use Queueable;
 
 
-    private $content;
+    private $data;
 
 
-    public function __construct($nodes)
+    public function __construct($data)
     {
     {
-        $content = '### '.trans('notification.node_offline_content')."\r\n";
-        foreach ($nodes as $node) {
-            $content .= "- {$node['name']} [{$node['ip']}]\r\n";
-        }
-        $this->content = $content;
+        $this->data = $data;
     }
     }
 
 
     public function via($notifiable)
     public function via($notifiable)
@@ -31,14 +27,42 @@ class NodeOffline extends Notification implements ShouldQueue
     {
     {
         return (new MailMessage)
         return (new MailMessage)
             ->subject(trans('notification.node_offline'))
             ->subject(trans('notification.node_offline'))
-            ->markdown('mail.node.offline', ['content' => $this->content]);
+            ->markdown('mail.simpleMarkdown', ['title' => trans('notification.node_offline_content'), 'content' => $this->markdownMessage(), 'url' => route('admin.node.index')]);
+    }
+
+    private function markdownMessage()
+    {
+        $content = '';
+        foreach ($this->data as $node) {
+            $content .= "- {$node['name']} {$node['host']}\r\n";
+        }
+
+        return $content;
     }
     }
 
 
     public function toCustom($notifiable)
     public function toCustom($notifiable)
     {
     {
         return [
         return [
             'title'   => trans('notification.node_offline'),
             'title'   => trans('notification.node_offline'),
-            'content' => $this->content,
+            'content' => $this->markdownMessage(),
         ];
         ];
     }
     }
+
+    public function toBark($notifiable)
+    {
+        return [
+            'title'   => trans('notification.node_offline'),
+            'content' => $this->stringMessage(),
+        ];
+    }
+
+    private function stringMessage()
+    {
+        $content = '';
+        foreach ($this->data as $node) {
+            $content .= "{$node['name']} {$node['host']}| ";
+        }
+
+        return $content;
+    }
 }
 }

+ 1 - 0
app/Notifications/PaymentReceived.php

@@ -28,6 +28,7 @@ class PaymentReceived extends Notification implements ShouldQueue
     public function toMail($notifiable)
     public function toMail($notifiable)
     {
     {
         return (new MailMessage)
         return (new MailMessage)
+            ->subject(__('Payment Received'))
             ->line(__('Payment for #:sn has been received! Total amount: ¥:amount.', ['sn' => $this->sn, 'amount' => $this->amount]))
             ->line(__('Payment for #:sn has been received! Total amount: ¥:amount.', ['sn' => $this->sn, 'amount' => $this->amount]))
             ->action(__('Invoice Detail'), route('invoiceInfo', $this->sn));
             ->action(__('Invoice Detail'), route('invoiceInfo', $this->sn));
     }
     }

+ 2 - 2
app/Notifications/TicketClosed.php

@@ -33,7 +33,7 @@ class TicketClosed extends Notification implements ShouldQueue
     public function toMail($notifiable)
     public function toMail($notifiable)
     {
     {
         return (new MailMessage)
         return (new MailMessage)
-            ->subject(trans('close_ticket', ['id' => $this->id, 'title' => $this->title]))
+            ->subject(trans('notification.close_ticket', ['id' => $this->id, 'title' => $this->title]))
             ->line($this->reason)
             ->line($this->reason)
             ->action(trans('notification.view_ticket'), $this->url)
             ->action(trans('notification.view_ticket'), $this->url)
             ->line(__('If your problem has not been solved, Feel free to open other one.'));
             ->line(__('If your problem has not been solved, Feel free to open other one.'));
@@ -42,7 +42,7 @@ class TicketClosed extends Notification implements ShouldQueue
     public function toCustom($notifiable)
     public function toCustom($notifiable)
     {
     {
         return [
         return [
-            'title'   => trans('close_ticket', ['id' => $this->id, 'title' => $this->title]),
+            'title'   => trans('notification.close_ticket', ['id' => $this->id, 'title' => $this->title]),
             'content' => $this->reason,
             'content' => $this->reason,
         ];
         ];
     }
     }

+ 1 - 1
app/Notifications/Verification.php

@@ -28,7 +28,7 @@ class Verification extends Notification
             ->subject(trans('notification.verification_account'))
             ->subject(trans('notification.verification_account'))
             ->line(trans('notification.verification'))
             ->line(trans('notification.verification'))
             ->line($this->code)
             ->line($this->code)
-            ->line(trans('verification_limit', ['minutes' => config('tasks.close.verify')]));
+            ->line(trans('notification.verification_limit', ['minutes' => config('tasks.close.verify')]));
     }
     }
 
 
     public function toArray($notifiable)
     public function toArray($notifiable)

文件差异内容过多而无法显示
+ 171 - 167
composer.lock


+ 1 - 0
resources/lang/zh-CN.json

@@ -8,6 +8,7 @@
   "Invoice Detail": "订单明细",
   "Invoice Detail": "订单明细",
   "Nodes Daily Report": "线路每日流量报告",
   "Nodes Daily Report": "线路每日流量报告",
   "Payment for #:sn has been received! Total amount: ¥:amount.": "您成功支付了订单#:sn,总金额为 ¥:amount。",
   "Payment for #:sn has been received! Total amount: ¥:amount.": "您成功支付了订单#:sn,总金额为 ¥:amount。",
+  "Payment Received": "账单付款成功",
   "Please click the button below to verify your email address.": "请点击下面按钮验证您的 E-mail:",
   "Please click the button below to verify your email address.": "请点击下面按钮验证您的 E-mail:",
   "Please click the button below to reset your password.": "请点击下面按钮重置您的密码:",
   "Please click the button below to reset your password.": "请点击下面按钮重置您的密码:",
   "Regards": "致敬",
   "Regards": "致敬",

+ 0 - 7
resources/views/mail/node/dailyReport.blade.php

@@ -1,7 +0,0 @@
-@component('mail::message')
-# {{__('Nodes Daily Report')}}
-{!! $content !!}
-@component('mail::button', ['url' => route('admin.node.index')])
-{{trans('notification.view_web')}}
-@endcomponent
-@endcomponent

+ 2 - 1
resources/views/mail/node/offline.blade.php → resources/views/mail/simpleMarkdown.blade.php

@@ -1,7 +1,8 @@
 @component('mail::message')
 @component('mail::message')
+# {{$title}}
 {!! $content !!}
 {!! $content !!}
 
 
-@component('mail::button', ['url' => route('admin.node.index')])
+@component('mail::button', ['url' => $url])
 {{trans('notification.view_web')}}
 {{trans('notification.view_web')}}
 @endcomponent
 @endcomponent
 @endcomponent
 @endcomponent

+ 1 - 1
resources/views/user/components/notification.blade.php

@@ -17,7 +17,7 @@
             <div class="list-group">
             <div class="list-group">
                 <div data-role="container">
                 <div data-role="container">
                     <div data-role="content">
                     <div data-role="content">
-                        @foreach(auth()->user()->unreadNotifications as $notification)
+                        @foreach(tap(auth()->user()->unreadNotifications)->markAsRead() as $notification)
                             @include('user.components.notifications.'.Str::camel(class_basename($notification->type)))
                             @include('user.components.notifications.'.Str::camel(class_basename($notification->type)))
                         @endforeach
                         @endforeach
                     </div>
                     </div>

+ 1 - 1
resources/views/user/invoices.blade.php

@@ -80,7 +80,7 @@
       function closePlan() {
       function closePlan() {
         swal.fire({
         swal.fire({
           title: '{{trans('user.invoice.active_prepaid_question')}}',
           title: '{{trans('user.invoice.active_prepaid_question')}}',
-          html: '{{trans('user.invoice.active_prepaid_tips')}}',
+          html: @json(trans('user.invoice.active_prepaid_tips')),
           icon: 'warning',
           icon: 'warning',
           showCancelButton: true,
           showCancelButton: true,
           cancelButtonText: '{{trans('common.close')}}',
           cancelButtonText: '{{trans('common.close')}}',

部分文件因为文件数量过多而无法显示