Forráskód Böngészése

签到获取积分

YH_0525 1 hónapja
szülő
commit
322ce9a71c

+ 69 - 9
LiangZhiYUMao/pages/matchmaker-workbench/earn-points.vue

@@ -25,8 +25,8 @@
             <view class="rule-desc">{{ getDesc(rule.ruleType) }}</view>
           </view>
           <view class="rule-points">+{{ rule.pointValue }}</view>
-          <view class="rule-action" @click="handleAction(rule)">
-            {{ getActionText(rule.ruleType) }}
+          <view class="rule-action" :class="{ disabled: rule.ruleType === 1 && isSignedToday }" @click="handleAction(rule)">
+            {{ rule.ruleType === 1 && isSignedToday ? '已签到' : getActionText(rule.ruleType) }}
           </view>
         </view>
       </view>
@@ -55,27 +55,67 @@ export default {
     return {
       balance: 0,
       rules: [],
-      makerId: null
+      makerId: null,
+      isSignedToday: false  // 今日是否已签到
     }
   },
   onLoad() {
     this.initData()
   },
+  onShow() {
+    // 每次显示页面时刷新数据,确保数据同步
+    if (this.makerId) {
+      this.loadBalance()
+      this.checkSignInStatus()
+    }
+  },
   methods: {
     async initData() {
       const userInfo = uni.getStorageSync('userInfo')
       if (userInfo && userInfo.matchmakerId) {
         this.makerId = userInfo.matchmakerId
       } else if (userInfo && userInfo.userId) {
-        this.makerId = userInfo.userId
+        // 如果没有matchmakerId,通过API获取
+        try {
+          const res = await api.matchmaker.getByUserId(userInfo.userId)
+          let matchmaker = res
+          if (res && res.data) {
+            matchmaker = res.data
+          }
+          if (matchmaker && (matchmaker.matchmakerId || matchmaker.matchmaker_id)) {
+            this.makerId = matchmaker.matchmakerId || matchmaker.matchmaker_id
+            // 保存到userInfo中
+            userInfo.matchmakerId = this.makerId
+            uni.setStorageSync('userInfo', userInfo)
+          }
+        } catch (e) {
+          console.error('获取红娘信息失败:', e)
+        }
       }
       
       await Promise.all([
         this.loadBalance(),
-        this.loadRules()
+        this.loadRules(),
+        this.checkSignInStatus()
       ])
     },
     
+    // 检查今日签到状态
+    async checkSignInStatus() {
+      if (!this.makerId) return
+      try {
+        const res = await api.matchmaker.checkinStatus(this.makerId)
+        // 解析返回数据
+        let data = res
+        if (res && res.data !== undefined) {
+          data = res.data
+        }
+        this.isSignedToday = data === true || data?.isCheckedIn === true || data?.checked === true
+      } catch (e) {
+        console.error('检查签到状态失败:', e)
+      }
+    },
+    
     async loadBalance() {
       if (!this.makerId) return
       try {
@@ -134,7 +174,11 @@ export default {
     
     async handleAction(rule) {
       if (rule.ruleType === 1) {
-        // 签到
+        // 签到 - 先检查是否已签到
+        if (this.isSignedToday) {
+          uni.showToast({ title: '今日已签到', icon: 'none' })
+          return
+        }
         await this.doSignIn(rule)
       } else if (rule.ruleType === 2) {
         // 上传线索
@@ -161,14 +205,25 @@ export default {
       }
       
       try {
-        const res = await api.pointsMall.addPoints(this.makerId, rule.ruleType, '每日签到')
+        // 使用红娘签到接口
+        const res = await api.matchmaker.doCheckin(this.makerId)
+        
+        // 签到成功后更新状态
+        this.isSignedToday = true
+        
+        // 刷新积分余额
+        await this.loadBalance()
+        
         uni.showToast({
-          title: `签到成功,+${res.addedPoints}积分`,
+          title: `签到成功,+${rule.pointValue}积分`,
           icon: 'success'
         })
-        this.balance = res.newBalance
       } catch (e) {
         console.error('签到失败:', e)
+        // 如果是已签到的错误,更新状态
+        if (e.message && e.message.includes('已签到')) {
+          this.isSignedToday = true
+        }
         uni.showToast({
           title: e.message || '签到失败',
           icon: 'none'
@@ -295,6 +350,11 @@ export default {
       color: #FFFFFF;
       font-size: 24rpx;
       border-radius: 30rpx;
+      
+      &.disabled {
+        background: #CCCCCC;
+        color: #FFFFFF;
+      }
     }
   }
 }

+ 8 - 1
LiangZhiYUMao/pages/matchmaker-workbench/index.vue

@@ -190,13 +190,20 @@ export default {
 					console.log('解析后红娘信息:', matchmaker)
 					
 					if (matchmaker && (matchmaker.matchmakerId || matchmaker.matchmaker_id)) {
+						// 获取红娘ID
+						const matchmakerId = matchmaker.matchmakerId || matchmaker.matchmaker_id
+						
 						this.matchmakerInfo = {
 							realName: matchmaker.realName || matchmaker.real_name || userInfo.nickname,
 							avatarUrl: matchmaker.avatarUrl || matchmaker.avatar_url || userInfo.avatarUrl,
 							successCouples: matchmaker.successCouples || matchmaker.success_couples || 0,
 							points: matchmaker.points || 0
 						}
-						console.log('设置红娘信息:', this.matchmakerInfo)
+						
+						// 将matchmakerId保存到userInfo中,供其他页面使用
+						userInfo.matchmakerId = matchmakerId
+						uni.setStorageSync('userInfo', userInfo)
+						console.log('设置红娘信息:', this.matchmakerInfo, '红娘ID:', matchmakerId)
 					} else {
 						console.log('未找到红娘信息,使用默认值')
 					}

+ 23 - 1
LiangZhiYUMao/pages/matchmaker-workbench/points-detail.vue

@@ -70,13 +70,35 @@ export default {
   onLoad() {
     this.initData()
   },
+  onShow() {
+    // 每次显示页面时刷新积分数据,确保数据同步
+    if (this.makerId) {
+      this.pageNum = 1
+      this.loadRecords()
+    }
+  },
   methods: {
     async initData() {
       const userInfo = uni.getStorageSync('userInfo')
       if (userInfo && userInfo.matchmakerId) {
         this.makerId = userInfo.matchmakerId
       } else if (userInfo && userInfo.userId) {
-        this.makerId = userInfo.userId
+        // 如果没有matchmakerId,通过API获取
+        try {
+          const res = await api.matchmaker.getByUserId(userInfo.userId)
+          let matchmaker = res
+          if (res && res.data) {
+            matchmaker = res.data
+          }
+          if (matchmaker && (matchmaker.matchmakerId || matchmaker.matchmaker_id)) {
+            this.makerId = matchmaker.matchmakerId || matchmaker.matchmaker_id
+            // 保存到userInfo中
+            userInfo.matchmakerId = this.makerId
+            uni.setStorageSync('userInfo', userInfo)
+          }
+        } catch (e) {
+          console.error('获取红娘信息失败:', e)
+        }
       }
       
       await this.loadRecords()

+ 16 - 1
LiangZhiYUMao/pages/matchmaker-workbench/points-mall.vue

@@ -122,7 +122,22 @@ export default {
       if (userInfo && userInfo.matchmakerId) {
         this.makerId = userInfo.matchmakerId
       } else if (userInfo && userInfo.userId) {
-        this.makerId = userInfo.userId
+        // 如果没有matchmakerId,通过API获取
+        try {
+          const res = await api.matchmaker.getByUserId(userInfo.userId)
+          let matchmaker = res
+          if (res && res.data) {
+            matchmaker = res.data
+          }
+          if (matchmaker && (matchmaker.matchmakerId || matchmaker.matchmaker_id)) {
+            this.makerId = matchmaker.matchmakerId || matchmaker.matchmaker_id
+            // 保存到userInfo中
+            userInfo.matchmakerId = this.makerId
+            uni.setStorageSync('userInfo', userInfo)
+          }
+        } catch (e) {
+          console.error('获取红娘信息失败:', e)
+        }
       }
       
       await Promise.all([

+ 16 - 1
LiangZhiYUMao/pages/matchmaker-workbench/product-detail.vue

@@ -92,7 +92,22 @@ export default {
       if (userInfo && userInfo.matchmakerId) {
         this.makerId = userInfo.matchmakerId
       } else if (userInfo && userInfo.userId) {
-        this.makerId = userInfo.userId
+        // 如果没有matchmakerId,通过API获取
+        try {
+          const res = await api.matchmaker.getByUserId(userInfo.userId)
+          let matchmaker = res
+          if (res && res.data) {
+            matchmaker = res.data
+          }
+          if (matchmaker && (matchmaker.matchmakerId || matchmaker.matchmaker_id)) {
+            this.makerId = matchmaker.matchmakerId || matchmaker.matchmaker_id
+            // 保存到userInfo中
+            userInfo.matchmakerId = this.makerId
+            uni.setStorageSync('userInfo', userInfo)
+          }
+        } catch (e) {
+          console.error('获取红娘信息失败:', e)
+        }
       }
       
       await Promise.all([

+ 112 - 26
LiangZhiYUMao/pages/matchmaker-workbench/sign-in.vue

@@ -90,14 +90,17 @@
 </template>
 
 <script>
+import api from '@/utils/api.js'
+
 export default {
 	data() {
 		return {
-			currentYear: 2025,
-			currentMonth: 11,
+			currentYear: new Date().getFullYear(),
+			currentMonth: new Date().getMonth() + 1,
 			totalSignDays: 0,
 			availablePoints: 0,
 			consecutiveDays: 0,
+			makerId: null,
 			isSigned: false,
 			calendarDays: [],
 			signedDates: [] // 已签到的日期
@@ -111,22 +114,80 @@ export default {
 		}
 	},
 	onLoad() {
-		this.loadSignInData()
-		this.generateCalendar()
+		this.initData()
+	},
+	onShow() {
+		// 每次显示页面时刷新数据
+		if (this.makerId) {
+			this.loadSignInData()
+		}
 	},
 	methods: {
 		goBack() {
 			uni.navigateBack()
 		},
+		async initData() {
+			// 获取红娘ID
+			const userInfo = uni.getStorageSync('userInfo')
+			if (userInfo && userInfo.matchmakerId) {
+				this.makerId = userInfo.matchmakerId
+			} else if (userInfo && userInfo.userId) {
+				// 如果没有matchmakerId,通过API获取
+				try {
+					const res = await api.matchmaker.getByUserId(userInfo.userId)
+					let matchmaker = res
+					if (res && res.data) {
+						matchmaker = res.data
+					}
+					if (matchmaker && (matchmaker.matchmakerId || matchmaker.matchmaker_id)) {
+						this.makerId = matchmaker.matchmakerId || matchmaker.matchmaker_id
+						userInfo.matchmakerId = this.makerId
+						uni.setStorageSync('userInfo', userInfo)
+					}
+				} catch (e) {
+					console.error('获取红娘信息失败:', e)
+				}
+			}
+			
+			await this.loadSignInData()
+			this.generateCalendar()
+		},
 		async loadSignInData() {
-			// 模拟加载签到数据
-			this.totalSignDays = 0
-			this.availablePoints = 0
-			this.consecutiveDays = 0
-			this.isSigned = false
+			if (!this.makerId) return
 			
-			// 模拟已签到日期
-			this.signedDates = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 30]
+			try {
+				// 获取签到统计数据
+				const statsRes = await api.matchmaker.checkinStats(this.makerId)
+				let stats = statsRes
+				if (statsRes && statsRes.data) {
+					stats = statsRes.data
+				}
+				
+				this.totalSignDays = stats.totalDays || 0
+				this.consecutiveDays = stats.continuousDays || 0
+				
+				// 获取积分余额
+				const balanceRes = await api.pointsMall.getBalance(this.makerId)
+				this.availablePoints = balanceRes.balance || 0
+				
+				// 检查今日签到状态
+				const statusRes = await api.matchmaker.checkinStatus(this.makerId)
+				let statusData = statusRes
+				if (statusRes && statusRes.data !== undefined) {
+					statusData = statusRes.data
+				}
+				this.isSigned = statusData === true || statusData?.isCheckedIn === true || statusData?.checked === true
+				
+				// 如果今日已签到,添加到已签到日期
+				if (this.isSigned) {
+					const today = new Date().getDate()
+					if (!this.signedDates.includes(today)) {
+						this.signedDates.push(today)
+					}
+				}
+			} catch (e) {
+				console.error('加载签到数据失败:', e)
+			}
 		},
 		generateCalendar() {
 			const year = this.currentYear
@@ -177,7 +238,7 @@ export default {
 			
 			this.calendarDays = days
 		},
-		handleSignIn() {
+		async handleSignIn() {
 			if (this.isSigned) {
 				uni.showToast({
 					title: '今日已签到',
@@ -186,21 +247,46 @@ export default {
 				return
 			}
 			
-			// 执行签到
-			this.isSigned = true
-			this.totalSignDays++
-			this.availablePoints += 10
-			this.consecutiveDays++
-			
-			// 更新今天的签到状态
-			const today = new Date().getDate()
-			this.signedDates.push(today)
-			this.generateCalendar()
+			if (!this.makerId) {
+				uni.showToast({ title: '请先登录', icon: 'none' })
+				return
+			}
 			
-			uni.showToast({
-				title: '签到成功 +10积分',
-				icon: 'success'
-			})
+			try {
+				// 调用后端签到接口
+				await api.matchmaker.doCheckin(this.makerId)
+				
+				// 签到成功后更新状态
+				this.isSigned = true
+				this.totalSignDays++
+				this.consecutiveDays++
+				
+				// 更新今天的签到状态
+				const today = new Date().getDate()
+				if (!this.signedDates.includes(today)) {
+					this.signedDates.push(today)
+				}
+				this.generateCalendar()
+				
+				// 刷新积分余额
+				const balanceRes = await api.pointsMall.getBalance(this.makerId)
+				this.availablePoints = balanceRes.balance || 0
+				
+				uni.showToast({
+					title: '签到成功 +5积分',
+					icon: 'success'
+				})
+			} catch (e) {
+				console.error('签到失败:', e)
+				// 如果是已签到的错误,更新状态
+				if (e.message && e.message.includes('已签到')) {
+					this.isSigned = true
+				}
+				uni.showToast({
+					title: e.message || '签到失败',
+					icon: 'none'
+				})
+			}
 		}
 	}
 }

+ 55 - 28
service/homePage/src/main/java/com/zhentao/service/impl/MatchmakerCheckinServiceImpl.java

@@ -1,7 +1,6 @@
 package com.zhentao.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.zhentao.entity.Matchmaker;
 import com.zhentao.entity.MatchmakerCheckin;
 import com.zhentao.mapper.MatchmakerCheckinMapper;
 import com.zhentao.service.MatchmakerCheckinService;
@@ -94,52 +93,80 @@ public class MatchmakerCheckinServiceImpl extends ServiceImpl<MatchmakerCheckinM
     }
 
     @Override
-    public boolean isCheckedIn(Long userId) {
-        // 根据 userId 查询 matchmaker 信息
-        MatchmakerVO matchmaker = matchmakerService.getMatchmakerByUserId(userId);
-        if (matchmaker == null) {
-            return false;
+    public boolean isCheckedIn(Long idParam) {
+        // idParam 可能是 userId 或 matchmakerId,需要兼容处理
+        LocalDate today = LocalDate.now();
+        
+        // 先尝试直接用 idParam 作为 matchmakerId 查询
+        MatchmakerCheckin checkin = matchmakerCheckinMapper.selectByMakerIdAndDate(idParam, today);
+        if (checkin != null) {
+            return true;
         }
-        Integer matchmakerId = matchmaker.getMatchmakerId();
         
-        LocalDate today = LocalDate.now();
-        MatchmakerCheckin checkin = matchmakerCheckinMapper.selectByMakerIdAndDate(matchmakerId.longValue(), today);
-        return checkin != null;
+        // 如果没找到,尝试把 idParam 当作 userId 来查询 matchmaker
+        MatchmakerVO matchmaker = matchmakerService.getMatchmakerByUserId(idParam);
+        if (matchmaker != null && matchmaker.getMatchmakerId() != null) {
+            Long matchmakerId = matchmaker.getMatchmakerId().longValue();
+            checkin = matchmakerCheckinMapper.selectByMakerIdAndDate(matchmakerId, today);
+            return checkin != null;
+        }
+        
+        return false;
     }
 
     @Override
-    public Integer getTotalDays(Long userId) {
-        // 根据 userId 查询 matchmaker 信息
-        MatchmakerVO matchmaker = matchmakerService.getMatchmakerByUserId(userId);
-        if (matchmaker == null) {
-            return 0;
+    public Integer getTotalDays(Long idParam) {
+        // idParam 可能是 userId 或 matchmakerId,需要兼容处理
+        Long matchmakerId = idParam;
+        
+        // 先尝试直接用 idParam 作为 matchmakerId 查询
+        Integer totalDays = matchmakerCheckinMapper.selectTotalDaysByMakerId(idParam);
+        if (totalDays != null && totalDays > 0) {
+            return totalDays;
         }
-        Integer matchmakerId = matchmaker.getMatchmakerId();
         
-        Integer totalDays = matchmakerCheckinMapper.selectTotalDaysByMakerId(matchmakerId.longValue());
-        return totalDays != null ? totalDays : 0;
+        // 如果没找到,尝试把 idParam 当作 userId 来查询 matchmaker
+        MatchmakerVO matchmaker = matchmakerService.getMatchmakerByUserId(idParam);
+        if (matchmaker != null && matchmaker.getMatchmakerId() != null) {
+            matchmakerId = matchmaker.getMatchmakerId().longValue();
+            totalDays = matchmakerCheckinMapper.selectTotalDaysByMakerId(matchmakerId);
+            return totalDays != null ? totalDays : 0;
+        }
+        
+        return 0;
     }
 
     @Override
-    public Integer getContinuousDays(Long userId) {
-        // 根据 userId 查询 matchmaker 信息
-        MatchmakerVO matchmaker = matchmakerService.getMatchmakerByUserId(userId);
-        if (matchmaker == null) {
-            return 0;
-        }
-        Integer matchmakerId = matchmaker.getMatchmakerId();
+    public Integer getContinuousDays(Long idParam) {
+        // idParam 可能是 userId 或 matchmakerId,需要兼容处理
+        Long matchmakerId = idParam;
         
-        MatchmakerCheckin lastCheckin = matchmakerCheckinMapper.selectLastByMakerId(matchmakerId.longValue());
+        // 先尝试直接用 idParam 作为 matchmakerId 查询
+        MatchmakerCheckin lastCheckin = matchmakerCheckinMapper.selectLastByMakerId(idParam);
         if (lastCheckin != null) {
-            // 检查是否是连续签到(今天或昨天)
             LocalDate today = LocalDate.now();
             LocalDate lastDate = lastCheckin.getCheckinDate();
             long daysBetween = ChronoUnit.DAYS.between(lastDate, today);
-            
             if (daysBetween <= 1) {
                 return lastCheckin.getContinuousDays();
             }
         }
+        
+        // 如果没找到,尝试把 idParam 当作 userId 来查询 matchmaker
+        MatchmakerVO matchmaker = matchmakerService.getMatchmakerByUserId(idParam);
+        if (matchmaker != null && matchmaker.getMatchmakerId() != null) {
+            matchmakerId = matchmaker.getMatchmakerId().longValue();
+            lastCheckin = matchmakerCheckinMapper.selectLastByMakerId(matchmakerId);
+            if (lastCheckin != null) {
+                LocalDate today = LocalDate.now();
+                LocalDate lastDate = lastCheckin.getCheckinDate();
+                long daysBetween = ChronoUnit.DAYS.between(lastDate, today);
+                if (daysBetween <= 1) {
+                    return lastCheckin.getContinuousDays();
+                }
+            }
+        }
+        
         return 0;
     }
 }