44323
2024-05-21 781b5fea46cd55220b5ffca17aa6bb1b83551410
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java
@@ -4,12 +4,19 @@
import com.alipay.api.AlipayApiException;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.JwtUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.auth.AuthUtil;
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.query.UseGuideQuery;
import com.ruoyi.study.domain.TUser;
import com.ruoyi.study.domain.TVipOrder;
import com.ruoyi.study.dto.AppUserQuery;
@@ -19,10 +26,17 @@
import com.ruoyi.study.utils.PayMoneyUtil;
import com.ruoyi.study.utils.UUIDUtil;
import com.ruoyi.study.vo.*;
import com.ruoyi.system.api.domain.SysRole;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import com.ruoyi.system.api.model.LoginUserParent;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
@@ -50,16 +64,34 @@
    private IVipOrderService vipOrderService;
    @Autowired
    private ManagementClient managementClient;
    @Autowired
    private TokenService tokenService;
    @PostMapping("/vipInfo")
    @ApiOperation(value = "会员中心-获取会员说明、当前登录用户是否为会员、会员购买规格", tags = {"家长端-个人中心"})
    public AjaxResult<List<VipInfoVO>> vipInfo() {
        if (tokenService.getLoginUser1() == null){
            return AjaxResult.tokenError("登录失效",new Object());
        }
        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());
//            vipInfoVO.setIsVip();
            Integer userid = tokenService.getLoginUser1().getUserid();
            TUser byId = userService.getById(userid);
            // 先判断vipEndTime
            if (byId.getVipEndTime() == null){
                vipInfoVO.setIsVip(0);
            }else{
                // 判断会员到期时间是否大于当前时间
                if (byId.getVipEndTime().getTime() > new Date().getTime()){
                    vipInfoVO.setIsVip(1);
                }else{
                    vipInfoVO.setIsVip(0);
                }
            }
            vipInfoVO.setTime(datum.getTime());
            vipInfoVO.setAmount(datum.getAmount());
        }
@@ -76,6 +108,10 @@
            @ApiImplicitParam(name = "id", value = "会员规格id", required = true),
    })
    public AjaxResult order(Integer payType,Integer id) throws Exception {
        if (tokenService.getLoginUser1() == null){
            return AjaxResult.tokenError("登录失效",new Object());
        }
        Integer userid = tokenService.getLoginUser1().getUserid();
        TVipOrder tVipOrder = new TVipOrder();
        List<TVipSet> data = managementClient.getVipSet1().getData();
        Integer time = 0;
@@ -86,10 +122,7 @@
            }
        }
        tVipOrder.setPayState(1);
//        tVipOrder.setUserId();
//        tVipOrder.setPayTime();
//        tVipOrder.setBackTime();
//        tVipOrder.setTime();
        tVipOrder.setUserId(userid);
        tVipOrder.setPayType(payType);
        tVipOrder.setCount(time);
        switch (payType){
@@ -137,19 +170,40 @@
                byId.setTransactionId(trade_no);
                byId.setOutTradeNo(out_trade_no);
                byId.setPayTime(new Date());
                TUser byId1 = userService.getById(byId.getUserId());
                if (byId1.getVipPayTime() == null){
                    // 是否是首次充值会员
                    byId1.setVipPayTime(new Date());
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(new Date());
                calendar.add(Calendar.MONTH, time);
                Date dateAfterOneMonth = calendar.getTime();
                byId.setTime(dateAfterOneMonth);
                    byId1.setVipEndTime(dateAfterOneMonth);
                }else{
                    // 不是首次 判断vipEndTime 是否到期 如果没有 加指定月份时间 如果到期了 将会员到期时间从当前增加指定月份
                    if (byId1.getVipEndTime().getTime() < new Date().getTime()){
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTime(new Date());
                        calendar.add(Calendar.MONTH, time);
                        Date dateAfterOneMonth = calendar.getTime();
                        byId.setTime(dateAfterOneMonth);
                        byId1.setVipEndTime(dateAfterOneMonth);
                    }else{
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTime(byId1.getVipEndTime());
                        calendar.add(Calendar.MONTH, time);
                        Date dateAfterOneMonth = calendar.getTime();
                        byId.setTime(dateAfterOneMonth);
                        byId1.setVipEndTime(dateAfterOneMonth);
                    }
                }
                // 修改订单状态
                vipOrderService.updateById(byId);
                TUser byId1 = userService.getById(byId.getUserId());
                if (byId1.getVipPayTime() == null){
                    // 是否是首次充值会员
                    byId1.setVipPayTime(new Date());
                }
                byId1.setVipEndTime(dateAfterOneMonth);
                // 修改用户会员续期信息
                userService.updateById(byId1);
                PrintWriter out = response.getWriter();
@@ -189,19 +243,38 @@
                byId.setTransactionId(transaction_id);
                byId.setOutTradeNo(out_trade_no);
                byId.setPayTime(new Date());
                TUser byId1 = userService.getById(byId.getUserId());
                if (byId1.getVipPayTime() == null){
                    // 是否是首次充值会员
                    byId1.setVipPayTime(new Date());
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(new Date());
                calendar.add(Calendar.MONTH, time);
                Date dateAfterOneMonth = calendar.getTime();
                byId.setTime(dateAfterOneMonth);
                    byId1.setVipEndTime(dateAfterOneMonth);
                }else{
                    // 不是首次 判断vipEndTime 是否到期 如果没有 加指定月份时间 如果到期了 将会员到期时间从当前增加指定月份
                    if (byId1.getVipEndTime().getTime() < new Date().getTime()){
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTime(new Date());
                        calendar.add(Calendar.MONTH, time);
                        Date dateAfterOneMonth = calendar.getTime();
                        byId.setTime(dateAfterOneMonth);
                        byId1.setVipEndTime(dateAfterOneMonth);
                    }else{
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTime(byId1.getVipEndTime());
                        calendar.add(Calendar.MONTH, time);
                        Date dateAfterOneMonth = calendar.getTime();
                        byId.setTime(dateAfterOneMonth);
                        byId1.setVipEndTime(dateAfterOneMonth);
                    }
                }
                // 修改订单状态
                vipOrderService.updateById(byId);
                TUser byId1 = userService.getById(byId.getUserId());
                if (byId1.getVipPayTime() == null){
                    // 是否是首次充值会员
                    byId1.setVipPayTime(new Date());
                }
                byId1.setVipEndTime(dateAfterOneMonth);
                // 修改用户会员续期信息
                userService.updateById(byId1);
                PrintWriter out = response.getWriter();
@@ -215,66 +288,107 @@
    }
    @PostMapping("/getPage")
    @ApiOperation(value = "获取注意事项", tags = {"家长端-注意事项"})
    public AjaxResult<TPage> getPage() {
    public AjaxResult<String> getPage() {
        List<TPage> data = managementClient.getPage1().getData();
        for (TPage datum : data) {
            if (datum.getType() == 4){
                return AjaxResult.success(datum);
                return AjaxResult.success(datum.getImg());
            }
        }
        return AjaxResult.success();
    }
    @Autowired
    private TokenService tokenService;
//    @Autowired
//    private HWSendSms hwSendSms;
//    @ResponseBody
//    @PostMapping("/getSMSCode")
//    @ApiOperation(value = "获取短信验证码", tags = {"家长端-登录注册"})
//    @ApiImplicitParams({
//            @ApiImplicitParam(value = "类型(1:登录,2:注册,3:修改密码,4:忘记密码,5:修改绑定手机号)", name = "type", dataType = "int", required = true),
//            @ApiImplicitParam(value = "电话号码", name = "phone", dataType = "string", required = true)
//    })
//    public AjaxResult getSMSCode(Integer type, String phone) {
//        if (ToolUtil.isEmpty(phone)) {
//            return AjaxResult.paranErr("phone");
//        }
//        if (ToolUtil.isEmpty(type)) {
//            return AjaxResult.paranErr("type");
//        }
//        try {
//            if (type == 2) {
//                AppUser tAppUser = appUserService.selectOne(new EntityWrapper<AppUser>()
//                        .eq("phone", phone).ne("state", 3));
//                if (null != tAppUser) {
//                    return AjaxResult.error("账号已存在");
//                }
//            }
//            if (type == 5) {
//                AppUser tAppUser = appUserService.selectOne(new EntityWrapper<AppUser>()
//                        .eq("phone", phone).ne("state", 3));
//                if (null != tAppUser) {
//                    return AjaxResult.error("账号已存在");
//                }
//            }
//            String numberRandom = UUIDUtil.getNumberRandom(6);
//            String templateCode = "";
//            if (type == 1 || type == 2) {
//                templateCode = "SMS_161275250";
//            }
//            if (type == 3 || type == 4) {
//                templateCode = "SMS_160960014";
//            }
////            aLiSendSms.sendSms(phone, templateCode, "{\"code\":\"" + numberRandom + "\"}");
//            hwSendSms.sendSms(numberRandom,phone);
//            redisUtil.setStrValue(phone, numberRandom, 300);
//            return AjaxResult.success();
//        } catch (Exception e) {
//            e.printStackTrace();
//            return ResultUtil.runErr();
//        }
//    }
    @PostMapping("/useGuide")
    @ApiOperation(value = "使用指南", tags = {"家长端-使用指南"})
    public AjaxResult<PageInfo<TUseGuide>> useGuide(@RequestBody UseGuideQuery query) {
        PageInfo<TUseGuide> data = managementClient.useGuide1(query).getData();
        return AjaxResult.success(data);
    }
    @PostMapping("/feedBack")
    @ApiOperation(value = "反馈", tags = {"家长端-意见反馈"})
    public AjaxResult feedBack(@RequestBody TFeedback dto) {
        if (tokenService.getLoginUser1() == null){
            return AjaxResult.tokenError("登录失效",new Object());
        }
        LoginUserParent loginUser1 = tokenService.getLoginUser1();
        dto.setUserId(loginUser1.getUserid());
        managementClient.addFeedBack(dto);
        return AjaxResult.success("反馈成功");
    }
    @PostMapping("/parentLogin")
    @ApiOperation(value = "登录", tags = {"家长端-登录"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "手机号", name = "phone", dataType = "string", required = true),
            @ApiImplicitParam(value = "验证码", name = "phoneCode", dataType = "string", required = true)
    })
    public AjaxResult login(String phone, String phoneCode)
    {
        TUser tUser1 = userService.getOne(new QueryWrapper<TUser>()
                .ne("state", 3)
                .eq("phone",phone));
        if (tUser1 != null){
            if (tUser1.getState() == 2){
                return AjaxResult.error("登录失败,您的账号已被冻结!");
            }
        }else{
            // todo 验证码校验
            tUser1 = new TUser();
            // 注册
            tUser1.setName(phone);
            tUser1.setAccount(phone);
            tUser1.setState(1);
            tUser1.setInsertTime(new Date());
            tUser1.setCreateTime(new Date());
            tUser1.setPhone(phone);
            userService.save(tUser1);
        }
        LoginUserParent loginUserParent = new LoginUserParent();
        loginUserParent.setName(tUser1.getName());
        loginUserParent.setUserid(tUser1.getId());
        loginUserParent.setPhone(tUser1.getPhone());
        loginUserParent.setLoginTime(new Date().getTime());
        HashMap<String, Object> map = new HashMap<>();
        map.put("token",tokenService.createToken1(loginUserParent));
        // 获取登录token
        return AjaxResult.success(map);
    }
    @PostMapping("/deleteUser")
    @ApiOperation(value = "注销当前帐号", tags = {"家长端-个人中心"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
    })
    public AjaxResult deleteUser() {
        if (tokenService.getLoginUser1() == null){
           return AjaxResult.tokenError("登录失效");
        }
        Integer userid = tokenService.getLoginUser1().getUserid();
        TUser tUser = userService.getById(userid);
        tUser.setState(3);
        userService.updateById(tUser);
        userService.removeById(tUser);
        return AjaxResult.success("注销成功");
    }
    @PostMapping("/logout")
    @ApiOperation(value = "退出登录", tags = {"家长端-个人中心"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
    })
    public AjaxResult logout(HttpServletRequest request) {
        if (tokenService.getLoginUser1() == null){
            return AjaxResult.tokenError("登录失效");
        }
        String token = SecurityUtils.getToken(request);
        if (com.ruoyi.common.core.utils.StringUtils.isNotEmpty(token))
        {
            // 删除用户缓存记录
            AuthUtil.logoutByToken1(token);
        }
        // todo 清除token
        return AjaxResult.success("退出登录成功");
    }
    @PostMapping("/updateUserInfo")
    @ApiOperation(value = "修改个人资料", tags = {"家长端-个人中心"})
    @ApiImplicitParams({
@@ -284,9 +398,13 @@
            @ApiImplicitParam(name = "headImg", value = "头像 改什么就只传什么"),
    })
    public AjaxResult updateUserInfo(String name, String phone,String headImg) {
        if (tokenService.getLoginUser1() == null){
            return AjaxResult.tokenError("登录失效",new Object());
        }
        // todo 获取用户id
        Long userid = tokenService.getLoginUser().getUserid();
        Integer userid = tokenService.getLoginUser1().getUserid();
        TUser byId = userService.getById(userid);
        if (StringUtils.hasLength(name)){
            byId.setName(name);
        }
@@ -295,9 +413,16 @@
//            if (byId == null){
//                return AjaxResult.tokenError("登录失效");
//            }
            if (phone.equals(byId.getPhone())){
                return AjaxResult.error("更换的手机号不能和原手机号相同");
            }
            List<TUser> list = userService.list(new QueryWrapper<TUser>()
                    .eq("phone", phone)
                    .ne("state", 3));
            if (list.size() > 0){
                return AjaxResult.error("更换的手机号已被使用",new Object());
            }
            byId.setPhone(phone);
        }
        if (StringUtils.hasLength(headImg)){