From f918bfc81a82d53d39694d5e5d0c78c9d97cc04c Mon Sep 17 00:00:00 2001 From: tsui110 Date: Tue, 3 Feb 2026 19:20:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BC=98=E6=83=A0=E5=88=B8?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/GamePassPurchasePopup.vue | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/components/GamePassPurchasePopup.vue b/components/GamePassPurchasePopup.vue index 64b5541..a46b9a7 100644 --- a/components/GamePassPurchasePopup.vue +++ b/components/GamePassPurchasePopup.vue @@ -263,8 +263,8 @@ async function fetchCoupons() { try { const userId = uni.getStorageSync('user_id') if (!userId) return - - const res = await getUserCoupons(userId, 1, 1, 100) // status=1 可用 + + const res = await getUserCoupons(userId, 0, 1, 20) // status=0 可用 let list = [] if (Array.isArray(res)) list = res else if (res && Array.isArray(res.coupons)) list = res.coupons @@ -273,14 +273,22 @@ async function fetchCoupons() { // 过滤出全场通用券 (scope_type = 1) 和金额券 (discount_type = 1) // 后端已限制次卡购买只能用全场券,这里前端也做一层过滤 + // 同时支持 balance_amount 和 remaining 字段 coupons.value = list.filter(c => { // 只显示 scope_type=1(全场通用)的优惠券 // 如果后端返回了 scope_type 字段 if (c.scope_type !== undefined && c.scope_type !== 1) return false - // 确保有余额 - if (!c.balance_amount || c.balance_amount <= 0) return false + // 确保有余额(兼容 balance_amount 和 remaining 字段) + const balance = c.balance_amount ?? c.remaining ?? c.amount + if (!balance || balance <= 0) return false return true - }) + }).map(c => ({ + // 统一转换为 balance_amount 字段供后续使用 + ...c, + balance_amount: c.balance_amount ?? c.remaining ?? c.amount + })) + + console.log('获取到的优惠券列表:', coupons.value) } catch (e) { console.error('获取优惠券失败:', e) coupons.value = []