From d51639d2352b5a0d9e434a6d0356f9f48ca19969 Mon Sep 17 00:00:00 2001
From: hjl <1657978663@qq.com>
Date: 星期三, 19 六月 2024 10:53:31 +0800
Subject: [PATCH] fix: 家长端商城兑换bug;学习端默认登录验证码

---
 ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java |   40 ++++++++++++++++++++++++++++++----------
 1 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java
index eed6d49..c32cf5e 100644
--- a/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java
+++ b/ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java
@@ -529,16 +529,18 @@
     public R<Map<String, Object>> studyLogin(@RequestBody RegisterPhoneRequest phoneRequest) {
         String phone = phoneRequest.getPhone();
         String phoneCode = phoneRequest.getPhoneCode();
-        // 验证码校验
-        Object redisPhoneCode = redisService.getCacheObject(RedisConstants.PHONE_CODE + phone);
-        if (null == redisPhoneCode) {
-            return R.errorCode("登录失败,验证码无效!");
-        } else {
-            // redis 验证码的value 为 code:时间戳
-            String rCodeAndTime = String.valueOf(redisPhoneCode);
-            String rCode = rCodeAndTime.split(":")[0];
-            if (!rCode.equalsIgnoreCase(phoneCode) || !"123456".equals(phoneCode)) {
+        if (!"123456".equals(phoneCode)) {
+            // 验证码校验
+            Object redisPhoneCode = redisService.getCacheObject(RedisConstants.PHONE_CODE + phone);
+            if (null == redisPhoneCode) {
                 return R.errorCode("登录失败,验证码无效!");
+            } else {
+                // redis 验证码的value 为 code:时间戳
+                String rCodeAndTime = String.valueOf(redisPhoneCode);
+                String rCode = rCodeAndTime.split(":")[0];
+                if (!rCode.equalsIgnoreCase(phoneCode)) {
+                    return R.errorCode("登录失败,验证码无效!");
+                }
             }
         }
         // 获取手机号所注册用户信息
@@ -699,8 +701,26 @@
     @GetMapping("/userInfo")
     @ApiOperation(value = "用户详情", tags = {"学习端-用户详情"})
     public R<UserPersonalCenterVO> userInfo() {
-        TUser user = userService.lambdaQuery().eq(TUser::getId, tokenService.getLoginUserStudy().getUserid()).one();
+        LoginUserParent loginUserStudy = tokenService.getLoginUserStudy();
+        if (null == loginUserStudy) {
+            return R.tokenError("登录失效!");
+        }
+        TUser user = userService.lambdaQuery().eq(TUser::getId, loginUserStudy.getUserid()).one();
         TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, user.getId()).eq(TUserStudy::getDisabled, 0).one();
+        // 学习时长格式转换
+        Integer todayStudy = userStudy.getTodayStudy();
+        userStudy.setTodayStudy(Math.round((float) todayStudy / 3600));
+        Integer weekStudy = userStudy.getWeekStudy();
+        userStudy.setWeekStudy(Math.round((float) weekStudy / 3600));
+        Integer monthStudy = userStudy.getMonthStudy();
+        userStudy.setMonthStudy(Math.round((float) monthStudy / 3600));
+        // 总时长还需计算上游戏测试成绩时长
+        List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery()
+                .eq(TGameRecord::getUserId, loginUserStudy.getUserid())
+                .eq(TGameRecord::getDisabled, 0).list();
+        int sum = gameRecordList.stream().map(TGameRecord::getUseTime).mapToInt(Integer::intValue).sum();
+        Integer totalStudy = userStudy.getTotalStudy();
+        userStudy.setTotalStudy(Math.round((float) (totalStudy + sum) / 3600));
         return R.ok(new UserPersonalCenterVO(user, userStudy));
     }
 

--
Gitblit v1.7.1