From 392b1b06bb296c75667c3906ae63a5379ba2b5b6 Mon Sep 17 00:00:00 2001 From: lkddi Date: Sun, 1 Mar 2026 19:27:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A9=9A=E7=A4=BC=E7=BA=A2?= =?UTF-8?q?=E5=8C=85=E9=A2=86=E5=8F=96=EF=BC=9A=E2=91=A0ChatController=20u?= =?UTF-8?q?serJoin=20=E5=86=99=E5=85=A5=20user=5Fid=20=E2=91=A1WeddingServ?= =?UTF-8?q?ice=20=E4=BB=8E=20room:1:users=20Hash=20=E8=AF=BB=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E7=94=A8=E6=88=B7=20=E2=91=A2=E6=96=B0=E9=83=8E?= =?UTF-8?q?=E6=96=B0=E5=A8=98=E4=B9=9F=E5=8F=AF=E9=A2=86=E7=BA=A2=E5=8C=85?= =?UTF-8?q?=20=E2=91=A3=E5=88=A0=E9=99=A4=E7=BB=93=E5=A9=9A=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=E5=86=97=E4=BD=99=E7=9A=84'=E4=B8=BE=E5=8A=9E?= =?UTF-8?q?=E5=A9=9A=E7=A4=BC'=E6=8C=89=E9=92=AE=20=E2=91=A4=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=E7=BA=A2=E5=8C=85=E9=A2=86=E5=8F=96=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E4=B8=BA=E6=A9=99=E8=89=B2=E6=B8=90=E5=8F=98=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/ChatController.php | 3 +- app/Services/WeddingService.php | 40 +++++++++---------- .../chat/partials/marriage-modals.blade.php | 21 ++++------ 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/app/Http/Controllers/ChatController.php b/app/Http/Controllers/ChatController.php index 54e140d..afe578d 100644 --- a/app/Http/Controllers/ChatController.php +++ b/app/Http/Controllers/ChatController.php @@ -71,6 +71,7 @@ class ChatController extends Controller // 获取当前在职职务信息(用于内容显示) $activePosition = $user->activePosition; $userData = [ + 'user_id' => $user->id, 'level' => $user->user_level, 'sex' => $user->sex, 'headface' => $user->headface, @@ -221,7 +222,7 @@ class ChatController extends Controller ->where('divorce_type', 'mutual') ->whereNotNull('divorcer_id') ->where('divorcer_id', '!=', $user->id) - ->where(function($q) use ($user) { + ->where(function ($q) use ($user) { $q->where('user_id', $user->id)->orWhere('partner_id', $user->id); }) ->first(); diff --git a/app/Services/WeddingService.php b/app/Services/WeddingService.php index a584a4c..77d8632 100644 --- a/app/Services/WeddingService.php +++ b/app/Services/WeddingService.php @@ -148,8 +148,6 @@ class WeddingService /** * 将预先设置好的定时婚礼(因求婚冻结)转为即刻开始(解冻并记录消费)。 - * - * @param WeddingCeremony $ceremony */ public function confirmCeremony(WeddingCeremony $ceremony): void { @@ -169,12 +167,12 @@ class WeddingService $marriage->partner->decrement('frozen_jjb', $ceremony->partner_amount); $this->currency->change($partner, 'gold', 0, CurrencySource::WEDDING_ENV_SEND, "求婚成功,正式发红包({$tierName})"); } - + // 将类型转为即时开始 $ceremony->update([ 'ceremony_type' => 'immediate', - 'ceremony_at' => now(), - 'expires_at' => now()->addHours($this->config->get('envelope_expire_hours', 24)) + 'ceremony_at' => now(), + 'expires_at' => now()->addHours($this->config->get('envelope_expire_hours', 24)), ]); } }); @@ -182,8 +180,6 @@ class WeddingService /** * 撤销由于求婚设置的婚礼,并且解冻/退还因为该婚礼冻结的金币。 - * - * @param WeddingCeremony $ceremony */ public function cancelAndRefund(WeddingCeremony $ceremony): void { @@ -219,11 +215,8 @@ class WeddingService return ['ok' => false, 'message' => '婚礼状态异常。', 'online_count' => 0]; } - // 获取当前在线用户(不含新郎新娘) - $onlineIds = $this->getOnlineUserIds(excludeIds: [ - $ceremony->marriage->user_id, - $ceremony->marriage->partner_id, - ]); + // 获取所有在线用户(含新郎新娘本人,让所有人都能领红包) + $onlineIds = $this->getOnlineUserIds(roomId: $ceremony->marriage->room_id ?? 1); // 在线人数为0时金币退还 if (count($onlineIds) === 0 && $ceremony->total_amount > 0) { @@ -370,20 +363,27 @@ class WeddingService } /** - * 获取当前在线用户 ID 列表(从 Redis chatroom_users)。 + * 从 Redis room:{roomId}:users Hash 获取当前在线用户 ID 列表。 * - * @param array $excludeIds 排除的用户 ID + * @param int $roomId 房间 ID * @return array */ - private function getOnlineUserIds(array $excludeIds = []): array + private function getOnlineUserIds(int $roomId = 1): array { - // chatroom_users 是 Hash,key=username,value=user_id(或 JSON) - // 实际取法根据现有 Redis 结构调整 try { - $raw = Redis::smembers('chatroom_online_ids'); - $ids = array_map('intval', $raw); + $key = "room:{$roomId}:users"; + $users = Redis::hgetall($key); + $ids = []; - return array_values(array_diff($ids, $excludeIds)); + foreach ($users as $username => $jsonInfo) { + $info = json_decode($jsonInfo, true); + // user_id 由 ChatController::join() 写入 userData + if (isset($info['user_id'])) { + $ids[] = (int) $info['user_id']; + } + } + + 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 7a426f7..c7b687d 100644 --- a/resources/views/chat/partials/marriage-modals.blade.php +++ b/resources/views/chat/partials/marriage-modals.blade.php @@ -253,15 +253,6 @@
- {{-- 举办婚礼按钮(仅对新婚夫妻显示) --}} -
- -
@@ -634,13 +625,17 @@ 红包有效期 24小时,过期自动消失