From 0ca028f73d87dd6951692a96ebe93b29eaaedb61 Mon Sep 17 00:00:00 2001 From: lkddi Date: Wed, 18 Mar 2026 20:12:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=B5=A0=E9=80=81=E9=87=91?= =?UTF-8?q?=E5=B8=81=E5=8A=9F=E8=83=BD=EF=BC=9A=E4=BB=BB=E6=84=8F=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=8F=AF=E4=BB=8E=E8=87=AA=E5=B7=B1=E4=BD=99=E9=A2=9D?= =?UTF-8?q?=E8=B5=A0=E9=80=81=E9=87=91=E5=B8=81=E7=BB=99=E4=BB=96=E4=BA=BA?= =?UTF-8?q?=EF=BC=8C=E6=88=90=E5=8A=9F=E5=90=8E=E8=81=8A=E5=A4=A9=E5=AE=A4?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E4=BC=A0=E9=9F=B3=E5=B9=BF=E6=92=AD=EF=BC=9B?= =?UTF-8?q?=E8=81=8C=E5=8A=A1=E5=A5=96=E5=8A=B1=E9=87=91=E5=B8=81=E7=A7=BB?= =?UTF-8?q?=E5=85=A5=E7=AE=A1=E7=90=86=E5=8C=BA=EF=BC=8C=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=8C=BA=E7=A7=81=E4=BF=A1=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/ChatController.php | 69 +++++++++++++++++++ resources/views/chat/frame.blade.php | 2 + .../chat/partials/layout/input-bar.blade.php | 7 +- .../chat/partials/user-actions.blade.php | 67 ++++++++++++++++-- routes/web.php | 1 + 5 files changed, 137 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/ChatController.php b/app/Http/Controllers/ChatController.php index a2b32ae..75b5b3b 100644 --- a/app/Http/Controllers/ChatController.php +++ b/app/Http/Controllers/ChatController.php @@ -1135,4 +1135,73 @@ class ChatController extends Controller return $isLeveledUp; } + + /** + * 用户间赠送金币(任何登录用户均可调用) + * + * 从自己的余额中扣除指定金额,转入对方账户, + * 并在房间内通过「系统传音」广播一条赠送提示。 + */ + public function giftGold(Request $request): JsonResponse + { + $request->validate([ + 'to_user' => 'required|string', + 'room_id' => 'required|integer', + 'amount' => 'required|integer|min:1|max:999999', + ]); + + $sender = Auth::user(); + $toName = $request->input('to_user'); + $roomId = $request->integer('room_id'); + $amount = $request->integer('amount'); + + // 不能给自己转账 + if ($toName === $sender->username) { + return response()->json(['status' => 'error', 'message' => '不能给自己赠送哦~']); + } + + // 查目标用户 + $receiver = User::where('username', $toName)->first(); + if (! $receiver) { + return response()->json(['status' => 'error', 'message' => '用户不存在']); + } + + // 余额校验 + if (($sender->jjb ?? 0) < $amount) { + return response()->json([ + 'status' => 'error', + 'message' => '金币不足!您当前余额 '.($sender->jjb ?? 0)." 金币,无法赠送 {$amount} 金币。", + ]); + } + + // 执行转账(直接操作字段,与 sendFlower 保持一致风格) + $sender->decrement('jjb', $amount); + $receiver->increment('jjb', $amount); + + // 广播「系统传音」条目至全房间 + $sysMsg = [ + 'id' => $this->chatState->nextMessageId($roomId), + 'room_id' => $roomId, + 'from_user' => '系统传音', + 'to_user' => '大家', + 'content' => "💝 【{$sender->username}】 向 【{$toName}】 赠送了 {$amount} 金币!", + 'is_secret' => false, + 'font_color' => '#b45309', + 'action' => '', + 'sent_at' => now()->toDateTimeString(), + ]; + + $this->chatState->pushMessage($roomId, $sysMsg); + broadcast(new MessageSent($roomId, $sysMsg)); + SaveMessageJob::dispatch($sysMsg); + + return response()->json([ + 'status' => 'success', + 'message' => "赠送成功!已向 {$toName} 赠送 {$amount} 金币。", + 'data' => [ + 'my_jjb' => $sender->fresh()->jjb, + 'target_jjb' => $receiver->fresh()->jjb, + ], + ]); + } } diff --git a/resources/views/chat/frame.blade.php b/resources/views/chat/frame.blade.php index 612b253..eb8a409 100644 --- a/resources/views/chat/frame.blade.php +++ b/resources/views/chat/frame.blade.php @@ -69,6 +69,8 @@ rewardUrl: "{{ route('command.reward') }}", rewardQuotaUrl: "{{ route('command.reward_quota') }}", userJjb: {{ (int) $user->jjb }}, // 当前用户金币(求婚前金额预检查用) + myGold: {{ (int) $user->jjb }}, // 赠金币面板显示余额用(赠送成功后前端更新) + // ─── 婚姻系统 ────────────────────────────── minWeddingCost: {{ (int) \App\Models\WeddingTier::where('is_active', true)->orderBy('amount')->value('amount') ?? 0 }}, marriage: { diff --git a/resources/views/chat/partials/layout/input-bar.blade.php b/resources/views/chat/partials/layout/input-bar.blade.php index 23704ad..e73ef81 100644 --- a/resources/views/chat/partials/layout/input-bar.blade.php +++ b/resources/views/chat/partials/layout/input-bar.blade.php @@ -96,7 +96,8 @@ ]; @endphp @foreach ($welcomeMessages as $msg) -
{{ $msg }}
+
+ {{ $msg }}
@endforeach @@ -145,8 +146,8 @@ {{-- 第二行:输入框 + 发送 --}}
- +
diff --git a/resources/views/chat/partials/user-actions.blade.php b/resources/views/chat/partials/user-actions.blade.php index 0536094..df34f2d 100644 --- a/resources/views/chat/partials/user-actions.blade.php +++ b/resources/views/chat/partials/user-actions.blade.php @@ -759,7 +759,7 @@ {{-- 操作按钮区:加好友 + 送礼物 + 送金币(有职务且有奖励权限时显示) --}} -
+
+ {{-- 内联赠送金币面板 --}} +
+
+ 💰 赠送金币给 + +
+
您当前余额: 金币
+
+ + +
+
+ {{-- 内联礼物面板 --}}
🔍 私信 @endif + {{-- 职务奖励金币(凭空产生),仅有在职职务且 max_reward != 0 的人可见 --}} + @if (Auth::user()->activePosition || $myLevel >= $superLevel) + + @endif
@endif diff --git a/routes/web.php b/routes/web.php index f860a5c..cb4b284 100644 --- a/routes/web.php +++ b/routes/web.php @@ -270,6 +270,7 @@ Route::middleware(['chat.auth'])->group(function () { // ---- 送花/礼物互动 ---- Route::post('/gift/flower', [ChatController::class, 'sendFlower'])->name('gift.flower'); + Route::post('/gift/gold', [ChatController::class, 'giftGold'])->name('gift.gold'); // ---- 管理员命令(聊天室内实时操作)---- Route::post('/command/warn', [AdminCommandController::class, 'warn'])->name('command.warn');