feat(wechat): 增加微信全局通知免打扰时间配置,避免夜间打扰用户
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,26 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 2. 群通知设置 -->
|
||||
<!-- 2. 全局推送时间设置 -->
|
||||
<div class="mb-8">
|
||||
<h3 class="text-md font-bold text-gray-800 border-b pb-2 mb-4">全局推送时间设置 (免打扰)</h3>
|
||||
<div class="mb-4">
|
||||
<p class="text-sm text-gray-600 mb-4">设置系统允许进行微信通知(包含群聊与私聊)的时间段,留空则全天24小时允许推送。适用于避免夜间打扰。</p>
|
||||
<div class="flex items-center space-x-4 max-w-lg">
|
||||
<div class="flex-1">
|
||||
<label class="block text-sm font-bold text-gray-700 mb-1">允许推送开始时间</label>
|
||||
<input type="time" name="global_start_time" value="{{ old('global_start_time', $config['global_notify']['start_time'] ?? '08:00') }}" class="w-full border-gray-300 rounded-md shadow-sm p-2.5 bg-gray-50 border">
|
||||
</div>
|
||||
<span class="text-gray-500 font-bold mt-6">至</span>
|
||||
<div class="flex-1">
|
||||
<label class="block text-sm font-bold text-gray-700 mb-1">允许推送结束时间</label>
|
||||
<input type="time" name="global_end_time" value="{{ old('global_end_time', $config['global_notify']['end_time'] ?? '22:00') }}" class="w-full border-gray-300 rounded-md shadow-sm p-2.5 bg-gray-50 border">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 3. 群通知设置 -->
|
||||
<div class="mb-8">
|
||||
<h3 class="text-md font-bold text-gray-800 border-b pb-2 mb-4">群聊通知设置</h3>
|
||||
<div class="mb-6 max-w-lg">
|
||||
|
||||
Reference in New Issue
Block a user