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小时,过期自动消失