修复婚礼红包领取:①ChatController userJoin 写入 user_id ②WeddingService 从 room:1:users Hash 读在线用户 ③新郎新娘也可领红包 ④删除结婚弹窗冗余的'举办婚礼'按钮 ⑤升级红包领取按钮为橙色渐变样式
This commit is contained in:
@@ -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<int> $excludeIds 排除的用户 ID
|
||||
* @param int $roomId 房间 ID
|
||||
* @return array<int>
|
||||
*/
|
||||
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 [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user