fix: 修复测算页面金币检查逻辑
- 恢复api.js文件并添加userApi - 修复coinUtils.js导入api模块 - 更新所有测算页面添加金币检查逻辑: - 八字测算 - 紫微斗数 - 六爻占卜 - 奇门遁甲 - 大六壬 - 梅花易数 - 占星术
This commit is contained in:
1 parent
624afe92e0
commit
e56af6feb5
7 files changed
+225
-10
No files matched your search
@@ -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({
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user