diff --git a/app/Events/MarriageDivorceRequested.php b/app/Events/MarriageDivorceRequested.php index c6c8fdf..ac45755 100644 --- a/app/Events/MarriageDivorceRequested.php +++ b/app/Events/MarriageDivorceRequested.php @@ -52,13 +52,20 @@ class MarriageDivorceRequested implements ShouldBroadcastNow { $this->marriage->load(['user:id,username', 'partner:id,username']); + $divorcerUsername = $this->marriage->user_id === $this->marriage->divorcer_id + ? $this->marriage->user?->username + : $this->marriage->partner?->username; + + // 读取协议离婚魅力惩罚供前端展示 + $penalty = (int) \App\Models\MarriageConfig::where('key', 'divorce_mutual_charm')->value('value'); + return [ 'marriage_id' => $this->marriage->id, - 'divorcer_username' => $this->marriage->user_id === $this->marriage->divorcer_id - ? $this->marriage->user?->username - : $this->marriage->partner?->username, + 'divorcer_username' => $divorcerUsername, + 'initiator_name' => $divorcerUsername, // 前端兼容字段 'timeout_hours' => 72, 'requested_at' => $this->marriage->divorce_requested_at, + 'mutual_charm_penalty' => $penalty, // 协议离婚双方各扣魅力 ]; } diff --git a/resources/views/chat/partials/marriage-modals.blade.php b/resources/views/chat/partials/marriage-modals.blade.php index 72b90d1..1c523a5 100644 --- a/resources/views/chat/partials/marriage-modals.blade.php +++ b/resources/views/chat/partials/marriage-modals.blade.php @@ -125,14 +125,15 @@ 预设婚礼档位 - - (不举办撒红包婚礼) + + 🎊 + 必须选择婚礼档位,婚礼红包会撒给在场所有人! + /** + * 全局辅助:向聊天主窗口追加一条婚姻系统公告(支持 HTML 内容,如按钮) + * 使用 innerHTML 而非 textContent,以支持内嵌的领取按钮等交互元素。 + */ + window.appendSystemMessage = function(html) { + const container = document.getElementById('chat-messages-container'); + if (!container) return; + const div = document.createElement('div'); + div.style.cssText = + 'background:linear-gradient(135deg,#fdf4ff,#fce7f3); border-left:3px solid #ec4899; border-radius:6px; padding:5px 12px; margin:3px 0; font-size:13px; line-height:1.6;'; + div.innerHTML = `${html}`; + container.appendChild(div); + container.scrollTop = container.scrollHeight; + }; + /** * 求婚弹窗组件 */ @@ -546,7 +562,7 @@ rings: [], selectedRing: null, tiers: @json(\App\Models\WeddingTier::where('is_active', true)->orderBy('amount')->get()), - selectedTierId: '', + selectedTierId: @json(\App\Models\WeddingTier::where('is_active', true)->orderBy('amount')->value('id') ?? ''), // 默认选最小档位 loading: false, sending: false, error: '', @@ -1018,13 +1034,35 @@ if (el) Alpine.$data(el).open(detail); }); - /** 收到婚礼庆典(全局,显示红包) */ + /** 收到婚礼庆典(全局,显示红包 + 公屏系统消息) */ window.addEventListener('chat:wedding-celebration', (e) => { const detail = e.detail; + const groomName = detail.user?.username ?? '??'; + const brideName = detail.partner?.username ?? '??'; + const tierIcon = detail.tier_icon ?? '🎊'; + const tierName = detail.tier_name ?? '婚礼'; + const amount = detail.total_amount ? Number(detail.total_amount).toLocaleString() : '?'; + const ceremonyId = detail.ceremony_id; + + // 公屏追加带按钮的系统消息 + if (typeof appendSystemMessage === 'function') { + const claimBtn = `🎁 点击领取红包`; + appendSystemMessage( + `${tierIcon} ${groomName} 与 ${brideName} 举办了【${tierName}】!总金额 🪙${amount} 金币,快来抢红包!${claimBtn}` + ); + } + + // 同时弹出全屏红包弹窗 const el = document.getElementById('wedding-envelope-modal'); if (el) Alpine.$data(el).open(detail); }); + /** 求婚被拒(私人频道,发起方) */ window.addEventListener('chat:marriage-rejected', (e) => { const { @@ -1051,10 +1089,14 @@ window.addEventListener('chat:divorce-requested', (e) => { const { initiator_name, - marriage_id + marriage_id, + mutual_charm_penalty } = e.detail; + const penaltyTip = mutual_charm_penalty > 0 ? + `\n\n⚠️ 双方各将被扣除 ${mutual_charm_penalty} 点魅力值作为惩罚。` : + ''; window.chatDialog?.confirm( - `${initiator_name} 申请与你协议离婚,是否同意?`, + `${initiator_name} 申请与你协议离婚,是否同意?${penaltyTip}`, '离婚申请 💔' ).then(ok => { if (!ok) return;