功能:送花/礼物系统完整开发
- 新增 Gift 模型和 gifts 数据表(7种默认花卉,各有图片/金币/魅力配置) - 7张花卉图片生成并存放于 public/images/gifts/ - 名片弹窗新增送礼物 UI:图片选择列表、金币/魅力标注、数量选择 - sendFlower 控制器方法:按 gift_id 查找礼物、扣金币、加魅力、广播消息 - 聊天消息渲染支持显示礼物图片(含弹跳动画效果) - 后台可在 gifts 表中管理花卉类型(名称、图标、图片、金币、魅力、排序、启禁用)
This commit is contained in:
@@ -240,7 +240,14 @@
|
||||
// 管理员公告/系统传音:大字醒目样式
|
||||
div.style.cssText =
|
||||
'background: linear-gradient(135deg, #fef2f2, #fff1f2); border: 2px solid #ef4444; border-radius: 6px; padding: 8px 12px; margin: 4px 0; box-shadow: 0 2px 4px rgba(239,68,68,0.15);';
|
||||
html = `<div style="font-size: 14px; font-weight: bold; color: #dc2626;">${msg.content}</div>`;
|
||||
// 如果是送花消息,显示礼物图片
|
||||
let giftHtml = '';
|
||||
if (msg.gift_image) {
|
||||
giftHtml =
|
||||
`<img src="${msg.gift_image}" alt="${msg.gift_name || ''}" style="display:inline-block;width:40px;height:40px;vertical-align:middle;margin-left:6px;animation:giftBounce 0.6s ease-in-out;">`;
|
||||
}
|
||||
html =
|
||||
`<div style="font-size: 14px; font-weight: bold; color: #dc2626;">${msg.content}${giftHtml}</div>`;
|
||||
} else {
|
||||
// 其他系统用户(钓鱼播报、AI小助手等):普通样式
|
||||
html =
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
</script>
|
||||
|
||||
{{-- ═══════════ 用户名片弹窗 (Alpine.js) ═══════════ --}}
|
||||
@php $gifts = \App\Models\Gift::activeList(); @endphp
|
||||
<div id="user-modal-container" x-data="{
|
||||
showUserModal: false,
|
||||
userInfo: {},
|
||||
@@ -71,6 +72,10 @@
|
||||
whisperList: [],
|
||||
showAnnounce: false,
|
||||
announceText: '',
|
||||
gifts: {{ Js::from($gifts) }},
|
||||
selectedGiftId: {{ $gifts->first()?->id ?? 0 }},
|
||||
giftCount: 1,
|
||||
sendingGift: false,
|
||||
|
||||
async fetchUser(username) {
|
||||
try {
|
||||
@@ -227,8 +232,20 @@
|
||||
alert(data.message);
|
||||
}
|
||||
} catch (e) { alert('网络异常'); }
|
||||
}
|
||||
}">
|
||||
},
|
||||
|
||||
async sendGift() {
|
||||
if (this.sendingGift || !this.selectedGiftId) return;
|
||||
this.sendingGift = true;
|
||||
try {
|
||||
const res = await fetch('/gift/flower', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content'), 'Content-Type'
|
||||
: 'application/json' , 'Accept' : 'application/json' }, body: JSON.stringify({ to_user: this.userInfo.username,
|
||||
room_id: window.chatContext.roomId, gift_id: this.selectedGiftId, count: this.giftCount }) }); const data=await
|
||||
res.json(); alert(data.message); if (data.status === 'success') { this.showUserModal=false; this.giftCount=1; } }
|
||||
catch (e) { alert('网络异常'); } this.sendingGift=false; } }">
|
||||
<div x-show="showUserModal" style="display: none;" class="modal-overlay" x-on:click.self="showUserModal = false">
|
||||
<div class="modal-card" x-transition>
|
||||
{{-- 弹窗头部 --}}
|
||||
@@ -273,6 +290,39 @@
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{{-- 送花/礼物互动区 --}}
|
||||
<div style="padding: 0 16px 12px;" x-show="userInfo.username !== window.chatContext.username">
|
||||
<div style="font-size: 11px; color: #e91e8f; margin-bottom: 6px; font-weight: bold;">🎁 送礼物</div>
|
||||
{{-- 礼物选择列表 --}}
|
||||
<div style="display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px;">
|
||||
<template x-for="g in gifts" :key="g.id">
|
||||
<div x-on:click="selectedGiftId = g.id"
|
||||
:style="selectedGiftId === g.id ? 'border: 2px solid #e91e63; background: #fce4ec;' :
|
||||
'border: 2px solid #eee; background: #fafafa;'"
|
||||
style="width: 68px; padding: 4px 2px; border-radius: 6px; text-align: center; cursor: pointer; transition: all 0.15s;">
|
||||
<img :src="'/images/gifts/' + g.image"
|
||||
style="width: 36px; height: 36px; object-fit: contain;" :alt="g.name">
|
||||
<div style="font-size: 10px; color: #333; margin-top: 2px;" x-text="g.name"></div>
|
||||
<div style="font-size: 9px; color: #e91e63;" x-text="g.cost + '💰 +' + g.charm + '✨'"></div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
{{-- 数量 + 送出按钮 --}}
|
||||
<div style="display: flex; gap: 6px; align-items: center;">
|
||||
<select x-model.number="giftCount"
|
||||
style="width: 60px; padding: 3px; border: 1px solid #f0a0c0; border-radius: 4px; font-size: 12px;">
|
||||
<option value="1">×1</option>
|
||||
<option value="5">×5</option>
|
||||
<option value="10">×10</option>
|
||||
<option value="99">×99</option>
|
||||
</select>
|
||||
<button x-on:click="sendGift()" :disabled="sendingGift"
|
||||
style="flex: 1; padding: 6px 10px; background: linear-gradient(135deg, #ff6b9d, #e91e63); color: #fff; border: none; border-radius: 6px; font-size: 12px; font-weight: bold; cursor: pointer; transition: opacity 0.15s;"
|
||||
:style="sendingGift ? 'opacity: 0.5; cursor: not-allowed;' : ''"
|
||||
x-text="sendingGift ? '送出中...' : '送出 💝'"></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- 特权操作(各按钮按等级独立显示) --}}
|
||||
@if ($myLevel >= $levelWarn || $room->master == Auth::user()->username)
|
||||
<div style="padding: 0 16px 12px;"
|
||||
|
||||
Reference in New Issue
Block a user