完善婚姻系统:①离婚弹窗展示魅力惩罚警告 ②婚礼档位强制必选(移除无选项默认第一档)③婚礼消息含领取红包按钮 ④AppendSystemMessage全局函数(支持HTML)

This commit is contained in:
2026-03-01 18:49:11 +08:00
parent 6b32fe38c8
commit 9b55b5558b
2 changed files with 59 additions and 10 deletions

View File

@@ -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, // 协议离婚双方各扣魅力
];
}

View File

@@ -125,14 +125,15 @@
</div>
<span style="font-size:12px; font-weight:700; color:#4b5563;">预设婚礼档位</span>
</div>
<select x-model="selectedTierId"
style="width:100%; padding:8px 10px; border-radius:8px; border:1px solid #d1d5db; background:#fff; font-size:13px; color:#1f2937; margin-bottom:10px;">
<option value="">(不举办撒红包婚礼)</option>
<select x-model="selectedTierId" required
style="width:100%; padding:8px 10px; border-radius:8px; border:1px solid #f43f5e; background:#fff; font-size:13px; color:#1f2937; margin-bottom:10px;">
<template x-for="tier in tiers" :key="tier.id">
<option :value="tier.id" x-text="`${tier.icon} ${tier.name} (🪙 ${tier.amount})`">
</option>
</template>
</select>
<div style="font-size:11px; color:#9ca3af; margin-top:-6px; margin-bottom:8px;">🎊
必须选择婚礼档位,婚礼红包会撒给在场所有人!</div>
<div x-show="selectedTier" x-transition
style="border-radius:12px; padding:12px 14px; font-size:12px; line-height:1.7; transition:all .2s;"
@@ -535,6 +536,21 @@
{{-- ═══════════ Alpine.js 组件脚本 ═══════════ --}}
<script>
/**
* 全局辅助:向聊天主窗口追加一条婚姻系统公告(支持 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 = `<span style="color:#9d174d;">${html}</span>`;
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 = `<button onclick="(function(){const el=document.getElementById('wedding-envelope-modal');if(el)Alpine.$data(el).open(${JSON.stringify(detail)});})()"
style="display:inline-block; margin-left:10px; padding:3px 12px; border-radius:20px;
background:linear-gradient(135deg,#fcd34d,#f59e0b); color:#92400e;
border:none; font-size:12px; font-weight:bold; cursor:pointer;
vertical-align:middle; line-height:1.8;"
title="点击领取婚礼红包">🎁 点击领取红包</button>`;
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;