无关风月
2024-07-19 1003cc0de71e26ffee6d9df9bcf4b5e4a3ead7b6
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java
@@ -28,7 +28,6 @@
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
@@ -65,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")
@@ -176,8 +209,12 @@
        try {
            System.err.println("进入支付宝回调");
            Map<String, String> map = payMoneyUtil.alipayCallback(request);
            System.err.println("返回参数"+map);
            System.err.println("返回参数" + map);
            if (null != map) {
                PrintWriter out = response.getWriter();
                out.write("success");
                out.flush();
                out.close();
                String out_trade_no = map.get("out_trade_no");
                String trade_no = map.get("trade_no");
                // 会员规格id
@@ -193,7 +230,7 @@
                String s1 = out_trade_no.split("_")[1];
                Integer integer1 = Integer.valueOf(s1);
                TVipOrder byId = vipOrderService.getById(integer1);
                if (byId.getBackTime()!=null){
                if (byId.getBackTime() != null) {
                    return;
                }
                byId.setPayState(2);
@@ -245,10 +282,7 @@
                // 修改用户会员续期信息
                userService.updateById(byId1);
                PrintWriter out = response.getWriter();
                out.write("success");
                out.flush();
                out.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
@@ -261,11 +295,16 @@
        try {
            Map<String, String> map = payMoneyUtil.weixinpayCallback(request);
            if (null != map) {
                // 内部订单号
                String out_trade_no = map.get("out_trade_no");
                // 微信订单号
                String transaction_id = map.get("transaction_id");
                String result = map.get("result");
                PrintWriter out = response.getWriter();
                out.write(result);
                out.flush();
                out.close();
                // 会员规格id
                String s = out_trade_no.split("_")[0];
                Integer integer = Integer.valueOf(s);
@@ -326,10 +365,7 @@
                vipOrderService.updateById(byId);
                // 修改用户会员续期信息
                userService.updateById(byId1);
                PrintWriter out = response.getWriter();
                out.write(result);
                out.flush();
                out.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
@@ -467,6 +503,7 @@
                return R.freeze("登录失败,您的账号已被冻结!");
            }
        } else {
            tUser1 = new TUser();
            // 手机验证码校验
            if (!phoneCode.equals("123456")) {
                Object redisPhoneCode = redisService.getCacheObject(RedisConstants.PHONE_CODE + phone);
@@ -628,7 +665,7 @@
            @ApiImplicitParam(value = "类型 更换手机号的时候传该参数 传1", name = "type", dataType = "int"),
    })
    public R<?> sendPhoneCode(String phone, Integer type) throws Exception {
        if (type != null && type == 1){
        if (type != null && type == 1) {
            List<TUser> list = userService.list(new QueryWrapper<TUser>()
                    .eq("phone", phone)
                    .ne("state", 3));
@@ -636,11 +673,11 @@
                return R.fail("更换的手机号已被使用!");
            }
            LoginUserParent loginUser1 = tokenService.getLoginUser1();
            if (loginUser1==null){
            if (loginUser1 == null) {
                return R.tokenError("登录失效!");
            }
            TUser byId = userService.getById(loginUser1.getUserid());
            if (byId.getPhone().equals(phone)){
            if (byId.getPhone().equals(phone)) {
                return R.fail("更换的手机号不能和原手机号相同!");
            }
        }
@@ -671,7 +708,14 @@
            TUserShare record = new TUserShare();
            record.setIntegral(integral);
            record.setUserId(userid);
            // 积分明细
            userShareService.save(record);
            TIntegralRecord tIntegralRecord = new TIntegralRecord();
            tIntegralRecord.setIntegral(data.getIntegralShare());
            tIntegralRecord.setMethod("每日分享");
            tIntegralRecord.setUserId(userid);
            integralRecordService.save(tIntegralRecord);
        }
        return R.ok(data);
    }
@@ -701,6 +745,11 @@
            record.setIntegral(integral);
            record.setUserId(userid);
            userShareService.save(record);
            TIntegralRecord tIntegralRecord = new TIntegralRecord();
            tIntegralRecord.setIntegral(data.getIntegralShare());
            tIntegralRecord.setMethod("每日分享");
            tIntegralRecord.setUserId(userid);
            integralRecordService.save(tIntegralRecord);
        }
        return R.ok(data);
    }
@@ -735,7 +784,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));
    }
@@ -777,7 +826,7 @@
            } else {
                byId.setIsVip(Constants.ONE);
            }
        }else{
        } else {
            byId.setIsVip(Constants.ZERO);
        }
        return R.ok(byId);
@@ -799,7 +848,22 @@
        userService.removeById(tUser);
        return R.ok("注销成功");
    }
    @PostMapping("/deleteUserStudy")
    @ApiOperation(value = "注销当前帐号", tags = {"学习端-个人中心"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
    })
    public R<String> deleteUserStudy() {
        if (tokenService.getLoginUserStudy() == null) {
            return R.tokenError("登录失效");
        }
        Integer userid = tokenService.getLoginUserStudy().getUserid();
        TUser tUser = userService.getById(userid);
        tUser.setState(3);
        userService.updateById(tUser);
        userService.removeById(tUser);
        return R.ok("注销成功");
    }
    @PostMapping("/logout")
    @ApiOperation(value = "退出登录", tags = {"家长端-个人中心"})
    @ApiImplicitParams({
@@ -855,7 +919,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];
@@ -878,9 +942,14 @@
        try {
            Map<String, String> map = payMoneyUtil.wxRefundCallback(request);
            if (null != map) {
                String code = map.get("out_refund_no");
                String refund_id = map.get("refund_id");
                String result = map.get("result");
                PrintWriter out = response.getWriter();
                out.write(result);
                out.flush();
                out.close();
                TVipOrder one = vipOrderService.getOne(new QueryWrapper<TVipOrder>()
                        .eq("outTradeNo", code)
                        .eq("payState", 3));
@@ -907,10 +976,7 @@
                    userService.updateById(byId1);
                }
                PrintWriter out = response.getWriter();
                out.write(result);
                out.flush();
                out.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
@@ -942,7 +1008,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("取消退款异常");
                }
@@ -950,7 +1016,7 @@
                if (!"10000".equals(code)) {
                    return R.fail(stringStringMap1.get("return_msg"));
                }
                System.err.println("修改会员订单状态"+ byId);
                System.err.println("修改会员订单状态" + byId);
                byId.setPayState(3);
                byId.setBackTime(new Date());
                vipOrderService.updateById(byId);
@@ -972,7 +1038,7 @@
                    byId1.setVipEndTime(null);
                    byId1.setVipPayTime(null);
                    userService.updateById(byId1);
                    userService.updateOne(byId1.getId(),null,null);
                    userService.updateOne(byId1.getId(), null, null);
                } else {
                    System.err.println("最近的一次充值会员时间  将会员到期时间回退到上一次");
                    // 最近的一次充值会员时间
@@ -1035,13 +1101,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());
@@ -1083,14 +1149,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());