From 0287a322e16580901ddb8e781df9da616f4751f9 Mon Sep 17 00:00:00 2001
From: hjl <1657978663@qq.com>
Date: 星期一, 08 七月 2024 09:00:34 +0800
Subject: [PATCH] fix: 学习端bug

---
 ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java |  110 +++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 94 insertions(+), 16 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 63f340d..5e6aa69 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
@@ -64,11 +64,45 @@
     @Resource
     private ITUserShareService userShareService;
 
+    @Autowired
+    private ITIntegralRecordService integralRecordService;
     @PostMapping("/getUserById/{id}")
     @ApiOperation(value = "根据用户id 获取用户信息", tags = {"管理后台-用户管理"})
     public R<TUser> getUserById(@PathVariable("id") Integer id) {
         TUser byId = userService.getById(id);
         return R.ok(byId);
+    }
+
+    @PostMapping("/vipInfoStudy")
+    @ApiOperation(value = "会员中心-获取会员说明、当前登录用户是否为会员、会员购买规格", tags = {"学习端-个人中心"})
+    public R<List<VipInfoVO>> vipInfoStudy() {
+        if (tokenService.getLoginUserStudy() == null) {
+            throw new GlobalException("登录失效!");
+        }
+        List<VipInfoVO> vipInfoVOS = new ArrayList<>();
+        List<TVipSet> data = managementClient.getVipSet1().getData();
+        for (TVipSet datum : data) {
+            VipInfoVO vipInfoVO = new VipInfoVO();
+            vipInfoVO.setInfo(datum.getInfo());
+            vipInfoVO.setId(datum.getId());
+            Integer userid = tokenService.getLoginUserStudy().getUserid();
+            TUser byId = userService.getById(userid);
+            // 先判断vipEndTime
+            if (byId.getVipEndTime() == null) {
+                vipInfoVO.setIsVip(0);
+            } else {
+                // 判断会员到期时间是否大于当前时间
+                if (byId.getVipEndTime().getTime() > System.currentTimeMillis()) {
+                    vipInfoVO.setIsVip(1);
+                } else {
+                    vipInfoVO.setIsVip(0);
+                }
+            }
+            vipInfoVO.setTime(datum.getTime());
+            vipInfoVO.setAmount(datum.getAmount());
+            vipInfoVOS.add(vipInfoVO);
+        }
+        return R.ok(vipInfoVOS);
     }
 
     @PostMapping("/vipInfo")
@@ -175,7 +209,7 @@
         try {
             System.err.println("进入支付宝回调");
             Map<String, String> map = payMoneyUtil.alipayCallback(request);
-            System.err.println("返回参数"+map);
+            System.err.println("返回参数" + map);
             if (null != map) {
                 String out_trade_no = map.get("out_trade_no");
                 String trade_no = map.get("trade_no");
@@ -192,6 +226,9 @@
                 String s1 = out_trade_no.split("_")[1];
                 Integer integer1 = Integer.valueOf(s1);
                 TVipOrder byId = vipOrderService.getById(integer1);
+                if (byId.getBackTime() != null) {
+                    return;
+                }
                 byId.setPayState(2);
                 byId.setTransactionId(trade_no);
                 byId.setOutTradeNo(out_trade_no);
@@ -447,13 +484,14 @@
         return R.ok("反馈成功");
     }
 
+
     @PostMapping("/parentLogin")
     @ApiOperation(value = "登录", tags = {"家长端-登录"})
     @ApiImplicitParams({
             @ApiImplicitParam(value = "手机号", name = "phone", dataType = "string", required = true),
             @ApiImplicitParam(value = "验证码", name = "phoneCode", dataType = "string", required = true)
     })
-    public R<Map<String, Object>> login(String phone, String phoneCode) {
+    public R<Map<String, Object>> login(String phone, String phoneCode) throws Exception {
         TUser tUser1 = userService.getOne(new QueryWrapper<TUser>()
                 .ne("state", 3)
                 .eq("phone", phone));
@@ -476,14 +514,18 @@
                     } else {
                         tUser1.setHeadImg("https://haitunyingyu.obs.cn-southwest-2.myhuaweicloud.com/admin/1c6ee218aa18434db2e86df903990de8.jpg");
                         tUser1 = getUser(phone);
-                        tUser1.setAccount("用户"+UUIDUtil.getNumberRandom(6));
+                        String upperCase = UUIDUtil.getRandomCode(6).toUpperCase();
+                        tUser1.setAccount("用户"+upperCase);
+                        tUser1.setName("用户"+upperCase);
                         userService.save(tUser1);
                     }
                 }
             } else {
+                String upperCase = UUIDUtil.getRandomCode(6).toUpperCase();
                 tUser1 = getUser(phone);
                 tUser1.setHeadImg("https://haitunyingyu.obs.cn-southwest-2.myhuaweicloud.com/admin/1c6ee218aa18434db2e86df903990de8.jpg");
-                tUser1.setAccount("用户"+UUIDUtil.getNumberRandom(6));
+                tUser1.setAccount("用户"+upperCase);
+                tUser1.setName("用户"+upperCase);
                 userService.save(tUser1);
             }
         }
@@ -527,7 +569,7 @@
      */
     @PostMapping("/studyLogin")
     @ApiOperation(value = "学习端-登录", tags = {"学习端-登录"})
-    public R<Map<String, Object>> studyLogin(@RequestBody RegisterPhoneRequest phoneRequest) {
+    public R<Map<String, Object>> studyLogin(@RequestBody RegisterPhoneRequest phoneRequest) throws Exception {
         String phone = phoneRequest.getPhone();
         String phoneCode = phoneRequest.getPhoneCode();
         if (!"123456".equals(phoneCode)) {
@@ -555,7 +597,9 @@
         } else {
             user = getUser(phone);
             user.setHeadImg("https://haitunyingyu.obs.cn-southwest-2.myhuaweicloud.com/admin/1c6ee218aa18434db2e86df903990de8.jpg");
-            user.setAccount("用户"+UUIDUtil.getNumberRandom(6));
+            String upperCase = UUIDUtil.getRandomCode(6).toUpperCase();
+            user.setAccount("用户"+upperCase);
+            user.setName("用户"+upperCase);
             userService.save(user);
         }
         // 生成登录用户信息
@@ -614,8 +658,25 @@
     @ApiOperation(value = "发送手机验证码", tags = {"家长端/学习端-发送手机验证码"})
     @ApiImplicitParams({
             @ApiImplicitParam(value = "手机号", name = "phone", dataType = "string", required = true),
+            @ApiImplicitParam(value = "类型 更换手机号的时候传该参数 传1", name = "type", dataType = "int"),
     })
-    public R<?> sendPhoneCode(@RequestParam String phone) throws Exception {
+    public R<?> sendPhoneCode(String phone, Integer type) throws Exception {
+        if (type != null && type == 1) {
+            List<TUser> list = userService.list(new QueryWrapper<TUser>()
+                    .eq("phone", phone)
+                    .ne("state", 3));
+            if (!list.isEmpty()) {
+                return R.fail("更换的手机号已被使用!");
+            }
+            LoginUserParent loginUser1 = tokenService.getLoginUser1();
+            if (loginUser1 == null) {
+                return R.tokenError("登录失效!");
+            }
+            TUser byId = userService.getById(loginUser1.getUserid());
+            if (byId.getPhone().equals(phone)) {
+                return R.fail("更换的手机号不能和原手机号相同!");
+            }
+        }
         return userService.phoneCode(phone) ? R.ok() : R.fail();
     }
 
@@ -643,7 +704,14 @@
             TUserShare record = new TUserShare();
             record.setIntegral(integral);
             record.setUserId(userid);
+            // 积分明细
+
             userShareService.save(record);
+            TIntegralRecord tIntegralRecord = new TIntegralRecord();
+            tIntegralRecord.setIntegral(data.getIntegral());
+            tIntegralRecord.setMethod("每日分享");
+            tIntegralRecord.setUserId(userid);
+            integralRecordService.save(tIntegralRecord);
         }
         return R.ok(data);
     }
@@ -673,6 +741,11 @@
             record.setIntegral(integral);
             record.setUserId(userid);
             userShareService.save(record);
+            TIntegralRecord tIntegralRecord = new TIntegralRecord();
+            tIntegralRecord.setIntegral(data.getIntegral());
+            tIntegralRecord.setMethod("每日分享");
+            tIntegralRecord.setUserId(userid);
+            integralRecordService.save(tIntegralRecord);
         }
         return R.ok(data);
     }
@@ -707,7 +780,7 @@
                 .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));
+        userStudy.setTotalStudy(Math.round((float) (totalStudy) / 3600));
         return R.ok(new UserPersonalCenterVO(user, userStudy));
     }
 
@@ -749,7 +822,7 @@
             } else {
                 byId.setIsVip(Constants.ONE);
             }
-        }else{
+        } else {
             byId.setIsVip(Constants.ZERO);
         }
         return R.ok(byId);
@@ -816,7 +889,7 @@
             List<TUser> list = userService.list(new QueryWrapper<TUser>()
                     .eq("phone", phone)
                     .ne("state", 3));
-            if (list.size() > 0) {
+            if (!list.isEmpty()) {
                 return R.fail("更换的手机号已被使用!");
             }
             byId.setPhone(phone);
@@ -827,7 +900,7 @@
                 Object redisPhoneCode = redisService.getCacheObject(RedisConstants.PHONE_CODE + phone);
                 if (null == redisPhoneCode) {
                     return R.errorCode("手机验证码无效");
-                }else{
+                } else {
                     // redis 验证码的value 为 code:时间戳
                     String rCodeAndTime = String.valueOf(redisPhoneCode);
                     String rCode = rCodeAndTime.split(":")[0];
@@ -914,7 +987,7 @@
             case 2:
                 // 支付宝退款
                 Map<String, String> stringStringMap1 = payMoneyUtil.aliRefund(transactionId, byId.getMoney().toString());
-                System.err.println("支付宝退款数据"+ stringStringMap1);
+                System.err.println("支付宝退款数据" + stringStringMap1);
                 if (null == stringStringMap1) {
                     return R.fail("取消退款异常");
                 }
@@ -922,6 +995,7 @@
                 if (!"10000".equals(code)) {
                     return R.fail(stringStringMap1.get("return_msg"));
                 }
+                System.err.println("修改会员订单状态" + byId);
                 byId.setPayState(3);
                 byId.setBackTime(new Date());
                 vipOrderService.updateById(byId);
@@ -938,15 +1012,19 @@
                         .orderByDesc("createTime"));
                 int size = list.size();
                 if (size == 0) {
+                    System.err.println("证明这是用户第一次充值会员 将首次充值会员时间和会员到期时间清空");
                     // 证明这是用户第一次充值会员 将首次充值会员时间和会员到期时间清空
                     byId1.setVipEndTime(null);
                     byId1.setVipPayTime(null);
                     userService.updateById(byId1);
+                    userService.updateOne(byId1.getId(), null, null);
                 } else {
+                    System.err.println("最近的一次充值会员时间  将会员到期时间回退到上一次");
                     // 最近的一次充值会员时间
                     TVipOrder tVipOrder = list.get(0);
                     // 将会员到期时间回退到上一次
                     byId1.setVipEndTime(tVipOrder.getTime());
+                    byId1.setVipPayTime(tVipOrder.getPayTime());
                     userService.updateById(byId1);
                 }
                 return R.ok();
@@ -1002,13 +1080,13 @@
                 res.setIsVip(0);
             }
         }
-        if (vipEndTime!=null){
+        if (vipEndTime != null) {
             res.setVipPayTime(format.format(vipPayTime));
         }
         res.setState(byId.getState());
         res.setName(name);
         res.setPhone(phone);
-        if (insertTime!=null){
+        if (insertTime != null) {
             res.setInsertTime(format.format(insertTime));
         }
         res.setIntegral(byId.getIntegral());
@@ -1050,14 +1128,14 @@
         int sum = gameRecordList.stream().map(TGameRecord::getUseTime).mapToInt(Integer::intValue).sum();
         Integer totalStudy = studyRecord.getTotalStudy();
         studyRecord.setTotalStudy(Math.round((float) (totalStudy) / 3600));
-        res.setCurrent(studyRecord.getWeek()+"");
+        res.setCurrent(studyRecord.getWeek() + "");
         // 剩余周目
         List<TStudy> studyList = studyService.lambdaQuery().eq(TStudy::getDisabled, 0)
                 .eq(TStudy::getType, Constants.ONE)
                 .orderByAsc(TStudy::getWeek).list();
         int size = studyService.residueWeek(studyRecord, studyList);
         studyRecord.setSurplus(size);
-        res.setSurplus(studyRecord.getSurplus()+"");
+        res.setSurplus(studyRecord.getSurplus() + "");
         res.setTotalHours(studyRecord.getTotalStudy().doubleValue());
         res.setTodayHours(studyRecord.getTodayStudy().doubleValue());
         res.setMonthHours(studyRecord.getMonthStudy().doubleValue());

--
Gitblit v1.7.1