|  |  |  | 
|---|
|  |  |  | package com.ruoyi.study.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.auth0.jwt.JWT; | 
|---|
|  |  |  | import com.auth0.jwt.algorithms.Algorithm; | 
|---|
|  |  |  | import com.auth0.jwt.exceptions.SignatureVerificationException; | 
|---|
|  |  |  | import com.auth0.jwt.interfaces.DecodedJWT; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.alipay.api.AlipayApiException; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.ruoyi.common.core.constant.Constants; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.ruoyi.common.security.auth.AuthUtil; | 
|---|
|  |  |  | import com.ruoyi.common.security.service.TokenService; | 
|---|
|  |  |  | import com.ruoyi.common.security.utils.SecurityUtils; | 
|---|
|  |  |  | import com.ruoyi.goods.api.model.OrderQuery; | 
|---|
|  |  |  | import com.ruoyi.management.api.feignClient.ManagementClient; | 
|---|
|  |  |  | import com.ruoyi.management.api.model.*; | 
|---|
|  |  |  | import com.ruoyi.management.api.query.UseGuideQuery; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | import java.io.BufferedReader; | 
|---|
|  |  |  | import java.io.ByteArrayInputStream; | 
|---|
|  |  |  | import java.io.PrintWriter; | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.security.PublicKey; | 
|---|
|  |  |  | import java.security.cert.CertificateException; | 
|---|
|  |  |  | import java.security.cert.CertificateFactory; | 
|---|
|  |  |  | import java.security.cert.X509Certificate; | 
|---|
|  |  |  | import java.security.interfaces.ECPublicKey; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @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("/listAll") | 
|---|
|  |  |  | public R<List<TUser>> listAll(@RequestBody OrderQuery query){ | 
|---|
|  |  |  | List<TUser> list = userService.lambdaQuery() | 
|---|
|  |  |  | .like(StringUtils.hasLength(query.getUserName()), TUser::getName, query.getUserName()) | 
|---|
|  |  |  | .like(StringUtils.hasLength(query.getPhone()), TUser::getPhone, query.getPhone()).list(); | 
|---|
|  |  |  | return R.ok(list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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") | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private PayMoneyUtil payMoneyUtil; | 
|---|
|  |  |  | public static JSONObject verifyAndGet(String jws) throws CertificateException { | 
|---|
|  |  |  | DecodedJWT decodedJWT = JWT.decode(jws); | 
|---|
|  |  |  | // 拿到 header 中 x5c 数组中第一个 | 
|---|
|  |  |  | String header = new String(java.util.Base64.getDecoder().decode(decodedJWT.getHeader())); | 
|---|
|  |  |  | String x5c = JSONObject.parseObject(header).getJSONArray("x5c").getString(0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取公钥 | 
|---|
|  |  |  | PublicKey publicKey = getPublicKeyByX5c(x5c); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 验证 token | 
|---|
|  |  |  | Algorithm algorithm = Algorithm.ECDSA256((ECPublicKey) publicKey, null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | algorithm.verify(decodedJWT); | 
|---|
|  |  |  | } catch (SignatureVerificationException e) { | 
|---|
|  |  |  | throw new RuntimeException("签名验证失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 解析数据 | 
|---|
|  |  |  | return JSONObject.parseObject(new String(java.util.Base64.getDecoder().decode(decodedJWT.getPayload()))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取公钥 | 
|---|
|  |  |  | * @param x5c | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | * @throws | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private static PublicKey getPublicKeyByX5c(String x5c) throws CertificateException { | 
|---|
|  |  |  | byte[] x5c0Bytes = java.util.Base64.getDecoder().decode(x5c); | 
|---|
|  |  |  | CertificateFactory fact = CertificateFactory.getInstance("X.509"); | 
|---|
|  |  |  | X509Certificate cer = (X509Certificate) fact.generateCertificate(new ByteArrayInputStream(x5c0Bytes)); | 
|---|
|  |  |  | return cer.getPublicKey(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @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()); | 
|---|
|  |  |  | 
|---|
|  |  |  | UUIDUtil.getRandomCode(8), | 
|---|
|  |  |  | tVipOrder.getMoney().toString(), | 
|---|
|  |  |  | "/base/user/aliPayBuyVip"); | 
|---|
|  |  |  | case 3: | 
|---|
|  |  |  | tVipOrder.setTransactionId(dto.getTransactionIdentifier()); | 
|---|
|  |  |  | vipOrderService.updateById(tVipOrder); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return AjaxResult.success(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @PostMapping("/queryOrderState") | 
|---|
|  |  |  | @ApiOperation(value = "苹果内购查询支付状态", tags = {"苹果内购查询支付状态"}) | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "orderId", value = "订单id", required = true) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public AjaxResult<Boolean> pay(Integer orderId) throws Exception { | 
|---|
|  |  |  | System.err.println("苹果orderId:"+orderId); | 
|---|
|  |  |  | TVipOrder byId = vipOrderService.getById(orderId); | 
|---|
|  |  |  | if (byId.getPayState() == 2){ | 
|---|
|  |  |  | return AjaxResult.success(true); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return AjaxResult.success(false); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/order") | 
|---|
|  |  |  | @ApiOperation(value = "购买会员下单操作", tags = {"家长端-个人中心"}) | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "payType", value = "支付类型 1=微信 2=支付宝", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(name = "id", value = "会员规格id", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(name = "payType", value = "支付类型 1=微信 2=支付宝 3=苹果内购", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(name = "id", value = "会员规格id", required = false), | 
|---|
|  |  |  | @ApiImplicitParam(name = "count", value = "购买会员月数--ios用", required = false), | 
|---|
|  |  |  | @ApiImplicitParam(name = "price", value = "价格--ios用", required = false), | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public R<PayVO> order(Integer payType, Integer id) throws Exception { | 
|---|
|  |  |  | public R<PayVO> order(Integer payType, Integer id,Integer count,BigDecimal price) throws Exception { | 
|---|
|  |  |  | if (tokenService.getLoginUser1() == null) { | 
|---|
|  |  |  | return R.tokenError("登录失效"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // todo price根据用户环境确定单位 可能为刀或欧等等 也许后续需要处理转换 存元 | 
|---|
|  |  |  | Integer userid = tokenService.getLoginUser1().getUserid(); | 
|---|
|  |  |  | TVipOrder tVipOrder = new TVipOrder(); | 
|---|
|  |  |  | List<TVipSet> data = managementClient.getVipSet1().getData(); | 
|---|
|  |  |  | if (price!=null){ | 
|---|
|  |  |  | id = null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer time = 0; | 
|---|
|  |  |  | for (TVipSet datum : data) { | 
|---|
|  |  |  | if (datum.getId() == id) { | 
|---|
|  |  |  | tVipOrder.setMoney(datum.getAmount()); | 
|---|
|  |  |  | time = datum.getTime(); | 
|---|
|  |  |  | if (id!=null){ | 
|---|
|  |  |  | for (TVipSet datum : data) { | 
|---|
|  |  |  | if (datum.getId() == id) { | 
|---|
|  |  |  | tVipOrder.setMoney(datum.getAmount()); | 
|---|
|  |  |  | time = datum.getTime(); | 
|---|
|  |  |  | tVipOrder.setCount(time); | 
|---|
|  |  |  | Calendar calendar = Calendar.getInstance(); | 
|---|
|  |  |  | calendar.setTime(new Date()); | 
|---|
|  |  |  | calendar.add(Calendar.MONTH, time); | 
|---|
|  |  |  | Date dateAfterOneMonth = calendar.getTime(); | 
|---|
|  |  |  | dateAfterOneMonth.setHours(23); | 
|---|
|  |  |  | dateAfterOneMonth.setMinutes(59); | 
|---|
|  |  |  | dateAfterOneMonth.setSeconds(59); | 
|---|
|  |  |  | tVipOrder.setTime(dateAfterOneMonth); | 
|---|
|  |  |  | tVipOrder.setCount(time); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | Calendar calendar = Calendar.getInstance(); | 
|---|
|  |  |  | calendar.setTime(new Date()); | 
|---|
|  |  |  | calendar.add(Calendar.MONTH, count); | 
|---|
|  |  |  | Date dateAfterOneMonth = calendar.getTime(); | 
|---|
|  |  |  | dateAfterOneMonth.setHours(23); | 
|---|
|  |  |  | dateAfterOneMonth.setMinutes(59); | 
|---|
|  |  |  | dateAfterOneMonth.setSeconds(59); | 
|---|
|  |  |  | tVipOrder.setTime(dateAfterOneMonth); | 
|---|
|  |  |  | tVipOrder.setCount(count); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | tVipOrder.setPayState(1); | 
|---|
|  |  |  | tVipOrder.setUserId(userid); | 
|---|
|  |  |  | tVipOrder.setPayType(payType); | 
|---|
|  |  |  | vipOrderService.save(tVipOrder); | 
|---|
|  |  |  | PayVO payVO = new PayVO(); | 
|---|
|  |  |  | payVO.setOrderId(tVipOrder.getId()); | 
|---|
|  |  |  | payVO.setId(id); | 
|---|
|  |  |  | return R.ok(payVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @PostMapping("/orderStudent") | 
|---|
|  |  |  | @ApiOperation(value = "学习端购买会员下单操作", tags = {"家长端-个人中心"}) | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "Authorization", value = "Bearer eyJhbGciOiJIUzUxMiJ....", required = true, paramType = "header"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "payType", value = "支付类型 1=微信 2=支付宝 3=苹果内购", required = true), | 
|---|
|  |  |  | @ApiImplicitParam(name = "id", value = "会员规格id", required = false), | 
|---|
|  |  |  | @ApiImplicitParam(name = "count", value = "购买会员月数--ios用", required = false), | 
|---|
|  |  |  | @ApiImplicitParam(name = "price", value = "价格--ios用", required = false), | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | public R<PayVO> orderStudent(Integer payType, Integer id,Integer count,BigDecimal price) throws Exception { | 
|---|
|  |  |  | if (tokenService.getLoginUserStudy() == null) { | 
|---|
|  |  |  | return R.tokenError("登录失效"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer userid = tokenService.getLoginUserStudy().getUserid(); | 
|---|
|  |  |  | TVipOrder tVipOrder = new TVipOrder(); | 
|---|
|  |  |  | List<TVipSet> data = managementClient.getVipSet1().getData(); | 
|---|
|  |  |  | Integer time = 0; | 
|---|
|  |  |  | if (id!=null){ | 
|---|
|  |  |  | for (TVipSet datum : data) { | 
|---|
|  |  |  | if (datum.getId() == id) { | 
|---|
|  |  |  | tVipOrder.setMoney(datum.getAmount()); | 
|---|
|  |  |  | time = datum.getTime(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | tVipOrder.setPayState(1); | 
|---|
|  |  |  | tVipOrder.setUserId(userid); | 
|---|
|  |  |  | tVipOrder.setPayType(payType); | 
|---|
|  |  |  | tVipOrder.setCount(time); | 
|---|
|  |  |  | if (count!=null){ | 
|---|
|  |  |  | tVipOrder.setCount(count); | 
|---|
|  |  |  | tVipOrder.setMoney(price); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | tVipOrder.setCount(time); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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("/testApple") | 
|---|
|  |  |  | public void testApple(HttpServletRequest request, HttpServletResponse response) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | System.err.println("请求"+request); | 
|---|
|  |  |  | BufferedReader reader = request.getReader(); | 
|---|
|  |  |  | String string1 = reader.toString(); | 
|---|
|  |  |  | System.err.println("请求reader"+string1); | 
|---|
|  |  |  | StringBuilder requestBody = new StringBuilder(); | 
|---|
|  |  |  | String line; | 
|---|
|  |  |  | while ((line = reader.readLine()) != null) { | 
|---|
|  |  |  | requestBody.append(line); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | System.err.println("全部请求体"+requestBody); | 
|---|
|  |  |  | org.json.JSONObject jsonObject1 = new org.json.JSONObject(requestBody.toString()); | 
|---|
|  |  |  | System.err.println("json串"+jsonObject1); | 
|---|
|  |  |  | String o = jsonObject1.getString("signedPayload"); | 
|---|
|  |  |  | JSONObject payload = verifyAndGet(o); | 
|---|
|  |  |  | String notificationType = payload.get("notificationType").toString(); | 
|---|
|  |  |  | JSONObject data = payload.getJSONObject("data"); | 
|---|
|  |  |  | String signedTransactionInfo = data.get("signedTransactionInfo").toString(); | 
|---|
|  |  |  | String environment = data.get("environment").toString(); | 
|---|
|  |  |  | JSONObject transactionInfo = verifyAndGet(signedTransactionInfo); | 
|---|
|  |  |  | String transactionId = transactionInfo.get("transactionId").toString(); | 
|---|
|  |  |  | String originalTransactionId = transactionInfo.get("originalTransactionId").toString(); | 
|---|
|  |  |  | String productId = transactionInfo.get("productId").toString(); | 
|---|
|  |  |  | System.err.println("json串"+transactionInfo); | 
|---|
|  |  |  | System.err.println("data"+data); | 
|---|
|  |  |  | // 苹果流水号 | 
|---|
|  |  |  | String string = transactionInfo.getString("originalTransactionId"); | 
|---|
|  |  |  | TVipOrder one = vipOrderService.getOne(new QueryWrapper<TVipOrder>() | 
|---|
|  |  |  | .eq("transactionId", string) | 
|---|
|  |  |  | .eq("payType", 3)); | 
|---|
|  |  |  | System.err.println("回调通知类型"+notificationType); | 
|---|
|  |  |  | if ("REFUND".equals(notificationType)){ | 
|---|
|  |  |  | if (one!=null && one.getPayState() == 2){ | 
|---|
|  |  |  | one.setPayState(3); | 
|---|
|  |  |  | one.setBackTime(new Date()); | 
|---|
|  |  |  | // 用户的vip剩余时间减少 | 
|---|
|  |  |  | Calendar calendar = Calendar.getInstance(); | 
|---|
|  |  |  | calendar.setTime(new Date()); | 
|---|
|  |  |  | calendar.add(Calendar.MONTH, -one.getCount()); | 
|---|
|  |  |  | Integer userId = one.getUserId(); | 
|---|
|  |  |  | TUser byId1 = userService.getById(userId); | 
|---|
|  |  |  | // 判断用户是不是第一次充值 | 
|---|
|  |  |  | List<TVipOrder> list = vipOrderService.list(new QueryWrapper<TVipOrder>() | 
|---|
|  |  |  | .eq("userId", userId) | 
|---|
|  |  |  | .ne("id",one.getId()) | 
|---|
|  |  |  | .eq("payState", 2) | 
|---|
|  |  |  | .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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | vipOrderService.updateById(one); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | if (one!=null){ | 
|---|
|  |  |  | one.setPayState(2); | 
|---|
|  |  |  | one.setPayTime(new Date()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | TUser byId1 = userService.getById(one.getUserId()); | 
|---|
|  |  |  | if (byId1.getVipPayTime() == null) { | 
|---|
|  |  |  | // 是否是首次充值会员 | 
|---|
|  |  |  | byId1.setVipPayTime(new Date()); | 
|---|
|  |  |  | Calendar calendar = Calendar.getInstance(); | 
|---|
|  |  |  | calendar.setTime(new Date()); | 
|---|
|  |  |  | calendar.add(Calendar.MONTH, one.getCount()); | 
|---|
|  |  |  | Date dateAfterOneMonth = calendar.getTime(); | 
|---|
|  |  |  | dateAfterOneMonth.setHours(23); | 
|---|
|  |  |  | dateAfterOneMonth.setMinutes(59); | 
|---|
|  |  |  | dateAfterOneMonth.setSeconds(59); | 
|---|
|  |  |  | byId1.setVipEndTime(dateAfterOneMonth); | 
|---|
|  |  |  | one.setTime(dateAfterOneMonth); | 
|---|
|  |  |  | userService.updateById(byId1); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 不是首次 判断vipEndTime 是否到期 如果没有 加指定月份时间 如果到期了 将会员到期时间从当前增加指定月份 | 
|---|
|  |  |  | if (byId1.getVipEndTime().getTime() < new Date().getTime()) { | 
|---|
|  |  |  | Calendar calendar = Calendar.getInstance(); | 
|---|
|  |  |  | calendar.setTime(new Date()); | 
|---|
|  |  |  | calendar.add(Calendar.MONTH, one.getCount()); | 
|---|
|  |  |  | Date dateAfterOneMonth = calendar.getTime(); | 
|---|
|  |  |  | dateAfterOneMonth.setHours(23); | 
|---|
|  |  |  | dateAfterOneMonth.setMinutes(59); | 
|---|
|  |  |  | dateAfterOneMonth.setSeconds(59); | 
|---|
|  |  |  | one.setTime(dateAfterOneMonth); | 
|---|
|  |  |  | byId1.setVipEndTime(dateAfterOneMonth); | 
|---|
|  |  |  | userService.updateById(byId1); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | Calendar calendar = Calendar.getInstance(); | 
|---|
|  |  |  | calendar.setTime(byId1.getVipEndTime()); | 
|---|
|  |  |  | calendar.add(Calendar.MONTH, one.getCount()); | 
|---|
|  |  |  | Date dateAfterOneMonth = calendar.getTime(); | 
|---|
|  |  |  | dateAfterOneMonth.setHours(23); | 
|---|
|  |  |  | dateAfterOneMonth.setMinutes(59); | 
|---|
|  |  |  | dateAfterOneMonth.setSeconds(59); | 
|---|
|  |  |  | one.setTime(dateAfterOneMonth); | 
|---|
|  |  |  | byId1.setVipEndTime(dateAfterOneMonth); | 
|---|
|  |  |  | userService.updateById(byId1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | vipOrderService.updateById(one); | 
|---|
|  |  |  | System.err.println("苹果流水号"+string); | 
|---|
|  |  |  | PrintWriter out = response.getWriter(); | 
|---|
|  |  |  | out.write("success"); | 
|---|
|  |  |  | out.flush(); | 
|---|
|  |  |  | out.close(); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 处理苹果退款 回调通知 | 
|---|
|  |  |  | * @param request | 
|---|
|  |  |  | * @param response | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | @PostMapping("/refundApple") | 
|---|
|  |  |  | public void refundApple(HttpServletRequest request, HttpServletResponse response) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | System.err.println("请求"+request); | 
|---|
|  |  |  | BufferedReader reader = request.getReader(); | 
|---|
|  |  |  | String string1 = reader.toString(); | 
|---|
|  |  |  | System.err.println("请求reader"+string1); | 
|---|
|  |  |  | StringBuilder requestBody = new StringBuilder(); | 
|---|
|  |  |  | String line; | 
|---|
|  |  |  | while ((line = reader.readLine()) != null) { | 
|---|
|  |  |  | requestBody.append(line); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | System.err.println("全部请求体"+requestBody); | 
|---|
|  |  |  | org.json.JSONObject jsonObject1 = new org.json.JSONObject(requestBody.toString()); | 
|---|
|  |  |  | System.err.println("json串"+jsonObject1); | 
|---|
|  |  |  | String o = jsonObject1.getString("signedPayload"); | 
|---|
|  |  |  | JSONObject payload = verifyAndGet(o); | 
|---|
|  |  |  | String notificationType = payload.get("notificationType").toString(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | JSONObject data = payload.getJSONObject("data"); | 
|---|
|  |  |  | String signedTransactionInfo = data.get("signedTransactionInfo").toString(); | 
|---|
|  |  |  | JSONObject transactionInfo = verifyAndGet(signedTransactionInfo); | 
|---|
|  |  |  | System.err.println("解签后的json串"+transactionInfo); | 
|---|
|  |  |  | System.err.println("data"+data); | 
|---|
|  |  |  | // 苹果流水号 | 
|---|
|  |  |  | String string = transactionInfo.getString("originalTransactionId"); | 
|---|
|  |  |  | TVipOrder one = vipOrderService.getOne(new QueryWrapper<TVipOrder>() | 
|---|
|  |  |  | .eq("transactionId", string) | 
|---|
|  |  |  | .eq("payType", 3)); | 
|---|
|  |  |  | if (one!=null && one.getPayState() == 2){ | 
|---|
|  |  |  | one.setPayState(3); | 
|---|
|  |  |  | one.setBackTime(new Date()); | 
|---|
|  |  |  | // 用户的vip剩余时间减少 | 
|---|
|  |  |  | Calendar calendar = Calendar.getInstance(); | 
|---|
|  |  |  | calendar.setTime(new Date()); | 
|---|
|  |  |  | calendar.add(Calendar.MONTH, -one.getCount()); | 
|---|
|  |  |  | Integer userId = one.getUserId(); | 
|---|
|  |  |  | TUser byId1 = userService.getById(userId); | 
|---|
|  |  |  | // 判断用户是不是第一次充值 | 
|---|
|  |  |  | List<TVipOrder> list = vipOrderService.list(new QueryWrapper<TVipOrder>() | 
|---|
|  |  |  | .eq("userId", userId) | 
|---|
|  |  |  | .eq("payState", 2) | 
|---|
|  |  |  | .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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | vipOrderService.updateById(one); | 
|---|
|  |  |  | System.err.println("苹果流水号"+string); | 
|---|
|  |  |  | PrintWriter out = response.getWriter(); | 
|---|
|  |  |  | out.write("success"); | 
|---|
|  |  |  | out.flush(); | 
|---|
|  |  |  | out.close(); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | @PostMapping("/aliPayBuyVip") | 
|---|
|  |  |  | public void addVipPaymentAliCallback(HttpServletRequest request, HttpServletResponse response) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | System.err.println("进入支付宝回调"); | 
|---|
|  |  |  | Map<String, String> map = payMoneyUtil.alipayCallback(request); | 
|---|
|  |  |  | 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 | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | byId.setPayTime(new Date()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | TUser byId1 = userService.getById(byId.getUserId()); | 
|---|
|  |  |  | if (byId1.getVipPayTime() == null) { | 
|---|
|  |  |  | 
|---|
|  |  |  | dateAfterOneMonth.setSeconds(59); | 
|---|
|  |  |  | byId1.setVipEndTime(dateAfterOneMonth); | 
|---|
|  |  |  | byId.setTime(dateAfterOneMonth); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 不是首次 判断vipEndTime 是否到期 如果没有 加指定月份时间 如果到期了 将会员到期时间从当前增加指定月份 | 
|---|
|  |  |  | if (byId1.getVipEndTime().getTime() < new Date().getTime()) { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 修改用户会员续期信息 | 
|---|
|  |  |  | userService.updateById(byId1); | 
|---|
|  |  |  | PrintWriter out = response.getWriter(); | 
|---|
|  |  |  | out.write("success"); | 
|---|
|  |  |  | out.flush(); | 
|---|
|  |  |  | out.close(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 
|---|
|  |  |  | vipOrderService.updateById(byId); | 
|---|
|  |  |  | // 修改用户会员续期信息 | 
|---|
|  |  |  | userService.updateById(byId1); | 
|---|
|  |  |  | PrintWriter out = response.getWriter(); | 
|---|
|  |  |  | out.write(result); | 
|---|
|  |  |  | out.flush(); | 
|---|
|  |  |  | out.close(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return R.tokenError("登录失效"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/studyPage") | 
|---|
|  |  |  | @ApiOperation(value = "学习端", tags = {"启动页"}) | 
|---|
|  |  |  | public R<String> studyPage() { | 
|---|
|  |  |  | List<TPage> data = managementClient.getPage1().getData(); | 
|---|
|  |  |  | for (TPage datum : data) { | 
|---|
|  |  |  | if (datum.getType() == 1) { | 
|---|
|  |  |  | return R.ok(datum.getImg()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/parentPage") | 
|---|
|  |  |  | 
|---|
|  |  |  | 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)); | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.freeze("登录失败,您的账号已被冻结!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | tUser1 = new TUser(); | 
|---|
|  |  |  | // 手机验证码校验 | 
|---|
|  |  |  | if (!phoneCode.equals("123456")) { | 
|---|
|  |  |  | Object redisPhoneCode = redisService.getCacheObject(RedisConstants.PHONE_CODE + phone); | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.errorCode("登录失败,手机验证码无效!"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | tUser1 = getUser(phone); | 
|---|
|  |  |  | tUser1.setHeadImg("https://haitunyingyu.obs.cn-southwest-2.myhuaweicloud.com/admin/1c6ee218aa18434db2e86df903990de8.jpg"); | 
|---|
|  |  |  | 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("用户"+upperCase); | 
|---|
|  |  |  | tUser1.setName("用户"+upperCase); | 
|---|
|  |  |  | userService.save(tUser1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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 R.ok(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 学生端登录 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param phoneRequest 手机号及手机验证码 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping("/studyLogin") | 
|---|
|  |  |  | @ApiOperation(value = "学习端-登录", tags = {"学习端-登录"}) | 
|---|
|  |  |  | public R<Map<String, Object>> studyLogin(@RequestBody RegisterPhoneRequest phoneRequest) { | 
|---|
|  |  |  | String phone = phoneRequest.getPhone(); | 
|---|
|  |  |  | String phoneCode = phoneRequest.getPhoneCode(); | 
|---|
|  |  |  | // 验证码校验 | 
|---|
|  |  |  | 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) || !"123456".equals(phoneCode)) { | 
|---|
|  |  |  | return R.errorCode("登录失败,验证码无效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 获取手机号所注册用户信息 | 
|---|
|  |  |  | TUser user = userService.getOne(new QueryWrapper<TUser>() | 
|---|
|  |  |  | .ne("state", 3) | 
|---|
|  |  |  | .eq("phone", phone)); | 
|---|
|  |  |  | if (user != null) { | 
|---|
|  |  |  | if (user.getState() == 2) { | 
|---|
|  |  |  | return R.freeze("登录失败,您的账号已被冻结!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | user = getUser(phone); | 
|---|
|  |  |  | userService.save(user); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 生成登录用户信息 | 
|---|
|  |  |  | LoginUserParent loginUserParent = new LoginUserParent(); | 
|---|
|  |  |  | loginUserParent.setName(user.getName()); | 
|---|
|  |  |  | loginUserParent.setUserid(user.getId()); | 
|---|
|  |  |  | loginUserParent.setPhone(user.getPhone()); | 
|---|
|  |  |  | loginUserParent.setLoginTime(System.currentTimeMillis()); | 
|---|
|  |  |  | HashMap<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | // 获取登录token | 
|---|
|  |  |  | map.put("token", tokenService.createTokenStudy(loginUserParent)); | 
|---|
|  |  |  | map.put("token", tokenService.createToken1(loginUserParent)); | 
|---|
|  |  |  | // 学习进度检查 | 
|---|
|  |  |  | TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, user.getId()) | 
|---|
|  |  |  | TUserStudy userStudy = userStudyService.lambdaQuery().eq(TUserStudy::getUserId, tUser1.getId()) | 
|---|
|  |  |  | .eq(TUserStudy::getDisabled, 0).one(); | 
|---|
|  |  |  | if (null == userStudy) { | 
|---|
|  |  |  | TUserStudy study = new TUserStudy(); | 
|---|
|  |  |  | study.setUserId(user.getId()); | 
|---|
|  |  |  | study.setWeek(Constants.ONE); | 
|---|
|  |  |  | 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.setPair(Constants.BURDEN_ONE); | 
|---|
|  |  |  | userStudyService.save(study); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | map.put("lookVideo", tUser1.getLookVideo()==null?0:tUser1.getLookVideo()); | 
|---|
|  |  |  | return R.ok(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 学生端登录 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param phoneRequest 手机号及手机验证码 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping("/studyLogin") | 
|---|
|  |  |  | @ApiOperation(value = "学习端-登录", tags = {"学习端-登录"}) | 
|---|
|  |  |  | public R<Map<String, Object>> studyLogin(@RequestBody RegisterPhoneRequest phoneRequest) throws Exception { | 
|---|
|  |  |  | 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)); | 
|---|
|  |  |  | if (user != null) { | 
|---|
|  |  |  | if (user.getState() == 2) { | 
|---|
|  |  |  | return R.freeze("登录失败,您的账号已被冻结!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | user = getUser(phone); | 
|---|
|  |  |  | user.setHeadImg("https://haitunyingyu.obs.cn-southwest-2.myhuaweicloud.com/admin/1c6ee218aa18434db2e86df903990de8.jpg"); | 
|---|
|  |  |  | String upperCase = UUIDUtil.getRandomCode(6).toUpperCase(); | 
|---|
|  |  |  | user.setAccount("用户"+upperCase); | 
|---|
|  |  |  | user.setName("用户"+upperCase); | 
|---|
|  |  |  | userService.save(user); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 生成登录用户信息 | 
|---|
|  |  |  | LoginUserParent loginUserParent = new LoginUserParent(); | 
|---|
|  |  |  | loginUserParent.setName(user.getName()); | 
|---|
|  |  |  | loginUserParent.setUserid(user.getId()); | 
|---|
|  |  |  | loginUserParent.setPhone(user.getPhone()); | 
|---|
|  |  |  | loginUserParent.setLoginTime(System.currentTimeMillis()); | 
|---|
|  |  |  | HashMap<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | // 获取登录token | 
|---|
|  |  |  | map.put("token", tokenService.createTokenStudy(loginUserParent)); | 
|---|
|  |  |  | return R.ok(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @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(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @GetMapping("/userInfo") | 
|---|
|  |  |  | @ApiOperation(value = "用户详情", tags = {"学习端-用户详情"}) | 
|---|
|  |  |  | public R<UserPersonalCenterVO> userInfo() { | 
|---|
|  |  |  | TUser user = userService.lambdaQuery().eq(TUser::getId, tokenService.getLoginUserStudy().getUserid()).one(); | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | if (null == userStudy) { | 
|---|
|  |  |  | userStudy = createUserStudy(loginUserStudy.getUserid()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 学习时长格式转换 | 
|---|
|  |  |  | 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) / 3600)); | 
|---|
|  |  |  | return R.ok(new UserPersonalCenterVO(user, userStudy)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private TUserStudy createUserStudy(Integer userid) { | 
|---|
|  |  |  | TUserStudy userStudy = new TUserStudy(); | 
|---|
|  |  |  | userStudy.setUserId(userid); | 
|---|
|  |  |  | // 学习周目 | 
|---|
|  |  |  | TStudy tStudy = studyService.lambdaQuery().eq(TStudy::getQuarter, Constants.ONE) | 
|---|
|  |  |  | .orderByAsc(TStudy::getWeek).last("limit 1").one(); | 
|---|
|  |  |  | userStudy.setWeek(tStudy.getWeek()); | 
|---|
|  |  |  | userStudy.setDay(Constants.ONE); | 
|---|
|  |  |  | userStudy.setTotalStudy(Constants.ZERO); | 
|---|
|  |  |  | userStudy.setTodayStudy(Constants.ZERO); | 
|---|
|  |  |  | userStudy.setWeekStudy(Constants.ZERO); | 
|---|
|  |  |  | userStudy.setMonthStudy(Constants.ZERO); | 
|---|
|  |  |  | userStudy.setListen(Constants.BURDEN_ONE); | 
|---|
|  |  |  | userStudy.setLook(Constants.BURDEN_ONE); | 
|---|
|  |  |  | userStudy.setInduction(Constants.BURDEN_ONE); | 
|---|
|  |  |  | userStudy.setAnswer(Constants.BURDEN_ONE); | 
|---|
|  |  |  | userStudy.setPair(Constants.BURDEN_ONE); | 
|---|
|  |  |  | userStudyService.save(userStudy); | 
|---|
|  |  |  | return userStudy; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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()); | 
|---|
|  |  |  | // 判断用户会员到期时间 用于判断这个用户到底是不是会员 | 
|---|
|  |  |  | if (null != byId.getVipEndTime()) { | 
|---|
|  |  |  | Date vipEndTime = byId.getVipEndTime(); | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | if (vipEndTime.before(now)) { | 
|---|
|  |  |  | byId.setIsVip(Constants.ZERO); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | byId.setIsVip(Constants.ONE); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | byId.setIsVip(Constants.ZERO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(byId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @PostMapping("/lookVideo") | 
|---|
|  |  |  | @ApiOperation(value = "看完操作视频调用", tags = {"家长端-登录"}) | 
|---|
|  |  |  | public R<TUser> lookVideo() { | 
|---|
|  |  |  | LoginUserParent loginUserStudy = tokenService.getLoginUser1(); | 
|---|
|  |  |  | if (null == loginUserStudy) { | 
|---|
|  |  |  | return R.tokenError("登录失效!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | TUser byId = userService.getById(loginUserStudy.getUserid()); | 
|---|
|  |  |  | byId.setLookVideo(1); | 
|---|
|  |  |  | userService.updateById(byId); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/deleteUser") | 
|---|
|  |  |  | 
|---|
|  |  |  | 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({ | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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)); | 
|---|
|  |  |  | 
|---|
|  |  |  | userService.updateById(byId1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PrintWriter out = response.getWriter(); | 
|---|
|  |  |  | out.write(result); | 
|---|
|  |  |  | out.flush(); | 
|---|
|  |  |  | out.close(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | 
|---|
|  |  |  | case 2: | 
|---|
|  |  |  | // 支付宝退款 | 
|---|
|  |  |  | Map<String, String> stringStringMap1 = payMoneyUtil.aliRefund(transactionId, byId.getMoney().toString()); | 
|---|
|  |  |  | System.err.println("支付宝退款数据" + stringStringMap1); | 
|---|
|  |  |  | if (null == stringStringMap1) { | 
|---|
|  |  |  | return R.fail("取消退款异常"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 
|---|
|  |  |  | Calendar calendar = Calendar.getInstance(); | 
|---|
|  |  |  | calendar.setTime(new Date()); | 
|---|
|  |  |  | calendar.add(Calendar.MONTH, -byId.getCount()); | 
|---|
|  |  |  | Date dateAfterOneMonth = calendar.getTime(); | 
|---|
|  |  |  | Integer userId = byId.getUserId(); | 
|---|
|  |  |  | TUser byId1 = userService.getById(userId); | 
|---|
|  |  |  | // 判断用户是不是第一次充值 | 
|---|
|  |  |  | 
|---|
|  |  |  | .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(); | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "用户列表", tags = {"管理后台-用户管理"}) | 
|---|
|  |  |  | public R<PageInfo<AppUserVO>> couponReceive(@RequestBody AppUserQuery query) { | 
|---|
|  |  |  | PageInfo<AppUserVO> res = new PageInfo<>(query.getPageNumber(), query.getPageSize()); | 
|---|
|  |  |  | List<AppUserVO> list = userService.listAll(query); | 
|---|
|  |  |  | List<AppUserVO> list = userService.listAll(query,res); | 
|---|
|  |  |  | for (AppUserVO appUserVO : list) { | 
|---|
|  |  |  | if (appUserVO.getVipEndTime() == null) { | 
|---|
|  |  |  | appUserVO.setIsVip(0); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | res.setRecords(list); | 
|---|
|  |  |  | res.setTotal(list.size()); | 
|---|
|  |  |  | return R.ok(res); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | public R<UserInfoVO> getUserInfo(@RequestBody UserInfoQuery dto) { | 
|---|
|  |  |  | SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd"); | 
|---|
|  |  |  | UserInfoVO res = new UserInfoVO(); | 
|---|
|  |  |  | PageInfo<UserGameRecordVO> list = new PageInfo<>(dto.getPageNumber(), dto.getPageSize()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | TUser byId = userService.getById(dto.getId()); | 
|---|
|  |  |  | String name = byId.getName(); | 
|---|
|  |  |  | String phone = byId.getPhone(); | 
|---|
|  |  |  | 
|---|
|  |  |  | res.setIsVip(0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (vipPayTime != null) { | 
|---|
|  |  |  | if (vipEndTime != null) { | 
|---|
|  |  |  | res.setVipPayTime(format.format(vipPayTime)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | res.setState(byId.getState()); | 
|---|
|  |  |  | res.setName(name); | 
|---|
|  |  |  | res.setPhone(phone); | 
|---|
|  |  |  | res.setInsertTime(format.format(insertTime)); | 
|---|
|  |  |  | if (insertTime != null) { | 
|---|
|  |  |  | res.setInsertTime(format.format(insertTime)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | res.setIntegral(byId.getIntegral()); | 
|---|
|  |  |  | // 学习记录 | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | int size = studyService.list(new QueryWrapper<TStudy>() | 
|---|
|  |  |  | .eq("type", 1)).size(); | 
|---|
|  |  |  | studyRecord.setSurplus(size - studyRecord.getWeek()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | res.setCurrent(0); | 
|---|
|  |  |  | res.setSurplus(0); | 
|---|
|  |  |  | res.setTotalHours(0.0); | 
|---|
|  |  |  | res.setTodayHours(0.0); | 
|---|
|  |  |  | res.setWeekHours(0.0); | 
|---|
|  |  |  | res.setMonthHours(0.0); | 
|---|
|  |  |  | TUserStudy tUserStudy = new TUserStudy(); | 
|---|
|  |  |  | tUserStudy.setSurplus(studyService.list(new QueryWrapper<TStudy>() | 
|---|
|  |  |  | .eq("type", 1)).size()); | 
|---|
|  |  |  | tUserStudy.setWeek(1); | 
|---|
|  |  |  | tUserStudy.setTodayStudy(Constants.ZERO); | 
|---|
|  |  |  | tUserStudy.setTotalStudy(Constants.ZERO); | 
|---|
|  |  |  | tUserStudy.setWeekStudy(Constants.ZERO); | 
|---|
|  |  |  | tUserStudy.setMonthStudy(Constants.ZERO); | 
|---|
|  |  |  | studyRecord = tUserStudy; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<UserGameRecordVO> userGameRecordVOS = new ArrayList<>(); | 
|---|
|  |  |  | // 学习时长格式转换 | 
|---|
|  |  |  | Integer todayStudy = studyRecord.getTodayStudy(); | 
|---|
|  |  |  | studyRecord.setTodayStudy(Math.round((float) todayStudy / 3600)); | 
|---|
|  |  |  | Integer weekStudy = studyRecord.getWeekStudy(); | 
|---|
|  |  |  | studyRecord.setWeekStudy(Math.round((float) weekStudy / 3600)); | 
|---|
|  |  |  | Integer monthStudy = studyRecord.getMonthStudy(); | 
|---|
|  |  |  | studyRecord.setMonthStudy(Math.round((float) monthStudy / 3600)); | 
|---|
|  |  |  | // 总时长还需计算上游戏测试成绩时长 | 
|---|
|  |  |  | List<TGameRecord> gameRecordList = gameRecordService.lambdaQuery().eq(TGameRecord::getUserId, dto.getId()) | 
|---|
|  |  |  | .eq(TGameRecord::getDisabled, 0) | 
|---|
|  |  |  | .orderByDesc(TGameRecord::getCreateTime) | 
|---|
|  |  |  | .list(); | 
|---|
|  |  |  | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm"); | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | tGameRecord.setTime(simpleDateFormat.format(tGameRecord.getCreateTime())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | list.setRecords(userGameRecordVOS); | 
|---|
|  |  |  | list.setTotal(userGameRecordVOS.size()); | 
|---|
|  |  |  | res.setGameRecords(list); | 
|---|
|  |  |  | 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() + ""); | 
|---|
|  |  |  | // 剩余周目 | 
|---|
|  |  |  | 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.setTotalHours(studyRecord.getTotalStudy().doubleValue()); | 
|---|
|  |  |  | res.setTodayHours(studyRecord.getTodayStudy().doubleValue()); | 
|---|
|  |  |  | res.setMonthHours(studyRecord.getMonthStudy().doubleValue()); | 
|---|
|  |  |  | res.setWeekHours(studyRecord.getWeekStudy().doubleValue()); | 
|---|
|  |  |  | PageInfo<TGameRecord> list1 = new PageInfo<>(dto.getPageNumber(), dto.getPageSize()); | 
|---|
|  |  |  | list1.setTotal(gameRecordList.size()); | 
|---|
|  |  |  | list1.setRecords(gameRecordList); | 
|---|
|  |  |  | res.setGameRecords(list1); | 
|---|
|  |  |  | return R.ok(res); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "列表查询", tags = {"管理后台-会员管理"}) | 
|---|
|  |  |  | public R<PageInfo<VipOrderVO>> vipOrderList(@RequestBody AppUserQuery query) { | 
|---|
|  |  |  | PageInfo<VipOrderVO> res = new PageInfo<>(query.getPageNumber(), query.getPageSize()); | 
|---|
|  |  |  | List<VipOrderVO> list = vipOrderService.listAll(query); | 
|---|
|  |  |  | List<VipOrderVO> list = vipOrderService.listAll(query,res); | 
|---|
|  |  |  | res.setRecords(list); | 
|---|
|  |  |  | res.setTotal(list.size()); | 
|---|
|  |  |  | return R.ok(res); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|