From f0cb2ed0aed012ae08fd957338650d91c3cc1d14 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期一, 17 六月 2024 11:43:16 +0800
Subject: [PATCH] 修改
---
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TUserController.java | 496 +++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 375 insertions(+), 121 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..52685cf 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
@@ -5,6 +5,7 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.constant.RedisConstants;
import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.exception.GlobalException;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.redis.service.RedisService;
@@ -12,18 +13,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.*;
@@ -33,7 +29,6 @@
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;
@@ -65,12 +60,21 @@
private TokenService tokenService;
@Resource
private RedisService redisService;
+ @Resource
+ private ITUserShareService userShareService;
+
+ @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("/vipInfo")
@ApiOperation(value = "会员中心-获取会员说明、当前登录用户是否为会员、会员购买规格", tags = {"家长端-个人中心"})
- public AjaxResult<List<VipInfoVO>> vipInfo() {
+ public R<List<VipInfoVO>> vipInfo() {
if (tokenService.getLoginUser1() == null) {
- return AjaxResult.tokenError("登录失效", new Object());
+ throw new GlobalException("登录失效!");
}
List<VipInfoVO> vipInfoVOS = new ArrayList<>();
List<TVipSet> data = managementClient.getVipSet1().getData();
@@ -95,11 +99,40 @@
vipInfoVO.setAmount(datum.getAmount());
vipInfoVOS.add(vipInfoVO);
}
- return AjaxResult.ok(vipInfoVOS);
+ return R.ok(vipInfoVOS);
}
@Autowired
private PayMoneyUtil payMoneyUtil;
+
+ @PostMapping("/pay")
+ @ApiOperation(value = "购买会员支付操作", tags = {"家长端-个人中心"})
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
+
+ })
+ public AjaxResult pay(@RequestBody PayDTO dto) throws Exception {
+ TVipOrder tVipOrder = vipOrderService.getById(dto.getOrderId());
+ switch (dto.getPayType()) {
+ case 1:
+ return payMoneyUtil.weixinpay
+ ("购买会员", "",
+ dto.getId() + "_" + tVipOrder.getId() + "_" +
+ UUIDUtil.getRandomCode(8),
+ tVipOrder.getMoney().toString(),
+ "/base/user/wxPayBuyVip", "APP", "");
+ case 2:
+ return payMoneyUtil.alipay
+ ("购买会员",
+ "购买会员下单支付",
+ "",
+ dto.getId() + "_" + tVipOrder.getId() + "_" +
+ UUIDUtil.getRandomCode(8),
+ tVipOrder.getMoney().toString(),
+ "/base/user/aliPayBuyVip");
+ }
+ return AjaxResult.success();
+ }
@PostMapping("/order")
@ApiOperation(value = "购买会员下单操作", tags = {"家长端-个人中心"})
@@ -108,9 +141,9 @@
@ApiImplicitParam(name = "payType", value = "支付类型 1=微信 2=支付宝", required = true),
@ApiImplicitParam(name = "id", value = "会员规格id", required = true),
})
- public AjaxResult order(Integer payType, Integer id) throws Exception {
+ public R<PayVO> order(Integer payType, Integer id) throws Exception {
if (tokenService.getLoginUser1() == null) {
- return AjaxResult.tokenError("登录失效", new Object());
+ return R.tokenError("登录失效");
}
Integer userid = tokenService.getLoginUser1().getUserid();
TVipOrder tVipOrder = new TVipOrder();
@@ -126,29 +159,36 @@
tVipOrder.setUserId(userid);
tVipOrder.setPayType(payType);
tVipOrder.setCount(time);
- switch (payType) {
- case 1:
- return payMoneyUtil.weixinpay
- ("购买会员", "",
- id + "_" + tVipOrder.getId() + "_" +
- UUIDUtil.getRandomCode(8),
- tVipOrder.getMoney().toString(),
- "/base/wxPayBuyVip", "APP", "");
- case 2:
- return payMoneyUtil.alipay
- ("购买会员",
- "购买会员下单支付",
- "",
- id + "_" + tVipOrder.getId() + "_" +
- UUIDUtil.getRandomCode(8),
- tVipOrder.getMoney().toString(),
- "/base/aliPayBuyVip");
- }
- return AjaxResult.success();
+ vipOrderService.save(tVipOrder);
+ PayVO payVO = new PayVO();
+ payVO.setOrderId(tVipOrder.getId());
+ payVO.setId(id);
+
+
+ return R.ok(payVO);
+// switch (payType) {
+// case 1:
+// return payMoneyUtil.weixinpay
+// ("购买会员", "",
+// id + "_" + tVipOrder.getId() + "_" +
+// UUIDUtil.getRandomCode(8),
+// tVipOrder.getMoney().toString(),
+// "/base/wxPayBuyVip", "APP", "");
+// case 2:
+// return payMoneyUtil.alipay
+// ("购买会员",
+// "购买会员下单支付",
+// "",
+// id + "_" + tVipOrder.getId() + "_" +
+// UUIDUtil.getRandomCode(8),
+// tVipOrder.getMoney().toString(),
+// "/base/aliPayBuyVip");
+// }
+
}
@ResponseBody
- @PostMapping("/base/aliPayBuyVip")
+ @PostMapping("/aliPayBuyVip")
public void addVipPaymentAliCallback(HttpServletRequest request, HttpServletResponse response) {
try {
Map<String, String> map = payMoneyUtil.alipayCallback(request);
@@ -182,8 +222,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 +235,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 +245,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);
}
@@ -219,7 +269,7 @@
}
@ResponseBody
- @PostMapping("/base/wxPayBuyVip")
+ @PostMapping("/wxPayBuyVip")
public void wxPayBuyPackage(HttpServletRequest request, HttpServletResponse response) {
try {
Map<String, String> map = payMoneyUtil.weixinpayCallback(request);
@@ -256,6 +306,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 +318,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 +328,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);
}
@@ -292,64 +351,104 @@
@PostMapping("/getPage")
@ApiOperation(value = "获取注意事项", tags = {"家长端-注意事项"})
- public AjaxResult<String> getPage() {
+ public R<String> getPage() {
List<TPage> data = managementClient.getPage1().getData();
for (TPage datum : data) {
if (datum.getType() == 4) {
- return AjaxResult.success(datum.getImg());
+ return R.ok(datum.getImg());
}
}
- return AjaxResult.success();
+ return R.ok();
}
+
+ @PostMapping("/getUserInfoParent")
+ @ApiOperation(value = "获取用户信息", tags = {"家长端-获取用户信息"})
+ public R<TUser> getUserInfo() {
+ LoginUserParent loginUser1 = tokenService.getLoginUser1();
+ if (loginUser1 != null) {
+ TUser byId = userService.getById(loginUser1.getUserid());
+ if (byId.getVipEndTime() == null) {
+ byId.setIsVip(0);
+ } else if (byId.getVipEndTime().after(new Date())) {
+ byId.setIsVip(1);
+ } else {
+ byId.setIsVip(0);
+ }
+ return R.ok(byId);
+ } else {
+ return R.tokenError("登录失效");
+ }
+ }
+
@PostMapping("/parentPage")
- @ApiOperation(value = "平板", tags = {"家长端-启动页"})
- public AjaxResult<String> parentPage() {
+ @ApiOperation(value = "平板", tags = {"启动页"})
+ public R<String> parentPage() {
List<TPage> data = managementClient.getPage1().getData();
for (TPage datum : data) {
if (datum.getType() == 3) {
- return AjaxResult.success(datum.getImg());
+ return R.ok(datum.getImg());
}
}
- return AjaxResult.success();
+ return R.ok();
}
+
@PostMapping("/parentPage1")
- @ApiOperation(value = "手机", tags = {"家长端-启动页"})
- public AjaxResult<String> parentPage1() {
+ @ApiOperation(value = "手机", tags = {"启动页"})
+ public R<String> parentPage1() {
List<TPage> data = managementClient.getPage1().getData();
for (TPage datum : data) {
if (datum.getType() == 2) {
- return AjaxResult.success(datum.getImg());
+ return R.ok(datum.getImg());
}
}
- return AjaxResult.success();
+ return R.ok();
}
+
@PostMapping("/getProtocol")
- @ApiOperation(value = "获取协议", tags = {"家长端-协议"})
+ @ApiOperation(value = "获取协议", tags = {"协议"})
@ApiImplicitParams({
@ApiImplicitParam(value = "类型 1用户 2隐私 3注销", name = "type", dataType = "string", required = true),
})
- public AjaxResult<String> getProtocol(Integer type) {
+ public R<String> getProtocol(Integer type) {
String data = managementClient.agreement1(type).getData();
- return AjaxResult.success(data);
+ return R.ok(data);
}
@PostMapping("/useGuide")
@ApiOperation(value = "使用指南", tags = {"家长端-使用指南"})
- public AjaxResult<PageInfo<TUseGuide>> useGuide(@RequestBody UseGuideQuery query) {
+ public R<PageInfo<TUseGuide>> useGuide(@RequestBody UseGuideQuery query) {
PageInfo<TUseGuide> data = managementClient.useGuide1(query).getData();
- return AjaxResult.success(data);
+ 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")
@ApiOperation(value = "反馈", tags = {"家长端-意见反馈"})
- public AjaxResult feedBack(@RequestBody TFeedback dto) {
+ public R<String> feedBack(@RequestBody TFeedback dto) {
if (tokenService.getLoginUser1() == null) {
- return AjaxResult.tokenError("登录失效", new Object());
+ return R.tokenError("登录失效");
}
LoginUserParent loginUser1 = tokenService.getLoginUser1();
dto.setUserId(loginUser1.getUserid());
managementClient.addFeedBack(dto);
- return AjaxResult.success("反馈成功");
+ return R.ok("反馈成功");
}
@PostMapping("/parentLogin")
@@ -358,18 +457,35 @@
@ApiImplicitParam(value = "手机号", name = "phone", dataType = "string", required = true),
@ApiImplicitParam(value = "验证码", name = "phoneCode", dataType = "string", required = true)
})
- public AjaxResult login(String phone, String phoneCode) {
+ public R<Map<String, Object>> 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("登录失败,您的账号已被冻结!");
+ return R.freeze("登录失败,您的账号已被冻结!");
}
} else {
- // todo 验证码校验
- tUser1 = getUser(phone);
- userService.save(tUser1);
+ // 手机验证码校验
+ 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 {
+ tUser1 = getUser(phone);
+ userService.save(tUser1);
+ }
+ }
+ } else {
+ tUser1 = getUser(phone);
+ userService.save(tUser1);
+ }
}
LoginUserParent loginUserParent = new LoginUserParent();
loginUserParent.setName(tUser1.getName());
@@ -379,7 +495,7 @@
HashMap<String, Object> map = new HashMap<>();
map.put("token", tokenService.createToken1(loginUserParent));
// 获取登录token
- return AjaxResult.success(map);
+ return R.ok(map);
}
/**
@@ -389,7 +505,7 @@
*/
@PostMapping("/studyLogin")
@ApiOperation(value = "学习端-登录", tags = {"学习端-登录"})
- public AjaxResult studyLogin(@RequestBody @Validated RegisterPhoneRequest phoneRequest) {
+ public R<Map<String, Object>> studyLogin(@RequestBody RegisterPhoneRequest phoneRequest) {
String phone = phoneRequest.getPhone();
String phoneCode = phoneRequest.getPhoneCode();
TUser user = userService.getOne(new QueryWrapper<TUser>()
@@ -397,23 +513,28 @@
.eq("phone", phone));
if (user != null) {
if (user.getState() == 2) {
- return AjaxResult.error("登录失败,您的账号已被冻结!");
+ return R.freeze("登录失败,您的账号已被冻结!");
}
} else {
- // 手机验证码校验
- 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("登录失败,手机验证码输入有误!");
+ if (!phoneCode.equals("123456")) {
+ // 手机验证码校验
+ Object redisPhoneCode = redisService.getCacheObject(RedisConstants.PHONE_CODE + phone);
+ if (null == redisPhoneCode) {
+ return R.errorCode("登录失败,验证码无效!");
} else {
- user = getUser(phone);
- userService.save(user);
+ // 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);
}
}
// 生成登录用户信息
@@ -425,7 +546,30 @@
HashMap<String, Object> map = new HashMap<>();
map.put("token", tokenService.createTokenStudy(loginUserParent));
// 获取登录token
- return AjaxResult.success(map);
+ return R.ok(map);
+ }
+
+ /**
+ * 学生端退出登录
+ *
+ * @param request 请求信息
+ */
+ @PostMapping("/logoutStudy")
+ @ApiOperation(value = "退出登录", tags = {"学习端-个人中心"})
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
+ })
+ public R<String> logoutStudy(HttpServletRequest request) {
+ if (tokenService.getLoginUserStudy() == null) {
+ return R.tokenError("登录失效!");
+ }
+ String token = SecurityUtils.getToken(request);
+ if (null != token) {
+ // 删除用户缓存记录
+ AuthUtil.logoutByTokenStudy(token);
+ }
+ // todo 清除token
+ return R.ok("退出登录成功!");
}
private TUser getUser(String phone) {
@@ -450,22 +594,79 @@
@ApiImplicitParams({
@ApiImplicitParam(value = "手机号", name = "phone", dataType = "string", required = true),
})
- public AjaxResult sendPhoneCode(@RequestParam String phone) {
- return userService.phoneCode(phone) ? AjaxResult.success() : AjaxResult.error();
+ public R<?> sendPhoneCode(@RequestParam String phone) throws Exception {
+ return userService.phoneCode(phone) ? R.ok() : R.fail();
}
/**
- * 家长端 学习端都可用
- *
- * @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 R<TSysSet> shareInfo() {
+ // 分享信息
+ TSysSet data = managementClient.shareInfo().getData();
+ if (tokenService.getLoginUserStudy() == null) {
+ return R.tokenError("登录失效");
+ }
+ 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 R.ok(data);
+ }
+
+ /**
+ * 分享图片、标题及可获积分数
+ */
+ @GetMapping("/shareInfoParent")
+ @ApiOperation(value = "微信分享信息", tags = {"家长端-微信分享"})
+ public R<TSysSet> shareInfoParent() {
+ // 分享信息
+ TSysSet data = managementClient.shareInfo().getData();
+ if (tokenService.getLoginUser1() == null) {
+ return R.tokenError("登录失效");
+ }
+ Integer userid = tokenService.getLoginUser1().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 R.ok(data);
+ }
+
+ /**
+ * 获取用户信息
+ *
+ * @return 用户信息
+ */
+ @GetMapping("/userInfo")
+ @ApiOperation(value = "用户详情", tags = {"学习端-用户详情"})
+ public R<UserPersonalCenterVO> userInfo() {
+ TUser user = userService.lambdaQuery().eq(TUser::getId, tokenService.getLoginUserStudy().getUserid()).one();
+ TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, user.getId()).eq(TUserStudy::getDisabled, 0).one();
+ return R.ok(new UserPersonalCenterVO(user, userStudy));
}
@PostMapping("/deleteUser")
@@ -473,18 +674,16 @@
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
})
- public AjaxResult deleteUser() {
+ public R<String> deleteUser() {
if (tokenService.getLoginUser1() == null) {
- return AjaxResult.tokenError("登录失效");
+ return R.tokenError("登录失效");
}
Integer userid = tokenService.getLoginUser1().getUserid();
TUser tUser = userService.getById(userid);
-
tUser.setState(3);
userService.updateById(tUser);
-
userService.removeById(tUser);
- return AjaxResult.success("注销成功");
+ return R.ok("注销成功");
}
@PostMapping("/logout")
@@ -492,9 +691,9 @@
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"),
})
- public AjaxResult logout(HttpServletRequest request) {
+ public R<String> logout(HttpServletRequest request) {
if (tokenService.getLoginUser1() == null) {
- return AjaxResult.tokenError("登录失效");
+ return R.tokenError("登录失效");
}
String token = SecurityUtils.getToken(request);
if (com.ruoyi.common.core.utils.StringUtils.isNotEmpty(token)) {
@@ -502,7 +701,7 @@
AuthUtil.logoutByToken1(token);
}
// todo 清除token
- return AjaxResult.success("退出登录成功");
+ return R.ok("退出登录成功");
}
@PostMapping("/updateUserInfo")
@@ -512,9 +711,12 @@
@ApiImplicitParam(name = "name", value = "姓名 改什么就只传什么"),
@ApiImplicitParam(name = "phone", value = "电话 改什么就只传什么"),
@ApiImplicitParam(name = "headImg", value = "头像 改什么就只传什么"),
+ @ApiImplicitParam(name = "phoneCode", value = "手机验证码,修改手机号的时候传"),
})
- public AjaxResult updateUserInfo(String name, String phone, String headImg) {
- // todo 获取用户id
+ public R<String> updateUserInfo(String name, String phone, String headImg, String phoneCode) {
+ if (tokenService.getLoginUser1() == null) {
+ return R.tokenError("登录失效");
+ }
Integer userid = tokenService.getLoginUser1().getUserid();
TUser byId = userService.getById(userid);
@@ -522,28 +724,40 @@
byId.setName(name);
}
if (StringUtils.hasLength(phone)) {
- // 先判断手机号是否和当前用户手机号一致
-// if (byId == null){
-// return AjaxResult.tokenError("登录失效");
-// }
-
if (phone.equals(byId.getPhone())) {
- return AjaxResult.error("更换的手机号不能和原手机号相同");
+ return R.fail("更换的手机号不能和原手机号相同!");
}
List<TUser> list = userService.list(new QueryWrapper<TUser>()
.eq("phone", phone)
.ne("state", 3));
if (list.size() > 0) {
- return AjaxResult.error("更换的手机号已被使用", new Object());
+ return R.fail("更换的手机号已被使用!");
}
byId.setPhone(phone);
+ }
+ // 手机验证码校验
+ 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("手机验证码无效");
+ }
+ }
+ }
}
if (StringUtils.hasLength(headImg)) {
byId.setHeadImg(headImg);
}
userService.saveOrUpdate(byId);
- return AjaxResult.success("修改成功");
+ return R.ok("修改成功");
}
+
@ResponseBody
@PostMapping("/base/wxRefund")
public void cancelMySiteCallback(HttpServletRequest request, HttpServletResponse response) {
@@ -566,12 +780,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 +802,7 @@
e.printStackTrace();
}
}
+
@PostMapping("/vipBack/{id}")
@ApiOperation(value = "会员退款", tags = {"管理后台-会员退款"})
public R vipBack(@PathVariable("id") Integer id) throws AlipayApiException {
@@ -596,7 +811,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 +822,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 +851,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);
// 将会员到期时间回退到上一次
@@ -673,6 +889,13 @@
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 +927,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