Parcourir la source

签到获取积分

YH_0525 il y a 1 mois
Parent
commit
2571530511

+ 37 - 17
LiangZhiYUMao/pages/matchmaker-workbench/earn-points.vue

@@ -56,6 +56,7 @@ export default {
       balance: 0,
       rules: [],
       makerId: null,
+      userId: null,  // 用户ID,用于签到
       isSignedToday: false  // 今日是否已签到
     }
   },
@@ -72,6 +73,11 @@ export default {
   methods: {
     async initData() {
       const userInfo = uni.getStorageSync('userInfo')
+      // 保存userId用于签到
+      if (userInfo && userInfo.userId) {
+        this.userId = userInfo.userId
+      }
+      
       if (userInfo && userInfo.matchmakerId) {
         this.makerId = userInfo.matchmakerId
       } else if (userInfo && userInfo.userId) {
@@ -199,35 +205,49 @@ export default {
     },
     
     async doSignIn(rule) {
-      if (!this.makerId) {
+      if (!this.userId) {
         uni.showToast({ title: '请先登录', icon: 'none' })
         return
       }
       
       try {
-        // 使用红娘签到接口
-        const res = await api.matchmaker.doCheckin(this.makerId)
+        // 使用userId进行签到(后端会根据userId查询matchmaker并添加积分)
+        const res = await api.matchmaker.doCheckin(this.userId)
         
-        // 签到成功后更新状态
-        this.isSignedToday = true
-        
-        // 刷新积分余额
-        await this.loadBalance()
+        // 检查签到结果
+        let success = false
+        if (res === true || res?.data === true) {
+          success = true
+        } else if (res?.msg === '今日已签到') {
+          this.isSignedToday = true
+          uni.showToast({ title: '今日已签到', icon: 'none' })
+          return
+        }
         
-        uni.showToast({
-          title: `签到成功,+${rule.pointValue}积分`,
-          icon: 'success'
-        })
+        if (success) {
+          // 签到成功后更新状态
+          this.isSignedToday = true
+          
+          // 刷新积分余额
+          await this.loadBalance()
+          
+          uni.showToast({
+            title: `签到成功,+${rule.pointValue}积分`,
+            icon: 'success'
+          })
+        }
       } catch (e) {
         console.error('签到失败:', e)
         // 如果是已签到的错误,更新状态
-        if (e.message && e.message.includes('已签到')) {
+        if (e.message && e.message.includes('已签到') || e.msg && e.msg.includes('已签到')) {
           this.isSignedToday = true
+          uni.showToast({ title: '今日已签到', icon: 'none' })
+        } else {
+          uni.showToast({
+            title: e.message || e.msg || '签到失败',
+            icon: 'none'
+          })
         }
-        uni.showToast({
-          title: e.message || '签到失败',
-          icon: 'none'
-        })
       }
     }
   }

+ 31 - 33
LiangZhiYUMao/pages/matchmaker-workbench/mine.vue

@@ -502,43 +502,30 @@ export default {
           return
         }
         
-        // 首先获取红娘信息,以获取makerId
-        const matchmakerInfo = await api.matchmaker.getByUserId(userInfo.userId)
-        if (!matchmakerInfo || !matchmakerInfo.matchmakerId && !matchmakerInfo.matchmaker_id) {
-          uni.showToast({
-            title: '没有有效的makerId,无法签到',
-            icon: 'none'
-          })
-          return
-        }
-        
-        const makerId = matchmakerInfo.matchmakerId || matchmakerInfo.matchmaker_id
-        
-        // 执行签到
-        const res = await api.matchmaker.doCheckin(makerId)
+        // 使用userId进行签到(后端会根据userId查询matchmaker并添加积分)
+        const res = await api.matchmaker.doCheckin(userInfo.userId)
         console.log('签到API返回结果:', res)
+        
+        // 判断签到结果
         let success = false
         let alreadySigned = false
-        if (typeof res === 'boolean') {
-          success = res
-        } else if (typeof res === 'string') {
-          success = res === 'true' || res === 'ok' || res === 'success'
+        
+        // 后端返回格式: { code: 200, msg: "签到成功", data: true/false }
+        if (res === true) {
+          success = true
+        } else if (res === false) {
+          alreadySigned = true
         } else if (res && typeof res === 'object') {
-          if (typeof res.success === 'boolean') success = res.success
-          if (typeof res.todaySigned === 'boolean') alreadySigned = res.todaySigned
-          else if (typeof res.signed === 'boolean') alreadySigned = res.signed
-          else if (typeof res.isSignedToday === 'boolean') alreadySigned = res.isSignedToday
-          if (res.data && typeof res.data === 'object') {
-            if (typeof res.data.success === 'boolean') success = res.data.success
-            if (typeof res.data.todaySigned === 'boolean') alreadySigned = res.data.todaySigned
-            else if (typeof res.data.signed === 'boolean') alreadySigned = res.data.signed
-            else if (typeof res.data.isSignedToday === 'boolean') alreadySigned = res.data.isSignedToday
+          if (res.data === true) {
+            success = true
+          } else if (res.data === false || res.msg === '今日已签到') {
+            alreadySigned = true
           }
         }
         
         if (success) {
           uni.showToast({
-            title: '签到成功',
+            title: '签到成功,+5积分',
             icon: 'success'
           })
           this.isSignedToday = true
@@ -550,9 +537,11 @@ export default {
             this.signedDays.sort((a, b) => a - b)
           }
           this.generateCalendar()
-          this.loadProfileData()
+          // 刷新个人资料(包含积分)
+          await this.loadProfileData()
           this.closeSignInPopup()
         } else if (alreadySigned) {
+          this.isSignedToday = true
           uni.showToast({
             title: '今日已签到',
             icon: 'none'
@@ -565,10 +554,19 @@ export default {
         }
       } catch (error) {
         console.error('签到失败:', error)
-        uni.showToast({
-          title: error.msg || '签到失败,请稍后重试',
-          icon: 'none'
-        })
+        // 检查是否是已签到的错误
+        if (error.msg && error.msg.includes('已签到')) {
+          this.isSignedToday = true
+          uni.showToast({
+            title: '今日已签到',
+            icon: 'none'
+          })
+        } else {
+          uni.showToast({
+            title: error.msg || '签到失败,请稍后重试',
+            icon: 'none'
+          })
+        }
       }
     },
     // 签到(旧方法,保持兼容)