From 310e8bc07d4aa646db6f8027fef6dd5e1d7318a9 Mon Sep 17 00:00:00 2001 From: lkddi Date: Thu, 2 Apr 2026 15:44:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(wechat):=20=E5=A2=9E=E5=8A=A0=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E5=85=A8=E5=B1=80=E9=80=9A=E7=9F=A5=E5=85=8D=E6=89=93?= =?UTF-8?q?=E6=89=B0=E6=97=B6=E9=97=B4=E9=85=8D=E7=BD=AE=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E5=A4=9C=E9=97=B4=E6=89=93=E6=89=B0=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Admin/WechatBotController.php | 10 ++++ .../WechatBot/WechatNotificationService.php | 47 +++++++++++++++++++ .../views/admin/wechat_bot/edit.blade.php | 21 ++++++++- 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Admin/WechatBotController.php b/app/Http/Controllers/Admin/WechatBotController.php index ad739c0..8e284d4 100644 --- a/app/Http/Controllers/Admin/WechatBotController.php +++ b/app/Http/Controllers/Admin/WechatBotController.php @@ -38,6 +38,10 @@ class WechatBotController extends Controller 'base_url' => '', 'bot_key' => '', ], + 'global_notify' => [ + 'start_time' => '08:00', + 'end_time' => '22:00', + ], 'group_notify' => [ 'target_wxid' => '', 'toggle_admin_online' => false, @@ -72,6 +76,8 @@ class WechatBotController extends Controller 'api_base_url' => 'nullable|string', 'api_bot_key' => 'nullable|string', 'qrcode_image' => 'nullable|image|max:2048', + 'global_start_time' => 'nullable|string', + 'global_end_time' => 'nullable|string', 'group_target_wxid' => 'nullable|string', 'toggle_admin_online' => 'nullable|boolean', 'toggle_baccarat_result' => 'nullable|boolean', @@ -105,6 +111,10 @@ class WechatBotController extends Controller 'bot_key' => $validated['api_bot_key'] ?? '', 'qrcode_image' => $qrcodePath, ], + 'global_notify' => [ + 'start_time' => $validated['global_start_time'] ?? '', + 'end_time' => $validated['global_end_time'] ?? '', + ], 'group_notify' => [ 'target_wxid' => $validated['group_target_wxid'] ?? '', 'toggle_admin_online' => $validated['toggle_admin_online'] ?? false, diff --git a/app/Services/WechatBot/WechatNotificationService.php b/app/Services/WechatBot/WechatNotificationService.php index 9d4540b..d36e36a 100644 --- a/app/Services/WechatBot/WechatNotificationService.php +++ b/app/Services/WechatBot/WechatNotificationService.php @@ -29,11 +29,38 @@ class WechatNotificationService } } + /** + * 检查当前时间是否在全局配置的允许推送免打扰时间窗口内 + */ + protected function isWithinNotificationWindow(): bool + { + $startTime = $this->config['global_notify']['start_time'] ?? ''; + $endTime = $this->config['global_notify']['end_time'] ?? ''; + + // 如果没有配置起止时间,默认全天放行 + if (! $startTime || ! $endTime) { + return true; + } + + $nowTime = date('H:i'); + + if ($startTime < $endTime) { + return $nowTime >= $startTime && $nowTime <= $endTime; + } else { + // 跨天逻辑,如 22:00 -> 08:00 + return $nowTime >= $startTime || $nowTime <= $endTime; + } + } + /** * 管理员上线群通知 */ public function notifyAdminOnline(User $user): void { + if (! $this->isWithinNotificationWindow()) { + return; + } + if (empty($this->config['group_notify']['toggle_admin_online'])) { return; } @@ -60,6 +87,10 @@ class WechatNotificationService */ public function notifyBaccaratResult(string $historyText): void { + if (! $this->isWithinNotificationWindow()) { + return; + } + if (empty($this->config['group_notify']['toggle_baccarat_result'])) { return; } @@ -76,6 +107,10 @@ class WechatNotificationService */ public function notifyLotteryResult(string $historyText): void { + if (! $this->isWithinNotificationWindow()) { + return; + } + if (empty($this->config['group_notify']['toggle_lottery_result'])) { return; } @@ -93,6 +128,10 @@ class WechatNotificationService */ public function notifyFriendsOnline(User $user): void { + if (! $this->isWithinNotificationWindow()) { + return; + } + if (empty($this->config['personal_notify']['toggle_friend_online'])) { return; } @@ -121,6 +160,10 @@ class WechatNotificationService */ public function notifySpouseOnline(User $user): void { + if (! $this->isWithinNotificationWindow()) { + return; + } + if (empty($this->config['personal_notify']['toggle_spouse_online'])) { return; } @@ -145,6 +188,10 @@ class WechatNotificationService */ public function notifyLevelChange(User $user, int $oldLevel, int $newLevel): void { + if (! $this->isWithinNotificationWindow()) { + return; + } + if (empty($this->config['personal_notify']['toggle_level_change'])) { return; } diff --git a/resources/views/admin/wechat_bot/edit.blade.php b/resources/views/admin/wechat_bot/edit.blade.php index 7907ac6..8aa388f 100644 --- a/resources/views/admin/wechat_bot/edit.blade.php +++ b/resources/views/admin/wechat_bot/edit.blade.php @@ -62,7 +62,26 @@ - + +
+

全局推送时间设置 (免打扰)

+
+

设置系统允许进行微信通知(包含群聊与私聊)的时间段,留空则全天24小时允许推送。适用于避免夜间打扰。

+
+
+ + +
+ +
+ + +
+
+
+
+ +

群聊通知设置