修复婚礼红包领取:①ChatController userJoin 写入 user_id ②WeddingService 从 room:1:users Hash 读在线用户 ③新郎新娘也可领红包 ④删除结婚弹窗冗余的'举办婚礼'按钮 ⑤升级红包领取按钮为橙色渐变样式

This commit is contained in:
2026-03-01 19:27:28 +08:00
parent 0990a13c2e
commit 392b1b06bb
3 changed files with 30 additions and 34 deletions
+2 -1
View File
@@ -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();
+20 -20
View File
@@ -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 是 Hashkey=usernamevalue=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 [];
}
@@ -253,15 +253,6 @@
</div>
<div style="padding:20px 24px;">
<div style="font-size:13px; color:#6b7280; margin-bottom:16px;" x-text="subText"></div>
{{-- 举办婚礼按钮(仅对新婚夫妻显示) --}}
<div x-show="isNewlywed"
style="display:none; display:flex; gap:10px; justify-content:center; margin-bottom:14px;">
<button x-on:click="openWeddingSetup(); close();"
style="padding:11px 24px; background:linear-gradient(135deg,#f59e0b,#d97706);
color:#fff; border:none; border-radius:12px; font-size:13px; font-weight:bold; cursor:pointer;">
🎊 立即举办婚礼!
</button>
</div>
<button x-on:click="close()"
style="padding:10px 32px; background:#f1f5f9; border:none; border-radius:10px;
font-size:13px; color:#6b7280; cursor:pointer;">关闭</button>
@@ -634,13 +625,17 @@
红包有效期 <strong style="color:#fcd34d;">24小时</strong>,过期自动消失
</div>
<button x-on:click="doClaim()" :disabled="claiming"
style="padding:14px 40px; border:none; border-radius:50px; font-size:16px;
font-weight:bold; cursor:pointer; transition:all .2s;"
style="display:block; width:100%; padding:14px 0; border:none;
border-radius:50px; font-size:16px; font-weight:bold;
cursor:pointer; transition:all .2s; letter-spacing:1px;
box-shadow:0 4px 20px rgba(245,158,11,.5);"
:style="claiming
?
'background:#fcd34d; color:#92400e; opacity:.7; cursor:not-allowed;' :
'background:linear-gradient(135deg,#fcd34d,#f59e0b); color:#92400e;'">
<span x-text="claiming ? '领取中…' : '🎁 点击领取'"></span>
'background:linear-gradient(135deg,#f59e0b,#d97706); color:#fff;'"
onmouseover="if(!this.disabled) this.style.transform='scale(1.04)'"
onmouseout="this.style.transform=''">
<span x-text="claiming ? '领取中…' : ' 点击领取红包'"></span>
</button>
</div>