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); + });