| | |
| | | |
| | | import com.alipay.api.AlipayApiException; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.common.core.constant.RedisConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.GlobalException; |
| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | |
| | | @Autowired |
| | | private PayMoneyUtil payMoneyUtil; |
| | | |
| | | @PostMapping("/pay") |
| | | @ApiOperation(value = "购买会员支付操作", tags = {"家长端-个人中心"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"), |
| | | @ApiImplicitParam(name = "payType", value = "支付类型 1=微信 2=支付宝", required = true), |
| | | @ApiImplicitParam(name = "orderId", value = "订单id", required = true), |
| | | @ApiImplicitParam(name = "id", value = "会员规格id", required = true), |
| | | |
| | | }) |
| | | public AjaxResult pay(Integer payType, Integer orderId, Integer id) throws Exception { |
| | | TVipOrder tVipOrder = vipOrderService.getById(orderId); |
| | | switch (payType) { |
| | | public AjaxResult pay(@RequestBody PayDTO dto) throws Exception { |
| | | TVipOrder tVipOrder = vipOrderService.getById(dto.getOrderId()); |
| | | switch (dto.getPayType()) { |
| | | case 1: |
| | | return payMoneyUtil.weixinpay |
| | | ("购买会员", "", |
| | | id + "_" + tVipOrder.getId() + "_" + |
| | | dto.getId() + "_" + tVipOrder.getId() + "_" + |
| | | UUIDUtil.getRandomCode(8), |
| | | tVipOrder.getMoney().toString(), |
| | | "/base/wxPayBuyVip", "APP", ""); |
| | | "/base/user/wxPayBuyVip", "APP", ""); |
| | | case 2: |
| | | return payMoneyUtil.alipay |
| | | ("购买会员", |
| | | "购买会员下单支付", |
| | | "", |
| | | id + "_" + tVipOrder.getId() + "_" + |
| | | dto.getId() + "_" + tVipOrder.getId() + "_" + |
| | | UUIDUtil.getRandomCode(8), |
| | | tVipOrder.getMoney().toString(), |
| | | "/base/aliPayBuyVip"); |
| | | "/base/user/aliPayBuyVip"); |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | @PostMapping("/order") |
| | | @ApiOperation(value = "购买会员下单操作", tags = {"家长端-个人中心"}) |
| | | @ApiImplicitParams({ |
| | |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/aliPayBuyVip") |
| | | @PostMapping("/aliPayBuyVip") |
| | | public void addVipPaymentAliCallback(HttpServletRequest request, HttpServletResponse response) { |
| | | try { |
| | | Map<String, String> map = payMoneyUtil.alipayCallback(request); |
| | |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/wxPayBuyVip") |
| | | @PostMapping("/wxPayBuyVip") |
| | | public void wxPayBuyPackage(HttpServletRequest request, HttpServletResponse response) { |
| | | try { |
| | | Map<String, String> map = payMoneyUtil.weixinpayCallback(request); |
| | |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @PostMapping("/getUserInfoParent") |
| | | @ApiOperation(value = "获取用户信息", tags = {"家长端-获取用户信息"}) |
| | | public R<TUser> getUserInfo() { |
| | | LoginUserParent loginUser1 = tokenService.getLoginUser1(); |
| | | if (loginUser1!=null){ |
| | | if (loginUser1 != null) { |
| | | TUser byId = userService.getById(loginUser1.getUserid()); |
| | | if (byId.getVipEndTime() == null){ |
| | | if (byId.getVipEndTime() == null) { |
| | | byId.setIsVip(0); |
| | | }else if (byId.getVipEndTime().after(new Date())){ |
| | | } else if (byId.getVipEndTime().after(new Date())) { |
| | | byId.setIsVip(1); |
| | | }else{ |
| | | } else { |
| | | byId.setIsVip(0); |
| | | } |
| | | return R.ok(byId); |
| | | }else{ |
| | | } else { |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | } |
| | | |
| | | @PostMapping("/parentPage") |
| | | @ApiOperation(value = "平板", tags = {"启动页"}) |
| | | public R<String> parentPage() { |
| | |
| | | @ApiOperation(value = "使用指南", tags = {"家长端-使用指南"}) |
| | | public R<PageInfo<TUseGuide>> useGuide(@RequestBody UseGuideQuery query) { |
| | | PageInfo<TUseGuide> data = managementClient.useGuide1(query).getData(); |
| | | for (TUseGuide record : data.getRecords()) { |
| | | String plainTextContent = record.getAnswer().replaceAll("\\<.*?\\>", ""); |
| | | record.setCount(plainTextContent); |
| | | } |
| | | return R.ok(data); |
| | | } |
| | | |
| | | @PostMapping("/useGuideGetInfo") |
| | | @ApiOperation(value = "查看详情", tags = {"家长端-使用指南"}) |
| | | public R useGuideGetInfo(Integer id) { |
| | | UseGuideQuery useGuideQuery = new UseGuideQuery(); |
| | | useGuideQuery.setPageNumber(1); |
| | | useGuideQuery.setPageSize(300); |
| | | PageInfo<TUseGuide> data = managementClient.useGuide1(useGuideQuery).getData(); |
| | | for (TUseGuide record : data.getRecords()) { |
| | | if (record.getId() == id) { |
| | | return R.ok(record.getAnswer()); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @PostMapping("/feedBack") |
| | |
| | | .eq("phone", phone)); |
| | | if (tUser1 != null) { |
| | | if (tUser1.getState() == 2) { |
| | | throw new GlobalException("登录失败,您的账号已被冻结!"); |
| | | return R.freeze("登录失败,您的账号已被冻结!"); |
| | | } |
| | | } else { |
| | | // 手机验证码校验 |
| | | if (!phoneCode.equals("123456")){ |
| | | Object redisPhoneCode = redisService.getCacheObject(RedisConstants.PHONE_CODE + phone); |
| | | if (!phoneCode.equals("123456")) { |
| | | Object redisPhoneCode = redisService.getCacheObject(RedisConstants.PHONE_CODE + phone); |
| | | if (null == redisPhoneCode) { |
| | | throw new GlobalException("登录失败,手机验证码已过期!"); |
| | | return R.errorCode("登录失败,手机验证码无效!"); |
| | | } else { |
| | | // redis 验证码的value 为 code:时间戳 |
| | | String rCodeAndTime = String.valueOf(redisPhoneCode); |
| | | String rCode = rCodeAndTime.split(":")[0]; |
| | | if (!rCode.equalsIgnoreCase(phoneCode)) { |
| | | throw new GlobalException("登录失败,手机验证码输入有误!"); |
| | | return R.errorCode("登录失败,手机验证码无效!"); |
| | | } else { |
| | | tUser1 = getUser(phone); |
| | | userService.save(tUser1); |
| | | } |
| | | } |
| | | }else{ |
| | | } else { |
| | | tUser1 = getUser(phone); |
| | | userService.save(tUser1); |
| | | } |
| | |
| | | loginUserParent.setName(tUser1.getName()); |
| | | loginUserParent.setUserid(tUser1.getId()); |
| | | loginUserParent.setPhone(tUser1.getPhone()); |
| | | loginUserParent.setLoginTime(new Date().getTime()); |
| | | loginUserParent.setLoginTime(System.currentTimeMillis()); |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("token", tokenService.createToken1(loginUserParent)); |
| | | // 获取登录token |
| | | map.put("token", tokenService.createToken1(loginUserParent)); |
| | | // 学习进度检查 |
| | | TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, tUser1.getId()) |
| | | .eq(TUserStudy::getDisabled, 0).one(); |
| | | if (null == userStudy) { |
| | | TUserStudy study = new TUserStudy(); |
| | | study.setUserId(tUser1.getId()); |
| | | // 学习周目 |
| | | TStudy tStudy = studyService.lambdaQuery().eq(TStudy::getQuarter, Constants.ONE) |
| | | .orderByAsc(TStudy::getWeek).last("limit 1").one(); |
| | | study.setWeek(tStudy.getWeek()); |
| | | study.setDay(Constants.ONE); |
| | | study.setTotalStudy(Constants.ZERO); |
| | | study.setTodayStudy(Constants.ZERO); |
| | | study.setWeekStudy(Constants.ZERO); |
| | | study.setMonthStudy(Constants.ZERO); |
| | | study.setListen(Constants.BURDEN_ONE); |
| | | study.setLook(Constants.BURDEN_ONE); |
| | | study.setInduction(Constants.BURDEN_ONE); |
| | | study.setAnswer(Constants.BURDEN_ONE); |
| | | study.setPair(Constants.BURDEN_ONE); |
| | | userStudyService.save(study); |
| | | } |
| | | return R.ok(map); |
| | | } |
| | | |
| | |
| | | public R<Map<String, Object>> studyLogin(@RequestBody RegisterPhoneRequest phoneRequest) { |
| | | String phone = phoneRequest.getPhone(); |
| | | String phoneCode = phoneRequest.getPhoneCode(); |
| | | 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("登录失败,验证码无效!"); |
| | | } |
| | | } |
| | | } |
| | | // 获取手机号所注册用户信息 |
| | | TUser user = userService.getOne(new QueryWrapper<TUser>() |
| | | .ne("state", 3) |
| | | .eq("phone", phone)); |
| | |
| | | return R.freeze("登录失败,您的账号已被冻结!"); |
| | | } |
| | | } else { |
| | | if (!phoneCode.equals("123456")) { |
| | | // 手机验证码校验 |
| | | 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("登录失败,验证码无效!"); |
| | | } else { |
| | | user = getUser(phone); |
| | | userService.save(user); |
| | | } |
| | | } |
| | | }else{ |
| | | user = getUser(phone); |
| | | userService.save(user); |
| | | } |
| | | user = getUser(phone); |
| | | userService.save(user); |
| | | } |
| | | // 生成登录用户信息 |
| | | LoginUserParent loginUserParent = new LoginUserParent(); |
| | |
| | | loginUserParent.setPhone(user.getPhone()); |
| | | loginUserParent.setLoginTime(System.currentTimeMillis()); |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("token", tokenService.createTokenStudy(loginUserParent)); |
| | | // 获取登录token |
| | | map.put("token", tokenService.createTokenStudy(loginUserParent)); |
| | | return R.ok(map); |
| | | } |
| | | |
| | | /** |
| | | * 学生端退出登录 |
| | | * |
| | | * @param request 请求信息 |
| | | */ |
| | | @PostMapping("/logoutStudy") |
| | |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "手机号", name = "phone", dataType = "string", required = true), |
| | | }) |
| | | public R<?> sendPhoneCode(@RequestParam String phone) { |
| | | public R<?> sendPhoneCode(@RequestParam String phone) throws Exception { |
| | | return userService.phoneCode(phone) ? R.ok() : R.fail(); |
| | | } |
| | | |
| | |
| | | public R<TSysSet> shareInfo() { |
| | | // 分享信息 |
| | | TSysSet data = managementClient.shareInfo().getData(); |
| | | if (tokenService.getLoginUserStudy() == null){ |
| | | if (tokenService.getLoginUserStudy() == null) { |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Integer userid = tokenService.getLoginUserStudy().getUserid(); |
| | |
| | | public R<TSysSet> shareInfoParent() { |
| | | // 分享信息 |
| | | TSysSet data = managementClient.shareInfo().getData(); |
| | | if (tokenService.getLoginUser1() == null){ |
| | | if (tokenService.getLoginUser1() == null) { |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Integer userid = tokenService.getLoginUser1().getUserid(); |
| | |
| | | } |
| | | return R.ok(data); |
| | | } |
| | | |
| | | /** |
| | | * 获取用户信息 |
| | | * |
| | |
| | | */ |
| | | @GetMapping("/userInfo") |
| | | @ApiOperation(value = "用户详情", tags = {"学习端-用户详情"}) |
| | | public R<TUser> userInfo() { |
| | | public R<UserPersonalCenterVO> userInfo() { |
| | | 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)); |
| | | } |
| | | |
| | | return R.ok(userService.lambdaQuery().eq(TUser::getId, tokenService.getLoginUserStudy().getUserid()).one()); |
| | | @GetMapping("/userInfoParent") |
| | | @ApiOperation(value = "用户详情", tags = {"家长端-用户详情"}) |
| | | public R<TUser> userInfoParent() { |
| | | LoginUserParent loginUserStudy = tokenService.getLoginUser1(); |
| | | if (null == loginUserStudy) { |
| | | return R.tokenError("登录失效!"); |
| | | } |
| | | TUser byId = userService.getById(loginUserStudy.getUserid()); |
| | | return R.ok(byId); |
| | | } |
| | | |
| | | @PostMapping("/deleteUser") |
| | |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"), |
| | | }) |
| | | public R<String> logout(HttpServletRequest request) { |
| | | if (tokenService.getLoginUser1() == null){ |
| | | if (tokenService.getLoginUser1() == null) { |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | String token = SecurityUtils.getToken(request); |
| | |
| | | @ApiImplicitParam(name = "headImg", value = "头像 改什么就只传什么"), |
| | | @ApiImplicitParam(name = "phoneCode", value = "手机验证码,修改手机号的时候传"), |
| | | }) |
| | | public R<String> updateUserInfo(String name, String phone, String headImg,String phoneCode) { |
| | | if (tokenService.getLoginUser1() == null){ |
| | | public R<String> updateUserInfo(String name, String phone, String headImg, String phoneCode) { |
| | | if (tokenService.getLoginUser1() == null) { |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Integer userid = tokenService.getLoginUser1().getUserid(); |
| | |
| | | byId.setPhone(phone); |
| | | } |
| | | // 手机验证码校验 |
| | | if (!phoneCode.equals("123456")){ |
| | | 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)) { |
| | | if (StringUtils.hasLength(phoneCode)) { |
| | | if (!phoneCode.equals("123456")) { |
| | | 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("手机验证码无效"); |
| | | } |
| | | } |
| | | } |
| | | } |