结婚/婚礼/离婚通知持久化:新增事件监听器自动写入聊天消息数据库,用户重新登录后可在历史记录中看到通知

This commit is contained in:
2026-03-01 19:16:27 +08:00
parent eefdae93fe
commit 68c4ca7a96
2 changed files with 146 additions and 3 deletions

View File

@@ -1,11 +1,20 @@
<?php
/**
* 文件功能:应用服务提供者
*
* 负责注册和引导应用级服务:自定义 SMTP 配置动态加载、
* 婚姻系统消息事件订阅者注册等。
*/
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Listeners\SaveMarriageSystemMessage;
use App\Models\Sysparam;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
@@ -22,11 +31,14 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot(): void
{
// 注册婚姻系统消息订阅者(结婚/婚礼/离婚通知写入聊天历史)
Event::subscribe(SaveMarriageSystemMessage::class);
// 动态加载自定义 SMTP 配置 (如果有数据库则执行)
try {
if (Schema::hasTable('sysparam')) {
$smtpConfig = Sysparam::where('alias', 'like', 'smtp_%')->pluck('body', 'alias');
if ($smtpConfig->isNotEmpty() && $smtpConfig->get('smtp_host')) {
Config::set('mail.default', 'smtp');
Config::set('mail.mailers.smtp', [
@@ -36,7 +48,7 @@ class AppServiceProvider extends ServiceProvider
'encryption' => $smtpConfig->get('smtp_encryption', 'ssl'),
'username' => $smtpConfig->get('smtp_username'),
'password' => $smtpConfig->get('smtp_password'),
'timeout' => 10,
'timeout' => 10,
'local_domain' => env('MAIL_EHLO_DOMAIN'),
]);