From 2885941cf88da7397f2e641e383a26337f3c2b03 Mon Sep 17 00:00:00 2001
From: 44323 <443237572@qq.com>
Date: 星期三, 22 五月 2024 20:55:51 +0800
Subject: [PATCH] 代码提交

---
 ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java |  169 +++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 131 insertions(+), 38 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 6cb31db..4f7e44d 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
@@ -12,18 +12,13 @@
 import com.ruoyi.common.security.service.TokenService;
 import com.ruoyi.common.security.utils.SecurityUtils;
 import com.ruoyi.management.api.feignClient.ManagementClient;
-import com.ruoyi.management.api.model.TFeedback;
-import com.ruoyi.management.api.model.TPage;
-import com.ruoyi.management.api.model.TUseGuide;
-import com.ruoyi.management.api.model.TVipSet;
+import com.ruoyi.management.api.model.*;
 import com.ruoyi.management.api.query.UseGuideQuery;
-import com.ruoyi.study.domain.TUser;
-import com.ruoyi.study.domain.TVipOrder;
+import com.ruoyi.study.domain.*;
 import com.ruoyi.study.dto.AppUserQuery;
 import com.ruoyi.study.dto.UserInfoQuery;
 import com.ruoyi.study.request.RegisterPhoneRequest;
-import com.ruoyi.study.service.ITUserService;
-import com.ruoyi.study.service.IVipOrderService;
+import com.ruoyi.study.service.*;
 import com.ruoyi.study.utils.PayMoneyUtil;
 import com.ruoyi.study.utils.UUIDUtil;
 import com.ruoyi.study.vo.*;
@@ -65,6 +60,8 @@
     private TokenService tokenService;
     @Resource
     private RedisService redisService;
+    @Resource
+    private ITUserShareService userShareService;
 
     @PostMapping("/vipInfo")
     @ApiOperation(value = "会员中心-获取会员说明、当前登录用户是否为会员、会员购买规格", tags = {"家长端-个人中心"})
@@ -182,8 +179,12 @@
                     calendar.setTime(new Date());
                     calendar.add(Calendar.MONTH, time);
                     Date dateAfterOneMonth = calendar.getTime();
-                    byId.setTime(dateAfterOneMonth);
+                    dateAfterOneMonth.setHours(23);
+                    dateAfterOneMonth.setMinutes(59);
+                    dateAfterOneMonth.setSeconds(59);
                     byId1.setVipEndTime(dateAfterOneMonth);
+                    byId.setTime(dateAfterOneMonth);
+
                 } else {
                     // 不是首次 判断vipEndTime 是否到期 如果没有 加指定月份时间 如果到期了 将会员到期时间从当前增加指定月份
                     if (byId1.getVipEndTime().getTime() < new Date().getTime()) {
@@ -191,6 +192,9 @@
                         calendar.setTime(new Date());
                         calendar.add(Calendar.MONTH, time);
                         Date dateAfterOneMonth = calendar.getTime();
+                        dateAfterOneMonth.setHours(23);
+                        dateAfterOneMonth.setMinutes(59);
+                        dateAfterOneMonth.setSeconds(59);
                         byId.setTime(dateAfterOneMonth);
                         byId1.setVipEndTime(dateAfterOneMonth);
                     } else {
@@ -198,6 +202,9 @@
                         calendar.setTime(byId1.getVipEndTime());
                         calendar.add(Calendar.MONTH, time);
                         Date dateAfterOneMonth = calendar.getTime();
+                        dateAfterOneMonth.setHours(23);
+                        dateAfterOneMonth.setMinutes(59);
+                        dateAfterOneMonth.setSeconds(59);
                         byId.setTime(dateAfterOneMonth);
                         byId1.setVipEndTime(dateAfterOneMonth);
                     }
@@ -256,6 +263,9 @@
                     calendar.setTime(new Date());
                     calendar.add(Calendar.MONTH, time);
                     Date dateAfterOneMonth = calendar.getTime();
+                    dateAfterOneMonth.setHours(23);
+                    dateAfterOneMonth.setMinutes(59);
+                    dateAfterOneMonth.setSeconds(59);
                     byId.setTime(dateAfterOneMonth);
                     byId1.setVipEndTime(dateAfterOneMonth);
                 } else {
@@ -265,6 +275,9 @@
                         calendar.setTime(new Date());
                         calendar.add(Calendar.MONTH, time);
                         Date dateAfterOneMonth = calendar.getTime();
+                        dateAfterOneMonth.setHours(23);
+                        dateAfterOneMonth.setMinutes(59);
+                        dateAfterOneMonth.setSeconds(59);
                         byId.setTime(dateAfterOneMonth);
                         byId1.setVipEndTime(dateAfterOneMonth);
                     } else {
@@ -272,6 +285,9 @@
                         calendar.setTime(byId1.getVipEndTime());
                         calendar.add(Calendar.MONTH, time);
                         Date dateAfterOneMonth = calendar.getTime();
+                        dateAfterOneMonth.setHours(23);
+                        dateAfterOneMonth.setMinutes(59);
+                        dateAfterOneMonth.setSeconds(59);
                         byId.setTime(dateAfterOneMonth);
                         byId1.setVipEndTime(dateAfterOneMonth);
                     }
@@ -301,6 +317,7 @@
         }
         return AjaxResult.success();
     }
+
     @PostMapping("/parentPage")
     @ApiOperation(value = "平板", tags = {"家长端-启动页"})
     public AjaxResult<String> parentPage() {
@@ -312,6 +329,7 @@
         }
         return AjaxResult.success();
     }
+
     @PostMapping("/parentPage1")
     @ApiOperation(value = "手机", tags = {"家长端-启动页"})
     public AjaxResult<String> parentPage1() {
@@ -323,6 +341,7 @@
         }
         return AjaxResult.success();
     }
+
     @PostMapping("/getProtocol")
     @ApiOperation(value = "获取协议", tags = {"家长端-协议"})
     @ApiImplicitParams({
@@ -367,9 +386,21 @@
                 return AjaxResult.error("登录失败,您的账号已被冻结!");
             }
         } else {
-            // todo 验证码校验
-            tUser1 = getUser(phone);
-            userService.save(tUser1);
+            // 手机验证码校验
+            Object redisPhoneCode = redisService.getCacheObject(RedisConstants.PHONE_CODE + phone);
+            if (null == redisPhoneCode) {
+                return AjaxResult.error("登录失败,手机验证码已过期!");
+            } else {
+                // redis 验证码的value 为 code:时间戳
+                String rCodeAndTime = String.valueOf(redisPhoneCode);
+                String rCode = rCodeAndTime.split(":")[0];
+                if (!rCode.equalsIgnoreCase(phoneCode)) {
+                    return AjaxResult.error("登录失败,手机验证码输入有误!");
+                } else {
+                    tUser1 = getUser(phone);
+                    userService.save(tUser1);
+                }
+            }
         }
         LoginUserParent loginUserParent = new LoginUserParent();
         loginUserParent.setName(tUser1.getName());
@@ -455,17 +486,40 @@
     }
 
     /**
-     * 家长端 学习端都可用
-     *
-     * @param url app网页链接
+     * 分享图片、标题及可获积分数
      */
-    @GetMapping("/weiXinShare")
-    @ApiOperation(value = "微信分享", tags = {"微信分享"})
-    @ApiImplicitParams({
-            @ApiImplicitParam(value = "应用分享url地址", name = "url", dataType = "string", required = true),
-    })
-    public AjaxResult weiXinShare(@RequestParam String url) {
-        return AjaxResult.success(userService.weiXinShare(url));
+    @GetMapping("/shareInfo")
+    @ApiOperation(value = "微信分享信息", tags = {"微信分享信息"})
+    public AjaxResult shareInfo() {
+        // 分享信息
+        TSysSet data = managementClient.shareInfo().getData();
+        Integer userid = tokenService.getLoginUserStudy().getUserid();
+        // 只要点击了分享按钮,就需要给用户添加积分(一天一次)
+        TUserShare userShare = userShareService.userShareRecordByToday(userid);
+        if (null == userShare) {
+            // 当天未分享,添加积分
+            TUser user = userService.getById(userid);
+            int integral = Integer.parseInt(data.getIntegralShare());
+            user.setIntegral(user.getIntegral() + integral);
+            userService.updateById(user);
+            // 添加分享记录
+            TUserShare record = new TUserShare();
+            record.setIntegral(integral);
+            record.setUserId(userid);
+            userShareService.save(record);
+        }
+        return AjaxResult.success();
+    }
+
+    /**
+     * 获取用户信息
+     *
+     * @return 用户信息
+     */
+    @GetMapping("/userInfo")
+    @ApiOperation(value = "用户详情", tags = {"用户详情"})
+    public R<TUser> userInfo() {
+        return R.ok(userService.lambdaQuery().eq(TUser::getId,tokenService.getLoginUserStudy().getUserid()).one());
     }
 
     @PostMapping("/deleteUser")
@@ -544,6 +598,7 @@
         userService.saveOrUpdate(byId);
         return AjaxResult.success("修改成功");
     }
+
     @ResponseBody
     @PostMapping("/base/wxRefund")
     public void cancelMySiteCallback(HttpServletRequest request, HttpServletResponse response) {
@@ -566,12 +621,12 @@
                         .eq("payState", 2)
                         .orderByDesc("createTime"));
                 int size = list.size();
-                if (size == 0){
+                if (size == 0) {
                     // 证明这是用户第一次充值会员 将首次充值会员时间和会员到期时间清空
                     byId1.setVipEndTime(null);
                     byId1.setVipPayTime(null);
                     userService.updateById(byId1);
-                }else{
+                } else {
                     // 最近的一次充值会员时间
                     TVipOrder tVipOrder = list.get(0);
                     // 将会员到期时间回退到上一次
@@ -588,6 +643,7 @@
             e.printStackTrace();
         }
     }
+
     @PostMapping("/vipBack/{id}")
     @ApiOperation(value = "会员退款", tags = {"管理后台-会员退款"})
     public R vipBack(@PathVariable("id") Integer id) throws AlipayApiException {
@@ -596,7 +652,7 @@
         String transactionId = byId.getTransactionId();
         // 内部订单号
         String outTradeNo = byId.getOutTradeNo();
-        switch (byId.getPayType()){
+        switch (byId.getPayType()) {
             case 1:
                 // 微信退款
                 Map<String, String> stringStringMap = payMoneyUtil.wxRefund(transactionId, outTradeNo, byId.getMoney().toString(), byId.getMoney().toString(), "/base/wxRefund");
@@ -607,11 +663,12 @@
                 if (!"SUCCESS".equals(result_code)) {
                     return R.fail(stringStringMap.get("return_msg"));
                 }
+                byId.setBackTime(new Date());
                 byId.setPayState(3);
                 vipOrderService.updateById(byId);
             case 2:
                 // 支付宝退款
-                Map<String, String> stringStringMap1 = payMoneyUtil.aliRefund(transactionId,byId.getMoney().toString());
+                Map<String, String> stringStringMap1 = payMoneyUtil.aliRefund(transactionId, byId.getMoney().toString());
                 if (null == stringStringMap1) {
                     return R.fail("取消退款异常");
                 }
@@ -635,12 +692,12 @@
                         .eq("payState", 2)
                         .orderByDesc("createTime"));
                 int size = list.size();
-                if (size == 0){
+                if (size == 0) {
                     // 证明这是用户第一次充值会员 将首次充值会员时间和会员到期时间清空
                     byId1.setVipEndTime(null);
                     byId1.setVipPayTime(null);
                     userService.updateById(byId1);
-                }else{
+                } else {
                     // 最近的一次充值会员时间
                     TVipOrder tVipOrder = list.get(0);
                     // 将会员到期时间回退到上一次
@@ -672,7 +729,12 @@
         res.setTotal(list.size());
         return R.ok(res);
     }
-
+    @Resource
+    private ITUserStudyService userStudyService;
+    @Resource
+    private ITGameRecordService gameRecordService;
+    @Autowired
+    private ITStudyService studyService;
     @PostMapping("/getUserInfo")
     @ApiOperation(value = "查看用户详情", tags = {"管理后台-用户管理"})
     public R<UserInfoVO> getUserInfo(@RequestBody UserInfoQuery dto) {
@@ -704,17 +766,48 @@
         res.setPhone(phone);
         res.setInsertTime(format.format(insertTime));
         res.setIntegral(byId.getIntegral());
-        // todo 查询进度
-        res.setCurrent(0);
-        res.setSurplus(0);
-        res.setTotalHours(0d);
-        res.setTodayHours(0d);
-        res.setWeekHours(0d);
-        res.setMonthHours(0d);
-        // todo 查询用户的游戏记录
+        TUserStudy studyRecord = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, dto.getId())
+                .eq(TUserStudy::getDisabled, 0).one();
+        // 游戏测试成绩
+        List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, dto.getId())
+                .eq(TGameRecord::getDisabled, 0).list();
+        if (studyRecord!=null){
+            res.setCurrent(studyRecord.getWeek());
+            // 查询当前听的总周目
+            List<TStudy> list1 = studyService.list(new QueryWrapper<>());
+            res.setSurplus(list1.size()-studyRecord.getWeek());
+            res.setTotalHours(studyRecord.getTotalStudy().doubleValue());
+            res.setTodayHours(studyRecord.getTodayStudy().doubleValue());
+            res.setWeekHours(studyRecord.getWeekStudy().doubleValue());
+            res.setMonthHours(studyRecord.getMonthStudy().doubleValue());
+        }else{
+            res.setCurrent(0);
+            res.setSurplus(0);
+            res.setTotalHours(0.0);
+            res.setTodayHours(0.0);
+            res.setWeekHours(0.0);
+            res.setMonthHours(0.0);
+        }
+
         List<UserGameRecordVO> userGameRecordVOS = new ArrayList<>();
+        for (TGameRecord tGameRecord : gameRecordList) {
+            UserGameRecordVO userGameRecordVO = new UserGameRecordVO();
+            userGameRecordVO.setGameName(tGameRecord.getGameName());
+            userGameRecordVO.setUseTime(tGameRecord.getUseTime().toString());
+            if (tGameRecord.getGameDifficulty() == 0) {
+                userGameRecordVO.setAccuracy("100%");
+            } else {
+                userGameRecordVO.setAccuracy(tGameRecord.getAccuracy() + "%");
+            }
+            if (tGameRecord.getGameDifficulty() == 0) {
+                userGameRecordVO.setTime(tGameRecord.getUseTime());
+            } else {
+                userGameRecordVO.setTime(tGameRecord.getUseTime() / 2);
+            }
+            userGameRecordVOS.add(userGameRecordVO);
+        }
         list.setRecords(userGameRecordVOS);
-        list.setTotal(0);
+        list.setTotal(userGameRecordVOS.size());
         res.setGameRecords(list);
         return R.ok(res);
     }

--
Gitblit v1.7.1