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 +}