From 4ef95eaa27833836b4c78ccb8bee2e8fd403b49f Mon Sep 17 00:00:00 2001 From: lkddi Date: Fri, 27 Feb 2026 17:21:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=96=B0=E4=BA=BA?= =?UTF-8?q?=E9=A6=96=E6=AC=A1=E5=85=A5=E4=BD=8F=E8=81=8A=E5=A4=A9=E5=AE=A4?= =?UTF-8?q?=E5=A4=A7=E7=A4=BC=E5=8C=85=E8=87=AA=E5=8A=A8=E5=8F=91=E6=94=BE?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=886666=E9=87=91=E5=B8=81=20+=20?= =?UTF-8?q?=E6=BB=A1=E5=9C=BA=E7=83=9F=E8=8A=B1=20+=20=E5=85=AC=E5=B1=8F?= =?UTF-8?q?=E6=AC=A2=E8=BF=8E=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/ChatController.php | 83 +++++++++++++------ app/Models/User.php | 2 + ...d_has_received_new_gift_to_users_table.php | 28 +++++++ resources/views/chat/frame.blade.php | 15 +++- 4 files changed, 97 insertions(+), 31 deletions(-) create mode 100644 database/migrations/2026_02_27_091852_add_has_received_new_gift_to_users_table.php diff --git a/app/Http/Controllers/ChatController.php b/app/Http/Controllers/ChatController.php index 9e08efa..8067f58 100644 --- a/app/Http/Controllers/ChatController.php +++ b/app/Http/Controllers/ChatController.php @@ -72,36 +72,65 @@ class ChatController extends Controller // 2. 广播 UserJoined 事件,通知房间内的其他人 broadcast(new UserJoined($id, $user->username, $userData))->toOthers(); - // 3. 管理员(superlevel)进入时:触发全房间烟花特效 + 公屏欢迎公告 - if ($user->user_level >= $superLevel) { - // 广播烟花特效给所有在线用户 - broadcast(new \App\Events\EffectBroadcast($id, 'fireworks', $user->username)); + // 3. 新人首次进入:赠送 6666 金币、播放满场烟花、发送全场欢迎通告 + $newbieEffect = null; + if (! $user->has_received_new_gift) { + $user->increment('jjb', 6666); + $user->update(['has_received_new_gift' => true]); - // 发送欢迎公告消息(使用系统公告样式) - $welcomeMsg = [ - 'id' => $this->chatState->nextMessageId($id), - 'room_id' => $id, - 'from_user' => '系统公告', - 'to_user' => '大家', - 'content' => "🎉 欢迎管理员 {$user->username} 驾临本聊天室!请各位文明聊天!", - 'is_secret' => false, - 'font_color' => '#b91c1c', - 'action' => '', - 'sent_at' => now()->toDateTimeString(), - ]; - $this->chatState->pushMessage($id, $welcomeMsg); - broadcast(new MessageSent($id, $welcomeMsg)); - } + // 发送新人专属欢迎公告 + $newbieMsg = [ + 'id' => $this->chatState->nextMessageId($id), + 'room_id' => $id, + 'from_user' => '系统公告', + 'to_user' => '大家', + 'content' => "🎉 缤纷礼花满天飞,热烈欢迎新朋友 {$user->username} 首次驾临本聊天室!系统已自动赠送 6666 金币新人大礼包!", + 'is_secret' => false, + 'font_color' => '#b91c1c', + 'action' => '', + 'sent_at' => now()->toDateTimeString(), + ]; + $this->chatState->pushMessage($id, $newbieMsg); + broadcast(new MessageSent($id, $newbieMsg)); - // 4. 获取历史消息用于初次渲染 - // TODO: 可在前端通过请求另外的接口拉取历史记录,或者直接在这里 attach + // 广播烟花特效给此时已在房间的其他用户 + broadcast(new \App\Events\EffectBroadcast($id, 'fireworks', $user->username))->toOthers(); - // 渲染主聊天框架视图 - return view('chat.frame', [ - 'room' => $room, - 'user' => $user, - 'weekEffect' => $this->shopService->getActiveWeekEffect($user), // 周卡特效(登录自动播放) - ]); + // 传给前端,让新人自己的屏幕上也燃放烟花 + $newbieEffect = 'fireworks'; + } + + // 4. 管理员(superlevel)进入时:触发全房间烟花特效 + 公屏欢迎公告 + if ($user->user_level >= $superLevel) { + // 广播烟花特效给所有在线用户 + broadcast(new \App\Events\EffectBroadcast($id, 'fireworks', $user->username)); + + // 发送欢迎公告消息(使用系统公告样式) + $welcomeMsg = [ + 'id' => $this->chatState->nextMessageId($id), + 'room_id' => $id, + 'from_user' => '系统公告', + 'to_user' => '大家', + 'content' => "🎉 欢迎管理员 {$user->username} 驾临本聊天室!请各位文明聊天!", + 'is_secret' => false, + 'font_color' => '#b91c1c', + 'action' => '', + 'sent_at' => now()->toDateTimeString(), + ]; + $this->chatState->pushMessage($id, $welcomeMsg); + broadcast(new MessageSent($id, $welcomeMsg)); + } + + // 5. 获取历史消息用于初次渲染 + // TODO: 可在前端通过请求另外的接口拉取历史记录,或者直接在这里 attach + + // 渲染主聊天框架视图 + return view('chat.frame', [ + 'room' => $room, + 'user' => $user, + 'weekEffect' => $this->shopService->getActiveWeekEffect($user), // 周卡特效(登录自动播放) + 'newbieEffect' => $newbieEffect, // 新人入场专属特效 + ]); } /** diff --git a/app/Models/User.php b/app/Models/User.php index c1911b1..84e2465 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -42,6 +42,7 @@ class User extends Authenticatable 'hy_time', 'question', 'answer', + 'has_received_new_gift', ]; /** @@ -75,6 +76,7 @@ class User extends Authenticatable 'yx_time' => 'datetime', 'sj' => 'datetime', 'q3_time' => 'datetime', + 'has_received_new_gift' => 'boolean', ]; } diff --git a/database/migrations/2026_02_27_091852_add_has_received_new_gift_to_users_table.php b/database/migrations/2026_02_27_091852_add_has_received_new_gift_to_users_table.php new file mode 100644 index 0000000..b3db8a9 --- /dev/null +++ b/database/migrations/2026_02_27_091852_add_has_received_new_gift_to_users_table.php @@ -0,0 +1,28 @@ +boolean('has_received_new_gift')->default(false)->after('id')->comment('是否已领取新人礼包'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('has_received_new_gift'); + }); + } +}; diff --git a/resources/views/chat/frame.blade.php b/resources/views/chat/frame.blade.php index ad46620..414700e 100644 --- a/resources/views/chat/frame.blade.php +++ b/resources/views/chat/frame.blade.php @@ -103,13 +103,20 @@ @include('chat.partials.scripts') - {{-- 周卡特效:登录时自动播放(仅持卡用户可见) --}} - @if (!empty($weekEffect)) + {{-- 进房特效自动播放:新人烟花礼包 / 周卡特效 --}} + @if (!empty($newbieEffect) || !empty($weekEffect))