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());
|
||||
}
|
||||
}
|
||||
}
|
||||
20
extend/base/common/event/NoticeSended/LogEventBase.php
Normal file
20
extend/base/common/event/NoticeSended/LogEventBase.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace base\common\event\NoticeSended;
|
||||
|
||||
use think\facade\Log;
|
||||
|
||||
class LogEventBase
|
||||
{
|
||||
public function handle(array $payload)
|
||||
{
|
||||
// 事件监听处理:payload = [$notice(模型), $targets(投递行数组)](NoticeServiceBase::send trigger 形态)
|
||||
[$notice, $targets] = $payload;
|
||||
|
||||
Log::info('notice sended', [
|
||||
'notice_id' => (int) $notice->id,
|
||||
'target_count' => count($targets),
|
||||
'channels' => array_values(array_unique(array_column($targets, 'channel'))),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user