优惠码Bug修复
This commit is contained in:
@@ -162,6 +162,18 @@ export default function SubscriptionContent() {
|
||||
// 计算价格(包含升级和优惠码)
|
||||
const calculatePrice = async (plan, cycle, promoCodeValue = null) => {
|
||||
try {
|
||||
// 确保优惠码值正确:只接受非空字符串,其他情况传null
|
||||
const validPromoCode = promoCodeValue && typeof promoCodeValue === 'string' && promoCodeValue.trim()
|
||||
? promoCodeValue.trim()
|
||||
: null;
|
||||
|
||||
logger.debug('SubscriptionContent', '计算价格', {
|
||||
plan: plan.name,
|
||||
cycle,
|
||||
promoCodeValue,
|
||||
validPromoCode
|
||||
});
|
||||
|
||||
const response = await fetch('/api/subscription/calculate-price', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -171,7 +183,7 @@ export default function SubscriptionContent() {
|
||||
body: JSON.stringify({
|
||||
to_plan: plan.name,
|
||||
to_cycle: cycle,
|
||||
promo_code: promoCodeValue || null
|
||||
promo_code: validPromoCode
|
||||
})
|
||||
});
|
||||
|
||||
@@ -191,7 +203,9 @@ export default function SubscriptionContent() {
|
||||
|
||||
// 验证优惠码
|
||||
const handleValidatePromoCode = async () => {
|
||||
if (!promoCode.trim()) {
|
||||
const trimmedCode = promoCode.trim();
|
||||
|
||||
if (!trimmedCode) {
|
||||
setPromoCodeError('请输入优惠码');
|
||||
return;
|
||||
}
|
||||
@@ -205,8 +219,8 @@ export default function SubscriptionContent() {
|
||||
setPromoCodeError('');
|
||||
|
||||
try {
|
||||
// 重新计算价格,包含优惠码
|
||||
const result = await calculatePrice(selectedPlan, selectedCycle, promoCode);
|
||||
// 重新计算价格,包含优惠码(使用去除空格后的值)
|
||||
const result = await calculatePrice(selectedPlan, selectedCycle, trimmedCode);
|
||||
|
||||
if (result && !result.promo_error) {
|
||||
setPromoCodeApplied(true);
|
||||
@@ -1171,6 +1185,11 @@ export default function SubscriptionContent() {
|
||||
stopAutoPaymentCheck();
|
||||
setPaymentOrder(null);
|
||||
setPaymentCountdown(0);
|
||||
// 清空优惠码状态
|
||||
setPromoCode('');
|
||||
setPromoCodeApplied(false);
|
||||
setPromoCodeError('');
|
||||
setPriceInfo(null);
|
||||
onPaymentModalClose();
|
||||
}}
|
||||
size="lg"
|
||||
|
||||
Reference in New Issue
Block a user