新增:新人首次入住聊天室大礼包自动发放功能(6666金币 + 满场烟花 + 公屏欢迎)

This commit is contained in:
2026-02-27 17:21:33 +08:00
parent efc4dfd752
commit 4ef95eaa27
4 changed files with 97 additions and 31 deletions
+56 -27
View File
@@ -72,36 +72,65 @@ class ChatController extends Controller
// 2. 广播 UserJoined 事件,通知房间内的其他人 // 2. 广播 UserJoined 事件,通知房间内的其他人
broadcast(new UserJoined($id, $user->username, $userData))->toOthers(); broadcast(new UserJoined($id, $user->username, $userData))->toOthers();
// 3. 管理员(superlevel)进入时:触发全房间烟花特效 + 公屏欢迎 // 3. 新人首次进入:赠送 6666 金币、播放满场烟花、发送全场欢迎
if ($user->user_level >= $superLevel) { $newbieEffect = null;
// 广播烟花特效给所有在线用户 if (! $user->has_received_new_gift) {
broadcast(new \App\Events\EffectBroadcast($id, 'fireworks', $user->username)); $user->increment('jjb', 6666);
$user->update(['has_received_new_gift' => true]);
// 发送欢迎公告消息(使用系统公告样式) // 发送新人专属欢迎公告
$welcomeMsg = [ $newbieMsg = [
'id' => $this->chatState->nextMessageId($id), 'id' => $this->chatState->nextMessageId($id),
'room_id' => $id, 'room_id' => $id,
'from_user' => '系统公告', 'from_user' => '系统公告',
'to_user' => '大家', 'to_user' => '大家',
'content' => "🎉 欢迎管理员 <b>{$user->username}</b> 驾临本聊天室!请各位文明聊天", 'content' => "🎉 缤纷礼花满天飞,热烈欢迎新朋友 <b>{$user->username}</b> 首次驾临本聊天室!系统已自动赠送 6666 金币新人大礼包",
'is_secret' => false, 'is_secret' => false,
'font_color' => '#b91c1c', 'font_color' => '#b91c1c',
'action' => '', 'action' => '',
'sent_at' => now()->toDateTimeString(), 'sent_at' => now()->toDateTimeString(),
]; ];
$this->chatState->pushMessage($id, $welcomeMsg); $this->chatState->pushMessage($id, $newbieMsg);
broadcast(new MessageSent($id, $welcomeMsg)); broadcast(new MessageSent($id, $newbieMsg));
}
// 4. 获取历史消息用于初次渲染 // 广播烟花特效给此时已在房间的其他用户
// TODO: 可在前端通过请求另外的接口拉取历史记录,或者直接在这里 attach broadcast(new \App\Events\EffectBroadcast($id, 'fireworks', $user->username))->toOthers();
// 渲染主聊天框架视图 // 传给前端,让新人自己的屏幕上也燃放烟花
return view('chat.frame', [ $newbieEffect = 'fireworks';
'room' => $room, }
'user' => $user,
'weekEffect' => $this->shopService->getActiveWeekEffect($user), // 周卡特效(登录自动播放) // 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' => "🎉 欢迎管理员 <b>{$user->username}</b> 驾临本聊天室!请各位文明聊天!",
'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, // 新人入场专属特效
]);
} }
/** /**
+2
View File
@@ -42,6 +42,7 @@ class User extends Authenticatable
'hy_time', 'hy_time',
'question', 'question',
'answer', 'answer',
'has_received_new_gift',
]; ];
/** /**
@@ -75,6 +76,7 @@ class User extends Authenticatable
'yx_time' => 'datetime', 'yx_time' => 'datetime',
'sj' => 'datetime', 'sj' => 'datetime',
'q3_time' => 'datetime', 'q3_time' => 'datetime',
'has_received_new_gift' => 'boolean',
]; ];
} }
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->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');
});
}
};
+11 -4
View File
@@ -103,13 +103,20 @@
@include('chat.partials.scripts') @include('chat.partials.scripts')
{{-- 周卡特效:登录时自动播放(仅持卡用户可见) --}} {{-- 进房特效自动播放:新人烟花礼包 / 周卡特效 --}}
@if (!empty($weekEffect)) @if (!empty($newbieEffect) || !empty($weekEffect))
<script> <script>
/** 周卡特效:延迟1秒待页面完成加载后自动播放 */ /**
* 延迟1秒待页面完成初始化后,自动播放进房附带的特效
* 优先级:如果有新人礼包特效,优先播放新人大礼包;如果没有,再播放周卡特效
*/
setTimeout(() => { setTimeout(() => {
if (window.EffectManager) { if (window.EffectManager) {
window.EffectManager.play('{{ $weekEffect }}'); @if (!empty($newbieEffect))
window.EffectManager.play('{{ $newbieEffect }}');
@elseif (!empty($weekEffect))
window.EffectManager.play('{{ $weekEffect }}');
@endif
} }
}, 1000); }, 1000);
</script> </script>