feat(notice): NoticeSended 事件与登录提醒内置监听

This commit is contained in:
augushong
2026-10-12 12:09:01 +00:00
parent 02f77f4eca
commit 7aba2d02fe
6 changed files with 233 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
<?php
namespace base\common\event\AdminLoginSuccess;
use app\admin\model\SystemAdmin;
use app\common\service\NoticeService;
use think\facade\Log;
class NoticeEventBase
{
public function handle(SystemAdmin $admin)
{
try {
// 登录提醒场景默认关闭:无配置行(null 强转 0)不发,DB value 为字符串须强转 int
if ((int) sysconfig('notify', 'notify_login_scene_enable') === 0) {
return;
}
// 不传 channels=按场景注册渠道展开(admin_login=[inmail,email]),再经各管理员订阅矩阵过滤
NoticeService::send([$admin->id], '登录提醒', "账号 {$admin->username} 于 ".date('Y-m-d H:i').' 登录成功', ['scene' => 'admin_login']);
} catch (\Throwable $e) {
// 通知失败不得影响登录主流程
Log::error('admin login notice failed: ' . $e->getMessage());
}
}
}