Explorar o código

feat(user): 添加红娘状态查询功能

- 新增查询用户是否为红娘的API接口
- 在首页根据数据库查询结果动态显示红娘工作台按钮
- 实现从数据库获取并更新用户红娘状态的逻辑
- 优化用户信息存储,同步红娘状态到本地缓存
- 修复日历组件渲染问题,改进样式布局
- 增加红娘申请状态查询接口及前端状态管理
- 完善红娘申请页面按钮状态控制逻辑
- 更新用户实体类和VO类,支持红娘标识字段
- 实现后端红娘申请状态查询服务和控制器逻辑
李思佳 hai 4 semanas
pai
achega
638b3cf92f

+ 48 - 14
LiangZhiYUMao/pages/index/index.vue

@@ -4,12 +4,12 @@
 		<view class="top-bar">
 		<view class="top-bar">
 			<view class="logo">婚恋</view>
 			<view class="logo">婚恋</view>
 			<view class="top-right-icons">
 			<view class="top-right-icons">
-				<!-- 红娘工作台切换按钮 - 仅登录用户显示 -->
-			<view v-if="userInfo && userInfo.userId && userInfo.isMatchmaker && parseInt(userInfo.isMatchmaker) === 1" 
-				class="matchmaker-btn" @click="openMatchmakerPopup">
-				<text class="switch-icon">🔄</text>
-				<text class="switch-text">切换工作台</text>
-			</view>
+				<!-- 红娘工作台切换按钮 - 根据数据库查询结果动态显示 -->
+				<view v-if="showMatchmakerButton"
+					class="matchmaker-btn" @click="openMatchmakerPopup">
+					<text class="switch-icon">🔄</text>
+					<text class="switch-text">切换工作台</text>
+				</view>
 				<!-- 消息通知图标 -->
 				<!-- 消息通知图标 -->
 				<view class="msg-icon" @click="goToMessages">
 				<view class="msg-icon" @click="goToMessages">
 					<text class="icon">🔔</text>
 					<text class="icon">🔔</text>
@@ -251,6 +251,9 @@
 				// 用户信息
 				// 用户信息
 				userInfo: {},
 				userInfo: {},
 				matchCount: 3,
 				matchCount: 3,
+				
+				// 是否显示红娘工作台按钮(根据数据库查询结果)
+				showMatchmakerButton: false,
 
 
 				// 轮播图数据
 				// 轮播图数据
 				bannerList: [],
 				bannerList: [],
@@ -338,16 +341,47 @@
 			console.log('📱 页面onShow触发')
 			console.log('📱 页面onShow触发')
 			// 页面显示时重新加载用户信息(确保登录后能更新)
 			// 页面显示时重新加载用户信息(确保登录后能更新)
 			this.loadUserInfo()
 			this.loadUserInfo()
-			// 页面显示时检查是否为红娘
-			this.checkMatchmakerStatus()
+			// 页面显示时查询数据库检查是否为红娘
+			this.checkMatchmakerStatusFromDB()
 		},
 		},
 		methods: {
 		methods: {
-			// 删除自动弹出功能,只保留手动点击切换
-			checkMatchmakerStatus() {
-				// 从本地存储获取用户信息
-				const userInfo = uni.getStorageSync('userInfo')
-				console.log('🔍 检查红娘状态,用户信息:', userInfo)
-				// 此处不再自动弹出弹框,只在用户点击切换按钮时显示
+			// 从数据库查询用户是否为红娘
+			async checkMatchmakerStatusFromDB() {
+				try {
+					const userId = uni.getStorageSync('userId')
+					if (!userId) {
+						console.log('⚠️ 用户未登录,不显示红娘按钮')
+						this.showMatchmakerButton = false
+						return
+					}
+					
+					console.log('🔍 查询用户红娘状态,userId:', userId)
+					
+					// 调用API查询用户的is_matchmaker字段
+					const result = await api.user.getMatchmakerStatus(userId)
+					
+					if (result && result.isMatchmaker !== undefined) {
+						const isMatchmaker = parseInt(result.isMatchmaker)
+						console.log('✅ 查询成功,isMatchmaker:', isMatchmaker)
+						
+						// 根据查询结果设置按钮显示状态
+						this.showMatchmakerButton = (isMatchmaker === 1)
+						
+						// 同时更新本地存储的用户信息
+						const userInfo = uni.getStorageSync('userInfo') || {}
+						userInfo.isMatchmaker = isMatchmaker
+						uni.setStorageSync('userInfo', userInfo)
+						this.userInfo.isMatchmaker = isMatchmaker
+						
+						console.log('🎯 红娘按钮显示状态:', this.showMatchmakerButton ? '显示' : '隐藏')
+					} else {
+						console.log('⚠️ 查询结果异常,不显示红娘按钮')
+						this.showMatchmakerButton = false
+					}
+				} catch (error) {
+					console.error('❌ 查询红娘状态失败:', error)
+					this.showMatchmakerButton = false
+				}
 			},
 			},
 			
 			
 			// 前往红娘工作台
 			// 前往红娘工作台

+ 32 - 13
LiangZhiYUMao/pages/mine/index.vue

@@ -703,28 +703,38 @@ export default {
       })
       })
     },
     },
 
 
-    // 根据后端数据生成日历
+    // 根据后端数据生成日历(修复版本)
     generateCalendarFromBackend(checkedDates) {
     generateCalendarFromBackend(checkedDates) {
       const today = new Date()
       const today = new Date()
       const year = today.getFullYear()
       const year = today.getFullYear()
-      const month = today.getMonth()
-      const todayStr = this.formatDate(today) // 今天的日期字符串
-
+      const month = today.getMonth() // 0-11
+      
+      // 格式化当前月份显示
       this.currentMonth = `${year}年${month + 1}月`
       this.currentMonth = `${year}年${month + 1}月`
+      
+      // 获取本月第一天是星期几(0=周日, 1=周一, ..., 6=周六)
       const firstDay = new Date(year, month, 1).getDay()
       const firstDay = new Date(year, month, 1).getDay()
+      
+      // 获取本月总天数
       const daysInMonth = new Date(year, month + 1, 0).getDate()
       const daysInMonth = new Date(year, month + 1, 0).getDate()
+      
+      // 今天的日期字符串(用于比较)
+      const todayStr = this.formatDate(today)
+      
       const days = []
       const days = []
-
+      
+      // 添加空白占位(月初前的空白)
       for (let i = 0; i < firstDay; i++) {
       for (let i = 0; i < firstDay; i++) {
-        days.push({date: null, checked: false, isToday: false})
+        days.push({ date: null, checked: false, isToday: false })
       }
       }
-
+      
+      // 添加本月的每一天
       for (let i = 1; i <= daysInMonth; i++) {
       for (let i = 1; i <= daysInMonth; i++) {
         const date = new Date(year, month, i)
         const date = new Date(year, month, i)
         const dateStr = this.formatDate(date)
         const dateStr = this.formatDate(date)
-        const isToday = dateStr === todayStr // 通过日期字符串比较,更准确
+        const isToday = dateStr === todayStr
         const checked = checkedDates.includes(dateStr)
         const checked = checkedDates.includes(dateStr)
-
+        
         days.push({
         days.push({
           date: i,
           date: i,
           checked: checked,
           checked: checked,
@@ -732,8 +742,16 @@ export default {
           dateStr: dateStr
           dateStr: dateStr
         })
         })
       }
       }
-
+      
       this.calendarDays = days
       this.calendarDays = days
+      
+      console.log('日历生成完成:', {
+        month: this.currentMonth,
+        firstDay: firstDay,
+        daysInMonth: daysInMonth,
+        totalDays: days.length,
+        todayStr: todayStr
+      })
     },
     },
     // 格式化日期
     // 格式化日期
     formatDate(date) {
     formatDate(date) {
@@ -1689,17 +1707,18 @@ export default {
     }
     }
 
 
     .calendar-body {
     .calendar-body {
-      display: flex;
-      flex-wrap: wrap;
+      display: grid;
+      grid-template-columns: repeat(7, 1fr);
+      gap: 0;
 
 
       .calendar-day {
       .calendar-day {
-        width: calc(100% / 7);
         height: 70rpx;
         height: 70rpx;
         display: flex;
         display: flex;
         align-items: center;
         align-items: center;
         justify-content: center;
         justify-content: center;
         position: relative;
         position: relative;
         margin-bottom: 8rpx;
         margin-bottom: 8rpx;
+        box-sizing: border-box;
 
 
         .day-num {
         .day-num {
           font-size: 24rpx;
           font-size: 24rpx;

+ 88 - 2
LiangZhiYUMao/pages/part-time-matchmaker/index.vue

@@ -122,7 +122,14 @@
 					></textarea>
 					></textarea>
 				</view>
 				</view>
 
 
-				<button class="submit-btn" @click="handleSubmit">提交申请</button>
+				<button
+					class="submit-btn"
+					:class="{ 'btn-disabled': buttonDisabled }"
+					:disabled="buttonDisabled"
+					@click="handleSubmit"
+				>
+					{{ buttonText }}
+				</button>
 			</view>
 			</view>
 
 
 			<!-- 更多特点 -->
 			<!-- 更多特点 -->
@@ -183,7 +190,11 @@
 				}),
 				}),
 				timeSlotData: [[], []], // [开始时间, 结束时间]
 				timeSlotData: [[], []], // [开始时间, 结束时间]
 				timeSlotIndex: [0, 0],
 				timeSlotIndex: [0, 0],
-				timeSlotDisplayText: ''
+				timeSlotDisplayText: '',
+				// 按钮状态
+				buttonText: '提交申请',
+				buttonDisabled: false,
+				applyStatus: null // null-未申请, 0-已通过, 1-已拒绝, 2-审核中
 			}
 			}
 		},
 		},
 		onLoad() {
 		onLoad() {
@@ -191,6 +202,8 @@
 			this.timeSlotData = [this.hourOptions, this.hourOptions]
 			this.timeSlotData = [this.hourOptions, this.hourOptions]
 			// 加载省市区数据
 			// 加载省市区数据
 			this.loadAreaData()
 			this.loadAreaData()
+			// 检查申请状态
+			this.checkApplyStatus()
 		},
 		},
 		methods: {
 		methods: {
 			// 返回上一页
 			// 返回上一页
@@ -206,6 +219,65 @@
 				})
 				})
 			},
 			},
 			
 			
+			// 检查申请状态
+			async checkApplyStatus() {
+				try {
+					console.log('=== 开始检查申请状态 ===')
+					
+					// 获取用户ID
+					const userId = await userAuth.checkLoginStatus({
+						requireLogin: false,
+						allowTestUser: false
+					})
+					
+					if (!userId) {
+						console.log('用户未登录,保持默认按钮状态')
+						return
+					}
+					
+					console.log('当前用户ID:', userId)
+					
+					// 查询申请状态
+					const result = await api.matchmaker.getApplyStatus(userId)
+					console.log('申请状态查询结果:', result)
+					
+					if (result && result.hasApplied) {
+						this.applyStatus = result.status
+						this.updateButtonState(result.status)
+					} else {
+						console.log('用户未申请过,保持默认状态')
+					}
+				} catch (error) {
+					console.error('查询申请状态失败:', error)
+					// 查询失败不影响页面显示,保持默认状态
+				}
+			},
+			
+			// 根据status更新按钮状态
+			updateButtonState(status) {
+				console.log('更新按钮状态,status:', status)
+				
+				if (status === 2) {
+					// 审核中
+					this.buttonText = '审核中'
+					this.buttonDisabled = true
+				} else if (status === 0) {
+					// 已成为红娘
+					this.buttonText = '已成为红娘'
+					this.buttonDisabled = true
+				} else if (status === 1) {
+					// 审核被拒绝,可以重新提交
+					this.buttonText = '重新提交'
+					this.buttonDisabled = false
+				} else {
+					// 其他状态,保持默认
+					this.buttonText = '提交申请'
+					this.buttonDisabled = false
+				}
+				
+				console.log('按钮文字:', this.buttonText, '是否禁用:', this.buttonDisabled)
+			},
+			
 			// 省市区相关方法
 			// 省市区相关方法
 			// 加载省市区数据
 			// 加载省市区数据
 			async loadAreaData() {
 			async loadAreaData() {
@@ -393,6 +465,11 @@
 			
 			
 			// 提交申请
 			// 提交申请
 			async handleSubmit() {
 			async handleSubmit() {
+				// 如果按钮被禁用,不执行提交
+				if (this.buttonDisabled) {
+					return
+				}
+				
 				// 表单验证
 				// 表单验证
 				if (!this.formData.name) {
 				if (!this.formData.name) {
 					uni.showToast({
 					uni.showToast({
@@ -558,6 +635,9 @@
 										this.areaDisplayText = ''
 										this.areaDisplayText = ''
 										this.timeSlotIndex = [0, 0]
 										this.timeSlotIndex = [0, 0]
 										this.timeSlotDisplayText = ''
 										this.timeSlotDisplayText = ''
+										
+										// 重新检查申请状态,更新按钮
+										this.checkApplyStatus()
 									}
 									}
 								})
 								})
 							} catch (error) {
 							} catch (error) {
@@ -848,6 +928,12 @@
 			border: none;
 			border: none;
 			border-radius: 40rpx;
 			border-radius: 40rpx;
 			margin-top: 30rpx;
 			margin-top: 30rpx;
+			
+			&.btn-disabled {
+				background: #CCCCCC;
+				color: #FFFFFF;
+				opacity: 0.6;
+			}
 		}
 		}
 	}
 	}
 </style>
 </style>

+ 13 - 2
LiangZhiYUMao/utils/api.js

@@ -87,8 +87,13 @@ export default {
     getInfo: () => request({ url: '/user/info' }),
     getInfo: () => request({ url: '/user/info' }),
     
     
     // 获取指定用户的详细信息(包含简介和照片)
     // 获取指定用户的详细信息(包含简介和照片)
-    getDetailInfo: (userId) => request({ 
-      url: `/user/info?userId=${userId}` 
+    getDetailInfo: (userId) => request({
+      url: `/user/info?userId=${userId}`
+    }),
+    
+    // 查询用户是否为红娘
+    getMatchmakerStatus: (userId) => request({
+      url: `/user/matchmaker-status?userId=${userId}`
     }),
     }),
     
     
     // 获取今日匹配数
     // 获取今日匹配数
@@ -319,6 +324,12 @@ export default {
             data
             data
         }),
         }),
         
         
+        // 查询红娘申请状态
+        getApplyStatus: (userId) => request({
+            url: `/matchmaker-apply/status?userId=${userId}`,
+            method: 'GET'
+        }),
+        
         // 工作台相关
         // 工作台相关
         getWorkbenchData: () => request({ url: '/matchmaker/workbench/data' }),
         getWorkbenchData: () => request({ url: '/matchmaker/workbench/data' }),
         
         

+ 7 - 0
common/src/main/java/com/zhentao/service/MatchmakerApplyService.java

@@ -14,4 +14,11 @@ public interface MatchmakerApplyService extends IService<MatchmakerApply> {
      * @return 是否成功
      * @return 是否成功
      */
      */
     boolean submitApply(MatchmakerApply matchmakerApply);
     boolean submitApply(MatchmakerApply matchmakerApply);
+    
+    /**
+     * 根据用户ID查询申请状态
+     * @param userId 用户ID
+     * @return 申请记录(如果存在)
+     */
+    MatchmakerApply getApplyByUserId(Long userId);
 }
 }

+ 20 - 6
common/src/main/java/com/zhentao/service/impl/MatchmakerApplyServiceImpl.java

@@ -1,5 +1,6 @@
 package com.zhentao.service.impl;
 package com.zhentao.service.impl;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.zhentao.mapper.MatchmakerApplyMapper;
 import com.zhentao.mapper.MatchmakerApplyMapper;
 import com.zhentao.pojo.MatchmakerApply;
 import com.zhentao.pojo.MatchmakerApply;
@@ -12,9 +13,9 @@ import java.time.LocalDateTime;
  * 红娘申请Service实现类
  * 红娘申请Service实现类
  */
  */
 @Service
 @Service
-public class MatchmakerApplyServiceImpl extends ServiceImpl<MatchmakerApplyMapper, MatchmakerApply> 
+public class MatchmakerApplyServiceImpl extends ServiceImpl<MatchmakerApplyMapper, MatchmakerApply>
         implements MatchmakerApplyService {
         implements MatchmakerApplyService {
-    
+
     @Override
     @Override
     public boolean submitApply(MatchmakerApply matchmakerApply) {
     public boolean submitApply(MatchmakerApply matchmakerApply) {
         // 设置创建时间
         // 设置创建时间
@@ -24,13 +25,26 @@ public class MatchmakerApplyServiceImpl extends ServiceImpl<MatchmakerApplyMappe
         // 更新人创建人
         // 更新人创建人
         matchmakerApply.setCreateMan("系统管理员");
         matchmakerApply.setCreateMan("系统管理员");
         matchmakerApply.setUpdateMan("系统管理员");
         matchmakerApply.setUpdateMan("系统管理员");
-        
-        // 设置默认状态为正常
+
         if (matchmakerApply.getStatus() == null) {
         if (matchmakerApply.getStatus() == null) {
-            matchmakerApply.setStatus(0);
+            matchmakerApply.setStatus(2);
         }
         }
-        
+
         // 保存申请信息
         // 保存申请信息
         return this.save(matchmakerApply);
         return this.save(matchmakerApply);
     }
     }
+
+    @Override
+    public MatchmakerApply getApplyByUserId(Long userId) {
+        if (userId == null) {
+            return null;
+        }
+
+        QueryWrapper<MatchmakerApply> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("user_id", userId);
+        queryWrapper.orderByDesc("create_time"); // 按创建时间倒序,获取最新的申请记录
+        queryWrapper.last("LIMIT 1"); // 只获取一条记录
+
+        return this.getOne(queryWrapper);
+    }
 }
 }

+ 46 - 0
service/Essential/src/main/java/com/zhentao/controller/UserController.java

@@ -55,6 +55,52 @@ public class UserController {
         }
         }
     }
     }
     
     
+    /**
+     * 查询用户是否为红娘
+     * @param userId 用户ID
+     * @return 红娘状态 {isMatchmaker: 0或1}
+     */
+    @GetMapping("/matchmaker-status")
+    public Result<java.util.Map<String, Object>> getMatchmakerStatus(@RequestParam Long userId) {
+        System.out.println("=== UserController.getMatchmakerStatus 接收请求 ===");
+        System.out.println("查询用户ID: " + userId);
+        
+        try {
+            if (userId == null || userId <= 0) {
+                System.out.println("❌ 用户ID无效: " + userId);
+                return Result.error("用户ID无效");
+            }
+            
+            // 查询用户信息
+            UserInfoVO userInfo = userService.getUserInfo(userId);
+            
+            if (userInfo == null) {
+                System.out.println("❌ 用户不存在: " + userId);
+                return Result.error("用户不存在");
+            }
+            
+            // 获取is_matchmaker字段值
+            Integer isMatchmaker = userInfo.getIsMatchmaker();
+            if (isMatchmaker == null) {
+                isMatchmaker = 0; // 默认值为0(不是红娘)
+            }
+            
+            System.out.println("✅ 查询成功,用户: " + userInfo.getNickname() + ", isMatchmaker: " + isMatchmaker);
+            
+            // 构造返回数据
+            java.util.Map<String, Object> result = new java.util.HashMap<>();
+            result.put("userId", userId);
+            result.put("isMatchmaker", isMatchmaker);
+            result.put("nickname", userInfo.getNickname());
+            
+            return Result.success(result);
+        } catch (Exception e) {
+            System.err.println("❌ 查询红娘状态失败: " + e.getMessage());
+            e.printStackTrace();
+            return Result.error("查询红娘状态失败: " + e.getMessage());
+        }
+    }
+    
     /**
     /**
      * 更新用户基本信息(包括出生日期等)
      * 更新用户基本信息(包括出生日期等)
      * @param user 用户基本信息对象
      * @param user 用户基本信息对象

+ 1 - 0
service/Essential/src/main/java/com/zhentao/entity/User.java

@@ -66,6 +66,7 @@ public class User implements Serializable {
      * 状态 (0-禁用 1-正常 2-注销)
      * 状态 (0-禁用 1-正常 2-注销)
      */
      */
     private Integer status;
     private Integer status;
+    private Integer isMatchmaker;
     
     
     /**
     /**
      * 注册来源
      * 注册来源

+ 1 - 0
service/Essential/src/main/java/com/zhentao/service/impl/UserServiceImpl.java

@@ -61,6 +61,7 @@ public class UserServiceImpl implements UserService {
         vo.setGenderText(getGenderText(user.getGender()));
         vo.setGenderText(getGenderText(user.getGender()));
         vo.setBirthDate(user.getBirthDate());
         vo.setBirthDate(user.getBirthDate());
         vo.setAge(calculateAge(user.getBirthDate()));
         vo.setAge(calculateAge(user.getBirthDate()));
+        vo.setIsMatchmaker(user.getIsMatchmaker());
         
         
         // 如果有扩展信息
         // 如果有扩展信息
         if (profile != null) {
         if (profile != null) {

+ 2 - 0
service/Essential/src/main/java/com/zhentao/vo/UserInfoVO.java

@@ -71,6 +71,8 @@ public class UserInfoVO {
      * 是否VIP会员
      * 是否VIP会员
      */
      */
     private Boolean isVip;
     private Boolean isVip;
+
+    private Integer isMatchmaker;
     
     
     // ========== 扩展信息 ==========
     // ========== 扩展信息 ==========
     
     

+ 44 - 0
service/homePage/src/main/java/com/zhentao/controller/MatchmakerApplyController.java

@@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.*;
 
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import java.io.BufferedReader;
 import java.io.BufferedReader;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Map;
 
 
 /**
 /**
@@ -103,4 +104,47 @@ public class MatchmakerApplyController {
             return Result.error("申请提交失败:" + e.getMessage());
             return Result.error("申请提交失败:" + e.getMessage());
         }
         }
     }
     }
+    
+    /**
+     * 查询用户的红娘申请状态
+     * @param userId 用户ID
+     * @return 申请状态信息
+     */
+    @GetMapping("/status")
+    public Result<Map<String, Object>> getApplyStatus(@RequestParam("userId") Long userId) {
+        try {
+            System.out.println("========== 查询红娘申请状态 ==========");
+            System.out.println("userId: " + userId);
+            
+            if (userId == null) {
+                return Result.error("用户ID不能为空");
+            }
+            
+            // 查询申请记录
+            MatchmakerApply apply = matchmakerApplyService.getApplyByUserId(userId);
+            
+            Map<String, Object> result = new HashMap<>();
+            if (apply == null) {
+                // 没有申请记录,status为null
+                result.put("status", null);
+                result.put("hasApplied", false);
+                System.out.println("未找到申请记录");
+            } else {
+                // 有申请记录,返回status值
+                result.put("status", apply.getStatus());
+                result.put("hasApplied", true);
+                result.put("applyId", apply.getApplyId());
+                result.put("createTime", apply.getCreateTime());
+                System.out.println("找到申请记录,status: " + apply.getStatus());
+            }
+            
+            System.out.println("返回结果: " + result);
+            System.out.println("=====================================");
+            
+            return Result.success(result);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Result.error("查询申请状态失败:" + e.getMessage());
+        }
+    }
 }
 }