From a37b04aca025b85ac20a9d6ee2b8e5279f7ec255 Mon Sep 17 00:00:00 2001 From: lkddi Date: Sun, 1 Mar 2026 19:36:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BA=A2=E5=8C=85=E9=A2=86?= =?UTF-8?q?=E5=8F=96=E4=B8=89=E9=87=8D=E9=97=AE=E9=A2=98=EF=BC=9A=E2=91=A0?= =?UTF-8?q?getOnlineUserIds=20=E5=85=BC=E5=AE=B9=E6=97=A7=E7=89=88?= =?UTF-8?q?=E7=94=A8=E6=88=B7(fallback=E6=95=B0=E6=8D=AE=E5=BA=93=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2)=20=E2=91=A1=E8=81=8A=E5=A4=A9=E9=A2=86=E5=8F=96?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E7=94=A8=E5=85=A8=E5=B1=80Map=E6=9B=BF?= =?UTF-8?q?=E4=BB=A3=E5=86=85=E5=B5=8CJSON=E9=81=BF=E5=85=8DHTML=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E7=A0=B4=E5=9D=8F=20=E2=91=A2doClaim=E6=94=B9?= =?UTF-8?q?=E5=88=A4=20data.ok=20=E8=80=8C=E9=9D=9E=E4=B8=8D=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E7=9A=84=20data.status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/WeddingService.php | 20 ++++++++++++++++++- .../chat/partials/marriage-modals.blade.php | 19 +++++++++++------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/Services/WeddingService.php b/app/Services/WeddingService.php index 77d8632..274d5f1 100644 --- a/app/Services/WeddingService.php +++ b/app/Services/WeddingService.php @@ -364,6 +364,7 @@ class WeddingService /** * 从 Redis room:{roomId}:users Hash 获取当前在线用户 ID 列表。 + * 若 Hash value 中无 user_id(旧版登录用户),则用 username 批量查库补齐。 * * @param int $roomId 房间 ID * @return array @@ -373,16 +374,33 @@ class WeddingService try { $key = "room:{$roomId}:users"; $users = Redis::hgetall($key); + if (empty($users)) { + return []; + } + $ids = []; + $fallbacks = []; // 需要 fallback 查库的用户名 foreach ($users as $username => $jsonInfo) { $info = json_decode($jsonInfo, true); - // user_id 由 ChatController::join() 写入 userData if (isset($info['user_id'])) { + // 新版登录:user_id 直接存在 Redis $ids[] = (int) $info['user_id']; + } else { + // 旧版登录(修复前):user_id 缺失,记录 username 待批量查库 + $fallbacks[] = $username; } } + // 对旧用户批量查库补齐 user_id + if (! empty($fallbacks)) { + $dbIds = User::whereIn('username', $fallbacks) + ->pluck('id') + ->map(fn ($id) => (int) $id) + ->all(); + $ids = array_merge($ids, $dbIds); + } + return array_values(array_unique($ids)); } catch (\Throwable) { return []; diff --git a/resources/views/chat/partials/marriage-modals.blade.php b/resources/views/chat/partials/marriage-modals.blade.php index f66f5e2..55a2a91 100644 --- a/resources/views/chat/partials/marriage-modals.blade.php +++ b/resources/views/chat/partials/marriage-modals.blade.php @@ -1225,7 +1225,7 @@ }) }); const data = await res.json(); - if (data.status === 'success') { + if (data.ok) { this.claimed = true; this.claimedAmount = data.amount || 0; } else { @@ -1327,14 +1327,18 @@ const amount = detail.total_amount ? Number(detail.total_amount).toLocaleString() : '?'; const ceremonyId = detail.ceremony_id; - // 公屏追加带按钮的系统消息 + // 将 detail 存入全局 Map,避免 onclick 属性内嵌 JSON 被双引号破坏 + if (!window._weddingEnvelopes) window._weddingEnvelopes = {}; + window._weddingEnvelopes[ceremonyId] = detail; + + // 公屏追加带按钮的系统消息(按钮通过 ceremonyId 引用全局 Map) if (typeof appendSystemMessage === 'function') { - const claimBtn = ``; + vertical-align:middle; line-height:1.8; box-shadow:0 2px 8px rgba(0,0,0,.3);" + title="点击领取婚礼红包">🧧 点击领取红包`; appendSystemMessage( `${tierIcon} ${groomName} 与 ${brideName} 举办了【${tierName}】!总金额 🪙${amount} 金币,快来抢红包!${claimBtn}` ); @@ -1343,6 +1347,7 @@ // 同时弹出全屏红包弹窗 const el = document.getElementById('wedding-envelope-modal'); if (el) Alpine.$data(el).open(detail); + });