From 9b55b5558bf4adeecb496854d55cec00e2b1939c Mon Sep 17 00:00:00 2001 From: lkddi Date: Sun, 1 Mar 2026 18:49:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=A9=9A=E5=A7=BB=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=EF=BC=9A=E2=91=A0=E7=A6=BB=E5=A9=9A=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E9=AD=85=E5=8A=9B=E6=83=A9=E7=BD=9A=E8=AD=A6?= =?UTF-8?q?=E5=91=8A=20=E2=91=A1=E5=A9=9A=E7=A4=BC=E6=A1=A3=E4=BD=8D?= =?UTF-8?q?=E5=BC=BA=E5=88=B6=E5=BF=85=E9=80=89=EF=BC=88=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=97=A0=E9=80=89=E9=A1=B9=E9=BB=98=E8=AE=A4=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E6=A1=A3=EF=BC=89=E2=91=A2=E5=A9=9A=E7=A4=BC=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=90=AB=E9=A2=86=E5=8F=96=E7=BA=A2=E5=8C=85=E6=8C=89=E9=92=AE?= =?UTF-8?q?=20=E2=91=A3AppendSystemMessage=E5=85=A8=E5=B1=80=E5=87=BD?= =?UTF-8?q?=E6=95=B0=EF=BC=88=E6=94=AF=E6=8C=81HTML=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Events/MarriageDivorceRequested.php | 13 ++++- .../chat/partials/marriage-modals.blade.php | 56 ++++++++++++++++--- 2 files changed, 59 insertions(+), 10 deletions(-) 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;