mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-11-07 19:40:49 +08:00
feat(notice): NoticeSended 事件与登录提醒内置监听
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user