fix(polish): 订单购物车论坛粉边软化 + 论坛付费帖购链路
- 购物车/商品/论坛表面复用 #77 soft recipe(mix 边 + soft ring) - 论坛 visibility=pay:订单 resource + 余额扣费闭环 - VIP 价/免费解锁 + 购买 CTA/AJAX,复用现有 Order/Credits Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -675,6 +675,49 @@
|
||||
});
|
||||
}
|
||||
|
||||
function bindPurchaseButton(button) {
|
||||
button.addEventListener('click', function () {
|
||||
var topicId = parseInt(button.getAttribute('data-topic-id') || '0', 10);
|
||||
var price = button.getAttribute('data-price') || '0';
|
||||
var isFree = button.getAttribute('data-free') === '1';
|
||||
var feedback = button.parentElement ? button.parentElement.querySelector('.js-aksrt-action-feedback') : null;
|
||||
|
||||
if (!topicId) {
|
||||
return;
|
||||
}
|
||||
|
||||
var confirmMsg = isFree
|
||||
? '确认使用 VIP 免费解锁此主题?'
|
||||
: ('确认使用余额支付 ¥' + price + ' 购买此主题?');
|
||||
if (!window.confirm(confirmMsg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
button.disabled = true;
|
||||
setFeedback(feedback, isFree ? '正在解锁…' : '正在支付…', 'is-loading');
|
||||
|
||||
var data = new FormData();
|
||||
data.append('action', 'aksrt_forum_purchase_topic');
|
||||
data.append('topic_id', topicId);
|
||||
data.append('_nonce', rootData.forumNonce || '');
|
||||
|
||||
fetch((rootData.ajaxUrl || '/wp-admin/admin-ajax.php'), {
|
||||
method: 'POST',
|
||||
body: data,
|
||||
credentials: 'same-origin',
|
||||
}).then(function (r) { return r.json(); }).then(function (payload) {
|
||||
if (!payload.success) {
|
||||
throw new Error((payload.data && payload.data.message) || '购买失败');
|
||||
}
|
||||
setFeedback(feedback, '购买成功,正在刷新…', 'is-success');
|
||||
setTimeout(function () { window.location.reload(); }, 800);
|
||||
}).catch(function (error) {
|
||||
setFeedback(feedback, error.message || '购买失败', 'is-error');
|
||||
button.disabled = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function bindComposeCoverToggle(form) {
|
||||
var coverTypeSelect = form.querySelector('#compose-cover-type');
|
||||
var imageField = form.querySelector('#compose-cover-image-field');
|
||||
@@ -1411,6 +1454,7 @@
|
||||
document.querySelectorAll('.js-aksrt-topic-score').forEach(bindScoreButton);
|
||||
document.querySelectorAll('.js-aksrt-adopt-answer').forEach(bindAdoptButton);
|
||||
document.querySelectorAll('.js-aksrt-unlock-topic').forEach(bindUnlockButton);
|
||||
document.querySelectorAll('.js-aksrt-purchase-topic').forEach(bindPurchaseButton);
|
||||
bindForumCommentEngine();
|
||||
bindForumHomeTabs();
|
||||
bindBoardSortTabs();
|
||||
|
||||
Reference in New Issue
Block a user