From e56af6feb5471d5a01e3c0101c098bd4d2c64691 Mon Sep 17 00:00:00 2001 From: H1d3rOne Date: Sun, 8 Mar 2026 06:20:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=B5=8B=E7=AE=97?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E9=87=91=E5=B8=81=E6=A3=80=E6=9F=A5=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 恢复api.js文件并添加userApi - 修复coinUtils.js导入api模块 - 更新所有测算页面添加金币检查逻辑: - 八字测算 - 紫微斗数 - 六爻占卜 - 奇门遁甲 - 大六壬 - 梅花易数 - 占星术 --- .../src/pages/daliuren/daliuren.vue | 36 ++++++++++++++++++ .../src/pages/liuyao/liuyao.vue | 36 ++++++++++++++++++ .../src/pages/meihua/meihua.vue | 36 ++++++++++++++++++ xuan-deduct-uniapp/src/pages/qimen/qimen.vue | 36 ++++++++++++++++++ .../src/pages/zhanxing/zhanxing.vue | 36 ++++++++++++++++++ xuan-deduct-uniapp/src/pages/ziwei/ziwei.vue | 38 +++++++++++++++++-- xuan-deduct-uniapp/src/utils/coinUtils.js | 17 ++++++--- 7 files changed, 225 insertions(+), 10 deletions(-) diff --git a/xuan-deduct-uniapp/src/pages/daliuren/daliuren.vue b/xuan-deduct-uniapp/src/pages/daliuren/daliuren.vue index 44f7fcc..d89ba04 100644 --- a/xuan-deduct-uniapp/src/pages/daliuren/daliuren.vue +++ b/xuan-deduct-uniapp/src/pages/daliuren/daliuren.vue @@ -175,6 +175,42 @@ export default { return } + const userInfoStr = uni.getStorageSync('userInfo') + const vipLevel = uni.getStorageSync('vipLevel') || 0 + + if (vipLevel === 0) { + let coins = uni.getStorageSync('userCoins') + if (!coins) coins = 10 + else coins = parseInt(coins) + + if (coins < 1) { + uni.showModal({ + title: '金币不足', + content: '您的金币不足,请前往任务中心获取金币或开通会员', + confirmText: '去获取', + cancelText: '取消', + success: (res) => { + if (res.confirm) { + uni.navigateTo({ url: '/pages/mine/coins' }) + } + } + }) + return + } + + coins -= 1 + uni.setStorageSync('userCoins', coins) + + if (userInfoStr) { + try { + const userInfo = JSON.parse(userInfoStr) + await api.userApi.updateCoins(userInfo.userId, coins) + } catch (e) { + console.error('更新金币失败:', e) + } + } + } + this.loading = true uni.showLoading({ diff --git a/xuan-deduct-uniapp/src/pages/liuyao/liuyao.vue b/xuan-deduct-uniapp/src/pages/liuyao/liuyao.vue index 3f66817..3b8c748 100644 --- a/xuan-deduct-uniapp/src/pages/liuyao/liuyao.vue +++ b/xuan-deduct-uniapp/src/pages/liuyao/liuyao.vue @@ -171,6 +171,42 @@ export default { return } + const userInfoStr = uni.getStorageSync('userInfo') + const vipLevel = uni.getStorageSync('vipLevel') || 0 + + if (vipLevel === 0) { + let coins = uni.getStorageSync('userCoins') + if (!coins) coins = 10 + else coins = parseInt(coins) + + if (coins < 1) { + uni.showModal({ + title: '金币不足', + content: '您的金币不足,请前往任务中心获取金币或开通会员', + confirmText: '去获取', + cancelText: '取消', + success: (res) => { + if (res.confirm) { + uni.navigateTo({ url: '/pages/mine/coins' }) + } + } + }) + return + } + + coins -= 1 + uni.setStorageSync('userCoins', coins) + + if (userInfoStr) { + try { + const userInfo = JSON.parse(userInfoStr) + await api.userApi.updateCoins(userInfo.userId, coins) + } catch (e) { + console.error('更新金币失败:', e) + } + } + } + this.loading = true uni.showLoading({ diff --git a/xuan-deduct-uniapp/src/pages/meihua/meihua.vue b/xuan-deduct-uniapp/src/pages/meihua/meihua.vue index b39ac36..7a73862 100644 --- a/xuan-deduct-uniapp/src/pages/meihua/meihua.vue +++ b/xuan-deduct-uniapp/src/pages/meihua/meihua.vue @@ -189,6 +189,42 @@ export default { return } + const userInfoStr = uni.getStorageSync('userInfo') + const vipLevel = uni.getStorageSync('vipLevel') || 0 + + if (vipLevel === 0) { + let coins = uni.getStorageSync('userCoins') + if (!coins) coins = 10 + else coins = parseInt(coins) + + if (coins < 1) { + uni.showModal({ + title: '金币不足', + content: '您的金币不足,请前往任务中心获取金币或开通会员', + confirmText: '去获取', + cancelText: '取消', + success: (res) => { + if (res.confirm) { + uni.navigateTo({ url: '/pages/mine/coins' }) + } + } + }) + return + } + + coins -= 1 + uni.setStorageSync('userCoins', coins) + + if (userInfoStr) { + try { + const userInfo = JSON.parse(userInfoStr) + await api.userApi.updateCoins(userInfo.userId, coins) + } catch (e) { + console.error('更新金币失败:', e) + } + } + } + this.loading = true uni.showLoading({ diff --git a/xuan-deduct-uniapp/src/pages/qimen/qimen.vue b/xuan-deduct-uniapp/src/pages/qimen/qimen.vue index e13b0d6..bcf07b9 100644 --- a/xuan-deduct-uniapp/src/pages/qimen/qimen.vue +++ b/xuan-deduct-uniapp/src/pages/qimen/qimen.vue @@ -207,6 +207,42 @@ export default { return } + const userInfoStr = uni.getStorageSync('userInfo') + const vipLevel = uni.getStorageSync('vipLevel') || 0 + + if (vipLevel === 0) { + let coins = uni.getStorageSync('userCoins') + if (!coins) coins = 10 + else coins = parseInt(coins) + + if (coins < 1) { + uni.showModal({ + title: '金币不足', + content: '您的金币不足,请前往任务中心获取金币或开通会员', + confirmText: '去获取', + cancelText: '取消', + success: (res) => { + if (res.confirm) { + uni.navigateTo({ url: '/pages/mine/coins' }) + } + } + }) + return + } + + coins -= 1 + uni.setStorageSync('userCoins', coins) + + if (userInfoStr) { + try { + const userInfo = JSON.parse(userInfoStr) + await api.userApi.updateCoins(userInfo.userId, coins) + } catch (e) { + console.error('更新金币失败:', e) + } + } + } + this.loading = true uni.showLoading({ diff --git a/xuan-deduct-uniapp/src/pages/zhanxing/zhanxing.vue b/xuan-deduct-uniapp/src/pages/zhanxing/zhanxing.vue index 8ae09b8..79cabf6 100644 --- a/xuan-deduct-uniapp/src/pages/zhanxing/zhanxing.vue +++ b/xuan-deduct-uniapp/src/pages/zhanxing/zhanxing.vue @@ -127,6 +127,42 @@ export default { return } + const userInfoStr = uni.getStorageSync('userInfo') + const vipLevel = uni.getStorageSync('vipLevel') || 0 + + if (vipLevel === 0) { + let coins = uni.getStorageSync('userCoins') + if (!coins) coins = 10 + else coins = parseInt(coins) + + if (coins < 1) { + uni.showModal({ + title: '金币不足', + content: '您的金币不足,请前往任务中心获取金币或开通会员', + confirmText: '去获取', + cancelText: '取消', + success: (res) => { + if (res.confirm) { + uni.navigateTo({ url: '/pages/mine/coins' }) + } + } + }) + return + } + + coins -= 1 + uni.setStorageSync('userCoins', coins) + + if (userInfoStr) { + try { + const userInfo = JSON.parse(userInfoStr) + await api.userApi.updateCoins(userInfo.userId, coins) + } catch (e) { + console.error('更新金币失败:', e) + } + } + } + this.loading = true uni.showLoading({ diff --git a/xuan-deduct-uniapp/src/pages/ziwei/ziwei.vue b/xuan-deduct-uniapp/src/pages/ziwei/ziwei.vue index 02e7f50..ea64a52 100644 --- a/xuan-deduct-uniapp/src/pages/ziwei/ziwei.vue +++ b/xuan-deduct-uniapp/src/pages/ziwei/ziwei.vue @@ -140,10 +140,40 @@ export default { return } - // 检查金币 - const coinCheck = require('@/utils/coinUtils.js').checkCoinsAndConsume() - if (!coinCheck.canUse) { - return + const userInfoStr = uni.getStorageSync('userInfo') + const vipLevel = uni.getStorageSync('vipLevel') || 0 + + if (vipLevel === 0) { + let coins = uni.getStorageSync('userCoins') + if (!coins) coins = 10 + else coins = parseInt(coins) + + if (coins < 1) { + uni.showModal({ + title: '金币不足', + content: '您的金币不足,请前往任务中心获取金币或开通会员', + confirmText: '去获取', + cancelText: '取消', + success: (res) => { + if (res.confirm) { + uni.navigateTo({ url: '/pages/mine/coins' }) + } + } + }) + return + } + + coins -= 1 + uni.setStorageSync('userCoins', coins) + + if (userInfoStr) { + try { + const userInfo = JSON.parse(userInfoStr) + await api.userApi.updateCoins(userInfo.userId, coins) + } catch (e) { + console.error('更新金币失败:', e) + } + } } this.loading = true diff --git a/xuan-deduct-uniapp/src/utils/coinUtils.js b/xuan-deduct-uniapp/src/utils/coinUtils.js index afebc3f..426ec9b 100644 --- a/xuan-deduct-uniapp/src/utils/coinUtils.js +++ b/xuan-deduct-uniapp/src/utils/coinUtils.js @@ -1,9 +1,9 @@ -// utils/coinUtils.js +import api from '@/utils/api.js' const checkCoinsAndConsume = () => { const vipLevel = uni.getStorageSync('vipLevel') || 0 if (vipLevel > 0) { - return { canUse: true, needCoins: true } + return { canUse: true, needCoins: false } } let coins = uni.getStorageSync('userCoins') @@ -18,17 +18,17 @@ const checkCoinsAndConsume = () => { cancelText: '取消', success: (res) => { if (res.confirm) { - uni.navigateTo({ url: '/pages/mine/coins' }) - } + uni.navigateTo({ url: '/pages/mine/coins' }) } - }) + } + }) return { canUse: false, needCoins: true } } return { canUse: true, needCoins: false } } -const consumeCoin = () => { +const consumeCoin = async () => { const vipLevel = uni.getStorageSync('vipLevel') || 0 if (vipLevel > 0) { return @@ -51,3 +51,8 @@ const consumeCoin = () => { console.error('更新金币失败:', e) } } + +export default { + checkCoinsAndConsume, + consumeCoin +}