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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user