新增每日签到与补签卡功能

This commit is contained in:
2026-04-24 22:47:27 +08:00
parent 34356a26ae
commit be9fc09d9d
46 changed files with 3934 additions and 55 deletions
@@ -344,7 +344,7 @@
{
label: '🎭 道具',
desc: '',
type: 'one_time'
type: 'tools'
},
];
@@ -352,7 +352,7 @@
itemsEl.innerHTML = '';
groups.forEach(g => {
const items = data.items.filter(i => i.type === g.type);
const items = data.items.filter(i => g.type === 'tools' ? ['one_time', 'sign_repair'].includes(i.type) : i.type === g.type);
if (!items.length) return;
const section = document.createElement('div');
@@ -417,7 +417,7 @@
} else {
btn.className = 'shop-btn';
btn.innerHTML = `💰 ${Number(item.price).toLocaleString()}`;
btn.onclick = () => buyItem(item.id, item.name, item.price);
btn.onclick = () => buyItem(item.id, item.name, item.price, item.type);
}
row.appendChild(btn);
card.appendChild(row);
@@ -457,14 +457,23 @@
}
/** 购买商品 */
window.buyItem = function(itemId, name, price) {
// 使用全局弹窗替代原生 confirm(),通过 .then() 注册回调确保事件正确触发
window.chatDialog.confirm(
`确定花费 ${Number(price).toLocaleString()} 金币购买【${name}】吗?`,
'确认购买',
'#336699'
).then(ok => {
if (!ok) return;
window.buyItem = async function(itemId, name, price, typeOrRecipient = '', message = '', presetQuantity = null) {
const knownTypes = ['instant', 'duration', 'one_time', 'ring', 'auto_fishing', 'sign_repair'];
const type = knownTypes.includes(typeOrRecipient) ? typeOrRecipient : '';
const recipient = type === '' ? (typeOrRecipient || 'all') : 'all';
let quantity = Number(presetQuantity || 1);
if (type === 'sign_repair') {
quantity = await window.promptSignRepairQuantity?.({
name,
price,
description: '补签卡只能补签本月漏掉的未签到日期,不能补签上月或更早日期。',
});
if (quantity === null || quantity === undefined) return;
}
const signRepairNotice = type === 'sign_repair' ? '\n说明:补签卡只能补签本月未签到日期。' : '';
const submitPurchase = () => {
fetch('{{ route('shop.buy') }}', {
method: 'POST',
headers: {
@@ -473,7 +482,10 @@
'X-CSRF-TOKEN': _csrf()
},
body: JSON.stringify({
item_id: itemId
item_id: itemId,
recipient,
message: message || '',
quantity: quantity || 1
}),
})
.then(r => r.json())
@@ -494,6 +506,21 @@
}
})
.catch(() => showShopToast('⚠ 网络异常,请重试', false));
};
if (presetQuantity !== null) {
submitPurchase();
return;
}
// 使用全局弹窗替代原生 confirm(),通过 .then() 注册回调确保事件正确触发
window.chatDialog.confirm(
`确定花费 ${Number(price * quantity).toLocaleString()} 金币购买【${name}】${quantity > 1 ? ' × ' + quantity : ''} 吗?${signRepairNotice}`,
'确认购买',
'#336699'
).then(ok => {
if (!ok) return;
submitPurchase();
});
};