feat(wechat): 增加微信全局通知免打扰时间配置,避免夜间打扰用户

This commit is contained in:
2026-04-02 15:44:05 +08:00
parent f04512ac3f
commit 310e8bc07d
3 changed files with 77 additions and 1 deletions

View File

@@ -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;
}