From e88d8861137a816a0ce8b79c390f319c46c6242d Mon Sep 17 00:00:00 2001 From: lisy <linlangsur163@163.com> Date: 星期五, 04 八月 2023 15:14:25 +0800 Subject: [PATCH] app端:开始上课-课后视频的字段添加 --- cloud-server-course/src/main/java/com/dsh/course/service/impl/TCoursePackagePaymentServiceImpl.java | 389 +++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 273 insertions(+), 116 deletions(-) diff --git a/cloud-server-course/src/main/java/com/dsh/course/service/impl/TCoursePackagePaymentServiceImpl.java b/cloud-server-course/src/main/java/com/dsh/course/service/impl/TCoursePackagePaymentServiceImpl.java index 72d255f..67ee58f 100644 --- a/cloud-server-course/src/main/java/com/dsh/course/service/impl/TCoursePackagePaymentServiceImpl.java +++ b/cloud-server-course/src/main/java/com/dsh/course/service/impl/TCoursePackagePaymentServiceImpl.java @@ -1,9 +1,15 @@ package com.dsh.course.service.impl; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alipay.api.domain.Person; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.dsh.course.entity.*; +import com.dsh.course.feignclient.account.AppUserClient; import com.dsh.course.feignclient.account.CoachClient; +import com.dsh.course.feignclient.account.model.AppUser; import com.dsh.course.feignclient.account.model.Coach; import com.dsh.course.feignclient.activity.BenefitVideoClient; import com.dsh.course.feignclient.activity.CouponClient; @@ -26,7 +32,6 @@ import com.dsh.course.util.*; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -78,11 +83,18 @@ @Resource private TCoursePackageDiscountMapper tcpdMapper; + + @Resource + private CoursePackagePaymentConfigMapper cpConfigMapper; + @Resource private CouponClient client; - @Autowired + @Resource private PayMoneyUtil payMoneyUtil; + + @Resource + private AppUserClient appuClient; /** @@ -98,9 +110,13 @@ @Override public List<AppUserVideoResponse> queryAfterVideo(CourseOfAfterRequest search,List<Integer> courseIds) { List<AppUserVideoResponse> responses = new ArrayList<>(); - List<PostCourseVideo> videoList = pcvMapper.selectList(new QueryWrapper<PostCourseVideo>() - .eq("coursePackageId", courseIds)); - + List<PostCourseVideo> videoList = new ArrayList<>(); + LambdaQueryWrapper<PostCourseVideo> queryWrapper = new LambdaQueryWrapper<PostCourseVideo>(); + if (courseIds.size() > 0 ){ + queryWrapper.in(PostCourseVideo::getCoursePackageId,courseIds); + } + videoList = pcvMapper.selectList(queryWrapper); + System.out.println(videoList); if (videoList.size() > 0){ List<Integer> videoIds = videoList.stream().map(PostCourseVideo::getCourseId).collect(Collectors.toList()); List<UserVideoDetails> userVideoDetails = uvdmapper.selectList(new QueryWrapper<UserVideoDetails>() @@ -114,23 +130,23 @@ BenefitsVideos videosWithIds = bfvoClient.getVideosWithIds(userVideoDetail.getCourseId()); response.setVideoId(userVideoDetail.getCourseId()); response.setCoverImage(videosWithIds.getCover()); - if (null != search.getSearch()){ -// 根据正则模糊匹配 - String pattern = ".*" + search.getSearch() + ".*"; - Pattern regex = Pattern.compile(pattern); - Matcher matcher = regex.matcher(videosWithIds.getName()); - if (matcher.matches()) { - response.setVideoName(videosWithIds.getName()); - } - }else { - response.setVideoName(videosWithIds.getName()); - } + response.setVideoName(videosWithIds.getName()); response.setSynopsis(videosWithIds.getIntroduction()); response.setIntegral(videosWithIds.getIntegral()); response.setStudyStatus(userVideoDetail.getState()); responses.add(response); } Collections.sort(responses, Comparator.comparing(AppUserVideoResponse::getStudyStatus)); + } + if (ToolUtil.isNotEmpty(search.getSearch())){ + responses = responses.stream() + .filter(person -> person.getPackageName().contains(search.getSearch())) + .collect(Collectors.toList()); + } + if (ToolUtil.isNotEmpty(search.getCourseTypeId())){ + responses = responses.stream() + .filter(person -> Objects.equals(person.getCoursePackageId(), search.getCourseTypeId())) + .collect(Collectors.toList()); } } return responses; @@ -156,6 +172,7 @@ response.setPackageName(coursePackage.getName()); response.setSynopsis(videosWithIds.getIntroduction()); response.setDetailedDiagram(coursePackage.getIntroduceDrawing()); + response.setCover(videosWithIds.getCover()); } return response; @@ -174,7 +191,7 @@ uvdmapper.updateById(userVideoDetails); return "SUCCESS"; } - return null; + return "ERROR"; } @Override @@ -182,6 +199,7 @@ List<RegisterCourseVo> courseVos = new ArrayList<>(); List<TCoursePackagePayment> tCoursePackagePayments = this.list(new QueryWrapper<TCoursePackagePayment>() .eq("appUserId",appUserId )); + System.out.println(tCoursePackagePayments); if (tCoursePackagePayments.size() > 0){ for (TCoursePackagePayment tCoursePackagePayment : tCoursePackagePayments) { TCoursePackage coursePackage = tcpmapper.selectById(tCoursePackagePayment.getCoursePackageId()); @@ -189,18 +207,39 @@ RegisterCourseVo registerCourseVo = new RegisterCourseVo(); registerCourseVo.setCoursePayId(tCoursePackagePayment.getId()); registerCourseVo.setCoursePackageId(tCoursePackagePayment.getCoursePackageId()); + registerCourseVo.setCoursePackTypeId(coursePackage.getCoursePackageTypeId()); registerCourseVo.setPackageImg(coursePackage.getCoverDrawing()); String storeAndCourse = coursePackage.getName()+"("+ store.getName() +")"; registerCourseVo.setCourseNameStore(storeAndCourse); registerCourseVo.setCourseTime(coursePackage.getClassStartTime()+"-"+coursePackage.getClassEndTime()); Coach coach = coachClient.queryCoachById(coursePackage.getCoachId()); - registerCourseVo.setCourseTeacher(coach.getName()); + registerCourseVo.setCourseTeacher(ToolUtil.isEmpty(coach) ? "" : coach.getName()); List<CoursePackageStudent> coursePackageStudents = cpsMapper.selectList(new QueryWrapper<CoursePackageStudent>() .eq("coursePackageId",coursePackage.getId()) .eq("studentId",appUserId )); - registerCourseVo.setCourseNums(coursePackageStudents.size() * 2); + if (coursePackageStudents.size() > 0 ){ + registerCourseVo.setCourseNums(coursePackageStudents.size() * 2); + } registerCourseVo.setPayStatus(tCoursePackagePayment.getPayStatus()); courseVos.add(registerCourseVo); + } + + if (ToolUtil.isNotEmpty(courseTypeId.getSearch())){ + courseVos = courseVos.stream() + .filter(person -> person.getCourseNameStore().contains(courseTypeId.getSearch())) + .collect(Collectors.toList()); + } + + if (ToolUtil.isNotEmpty(courseTypeId.getCourseTypeId())){ + courseVos = courseVos.stream() + .filter(person -> Objects.equals(person.getCoursePackTypeId(), courseTypeId.getCourseTypeId())) + .collect(Collectors.toList()); + } + + if (courseVos.size() > 0 ){ + courseVos = courseVos.stream() + .sorted(Comparator.comparingInt(person -> person.getPayStatus() == 1 ? -1 : 1)) + .collect(Collectors.toList()); } } return courseVos; @@ -221,33 +260,9 @@ if (integers.size() > 0){ StringBuilder courWeeks = new StringBuilder("每"); for (Integer integer : integers) { - switch (integer){ - case 1: - courWeeks.append("周一、"); - break; - case 2: - courWeeks.append("周二、"); - break; - case 3: - courWeeks.append("周三、"); - break; - case 4: - courWeeks.append("周四、"); - break; - case 5: - courWeeks.append("周五、"); - break; - case 6: - courWeeks.append("周六、"); - break; - case 7: - courWeeks.append("周末、"); - break; - default: - break; - } + courWeeks.append(integer).append("、"); } - if (courWeeks.length() > 0 && courWeeks.charAt(courWeeks.length() - 1) == ','){ + if (courWeeks.length() > 0 && courWeeks.charAt(courWeeks.length() - 1) == '、'){ courWeeks.deleteCharAt(courWeeks.length() - 1); } response.setWeeks(courWeeks.toString()); @@ -289,26 +304,61 @@ } @Override - public ResultUtil ContinuationOrpaymentCourse(Integer userIdFormRedis, ClasspaymentRequest request) { + public ResultUtil ContinuationOrpaymentCourse(Integer ids, ClasspaymentRequest request) { + AppUser userIdFormRedis = appuClient.queryAppUser(ids); TCoursePackagePayment tCoursePackagePayment = this.baseMapper.selectById(request.getCoursePayId()); String code = ""; + BigDecimal money = tCoursePackagePayment.getCashPayment(); + Integer wpGold = tCoursePackagePayment.getPlayPaiCoin(); if (tCoursePackagePayment.getPayStatus() == 1){ +// 待支付的订单 code = tCoursePackagePayment.getCode(); + tCoursePackagePayment.setPayType(request.getPayType()); + if (request.getUseConpon() == 1){ + tCoursePackagePayment.setUserCouponId(Long.valueOf(request.getUseConpon())); + } + this.baseMapper.updateById(tCoursePackagePayment); }else { +// 续课的订单 +// 查询是否续课优惠 + + CoursePackagePaymentConfig paymentConfig = cpConfigMapper.selectOne(new QueryWrapper<CoursePackagePaymentConfig>() + .eq("coursePackageId", request.getLessonId()) + .eq("classHours", request.getCourseHoursNum())); + TCoursePackageDiscount coursePackageDiscount = tcpdMapper.selectOne(new QueryWrapper<TCoursePackageDiscount>() + .eq("coursePackageId", request.getLessonId()) + .eq("type", 2) + .eq("auditStatus", 1) + .eq("coursePackagePaymentConfigId", paymentConfig.getCoursePackageId())); + if (ToolUtil.isNotEmpty(coursePackageDiscount)){ + String content = coursePackageDiscount.getContent(); + JSONObject jsonObject = JSON.parseObject(content); + if (userIdFormRedis.getIsVip() == 1){ + Double jsonObjectDouble = jsonObject.getDouble("num1"); + money = BigDecimal.valueOf(jsonObjectDouble); + }else { + Double jsonObjectDouble = jsonObject.getDouble("num2"); + money = BigDecimal.valueOf(jsonObjectDouble); + } + } TCoursePackagePayment newPayment = new TCoursePackagePayment(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); newPayment.setCode(sdf.format(new Date()) + UUIDUtil.getNumberRandom(5)); - newPayment.setAppUserId(userIdFormRedis); + newPayment.setAppUserId(userIdFormRedis.getId()); newPayment.setStudentId(request.getStuId()); newPayment.setCoursePackageId(request.getLessonId()); newPayment.setClassHours(tCoursePackagePayment.getClassHours()); newPayment.setOriginalPrice(tCoursePackagePayment.getOriginalPrice()); newPayment.setTotalClassHours(tCoursePackagePayment.getTotalClassHours()); newPayment.setLaveClassHours(tCoursePackagePayment.getTotalClassHours()); + if (request.getUseConpon() == 1){ + newPayment.setUserCouponId(Long.valueOf(request.getUseConpon())); + } newPayment.setAbsencesNumber(0); newPayment.setPayUserType(1); newPayment.setPayStatus(1); newPayment.setStatus(1); + newPayment.setPayType(request.getPayType()); newPayment.setState(1); newPayment.setInsertTime(new Date()); this.baseMapper.insert(newPayment); @@ -316,13 +366,47 @@ } switch (request.getPayType()){ case 1: - WeChatPayment(code,request); - break; + if (request.getUseConpon() == 1){ + Coupon coupon = client.queryCouponById(request.getConponId()); + if (coupon.getType() == 1){ + Map<String, Object> couponRules = client.getCouponRules(coupon.getId()); + Double conditionalAmount = (Double) couponRules.get("conditionalAmount"); + Double deductionAmount = (Double) couponRules.get("deductionAmount"); + if (money.compareTo(BigDecimal.valueOf(conditionalAmount)) >= 0){ + money = BigDecimal.valueOf(deductionAmount); + } + } + if (coupon.getType() == 2){ + Map<String, Object> couponRules = client.getCouponRules(coupon.getId()); + Object amount = couponRules.get("deductionAmount"); + money = BigDecimal.valueOf((Double) amount); + } + } + try { + return WeChatPayment(code,money); + }catch (Exception e){ + return ResultUtil.runErr(); + } case 2: - AlipayPayment(code,request); - break; + if (request.getUseConpon() == 1){ + Coupon coupon = client.queryCouponById(request.getConponId()); + if (coupon.getType() == 1){ + Map<String, Object> couponRules = client.getCouponRules(coupon.getId()); + Double conditionalAmount = (Double) couponRules.get("conditionalAmount"); + Double deductionAmount = (Double) couponRules.get("deductionAmount"); + if (money.compareTo(BigDecimal.valueOf(conditionalAmount)) >= 0){ + money = BigDecimal.valueOf(deductionAmount); + } + } + if (coupon.getType() == 2){ + Map<String, Object> couponRules = client.getCouponRules(coupon.getId()); + Object amount = couponRules.get("deductionAmount"); + money = BigDecimal.valueOf((Double) amount); + } + } + return AlipayPayment(code,money); case 3: - PlaypaiGoldPayment(code,request); + PlaypaiGoldPayment(userIdFormRedis,code,wpGold); break; default: break; @@ -331,73 +415,135 @@ } - public void WeChatPayment(String code, ClasspaymentRequest request){ - + public ResultUtil WeChatPayment(String code, BigDecimal request) throws Exception { + TCoursePackagePaymentMapper baseMapper1 = this.baseMapper; + ResultUtil weixinpay = payMoneyUtil.weixinpay("课包续费", "", code, request.toString(), + "/base/coursePackage/wechatRegisteredCoursesCallback", "APP", ""); + if(weixinpay.getCode() == 200){ + new Thread(new Runnable() { + @Override + public void run() { + try { + int num = 1; + int wait = 0; + while (num <= 10){ + int min = 5000; + wait += (min * num); + Thread.sleep(wait); + TCoursePackagePayment coursePackagePayment = baseMapper1.getCoursePackagePaymentByCode(code); + if(coursePackagePayment.getPayStatus() == 2){ + break; + } + ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(code, ""); + if(resultUtil.getCode() == 200 && coursePackagePayment.getPayStatus() == 1){ + /** + * SUCCESS—支付成功, + * REFUND—转入退款, + * NOTPAY—未支付, + * CLOSED—已关闭, + * REVOKED—已撤销(刷卡支付), + * USERPAYING--用户支付中, + * PAYERROR--支付失败(其他原因,如银行返回失败) + */ + Map<String, String> data1 = resultUtil.getData(); + String s = data1.get("trade_state"); + String transaction_id = data1.get("transaction_id"); + if("REFUND".equals(s) || "NOTPAY".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s) || num == 10){ + coursePackagePayment.setState(3); + baseMapper1.deleteById(coursePackagePayment.getId()); + break; + } + if("SUCCESS".equals(s)){ + coursePackagePayment.setPayStatus(2); + coursePackagePayment.setOrderNumber(transaction_id); + baseMapper1.updateById(coursePackagePayment); + break; + } + if("USERPAYING".equals(s)){ + num++; + } + } + } + }catch (Exception e){ + e.printStackTrace(); + } + } + }).start(); + } + return weixinpay; } - public ResultUtil AlipayPayment(String code, ClasspaymentRequest request){ - BigDecimal amount = BigDecimal.ZERO; - if (request.getUseConpon() == 1){ - Coupon coupon = client.queryCouponById(request.getConponId()); - //TODO: 2023/7/11 课包购买的微信支付 - } - ResultUtil alipay = payMoneyUtil.alipay("课包购买", "", "", code, amount.toString(), - "/base/coursePackage/alipayNewPaymentCallback"); -// if(alipay.getCode() == 200){ -// new Thread(new Runnable() { -// @Override -// public void run() { -// try { -// int num = 1; -// int wait = 0; -// while (num <= 10){ -// int min = 5000; -// wait += (min * num); -// Thread.sleep(wait); -// TCoursePackagePayment coursePackagePayment = couPayClient.getCoursePackagePaymentByCode(code); -// if(coursePackagePayment.getPayStatus() == 2){ -// break; -// } -// ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryALIOrder(code); -// if(resultUtil.getCode() == 200 && coursePackagePayment.getPayStatus() == 1){ -// /** -// * WAIT_BUYER_PAY(交易创建,等待买家付款)、 -// * TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、 -// * TRADE_SUCCESS(交易支付成功)、 -// * TRADE_FINISHED(交易结束,不可退款) -// */ -// Map<String, String> data1 = resultUtil.getData(); -// String s = data1.get("tradeStatus"); -// String tradeNo = data1.get("tradeNo"); -// if("TRADE_CLOSED".equals(s) || "TRADE_FINISHED".equals(s) || num == 10){ -// coursePackagePayment.setState(3); -// couPayClient.delPaymentCoursePackage(coursePackagePayment.getId()); -// break; -// } -// if("TRADE_SUCCESS".equals(s)){ -// coursePackagePayment.setPayStatus(2); -// coursePackagePayment.setOrderNumber(tradeNo); -// couPayClient.updatePaymentCoursePackage(coursePackagePayment); -// break; -// } -// if("WAIT_BUYER_PAY".equals(s)){ -// num++; -// } -// } -// } -// }catch (Exception e){ -// e.printStackTrace(); -// } -// } -// }).start(); -// } + public ResultUtil AlipayPayment(String code, BigDecimal request){ + TCoursePackagePaymentMapper baseMapper1 = this.baseMapper; + ResultUtil alipay = payMoneyUtil.alipay("课包购买", "", "", code, request.toString(), + "/base/coursePackage/alipayRegisteredCoursesCallback"); + if(alipay.getCode() == 200){ + new Thread(new Runnable() { + @Override + public void run() { + try { + int num = 1; + int wait = 0; + while (num <= 10){ + int min = 5000; + wait += (min * num); + Thread.sleep(wait); + TCoursePackagePayment coursePackagePayment = baseMapper1.getCoursePackagePaymentByCode(code); + if(coursePackagePayment.getPayStatus() == 2){ + break; + } + ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryALIOrder(code); + if(resultUtil.getCode() == 200 && coursePackagePayment.getPayStatus() == 1){ + /** + * WAIT_BUYER_PAY(交易创建,等待买家付款)、 + * TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、 + * TRADE_SUCCESS(交易支付成功)、 + * TRADE_FINISHED(交易结束,不可退款) + */ + Map<String, String> data1 = resultUtil.getData(); + String s = data1.get("tradeStatus"); + String tradeNo = data1.get("tradeNo"); + if("TRADE_CLOSED".equals(s) || "TRADE_FINISHED".equals(s) || num == 10){ + coursePackagePayment.setState(3); + baseMapper1.deleteById(coursePackagePayment.getId()); + break; + } + if("TRADE_SUCCESS".equals(s)){ + coursePackagePayment.setPayStatus(2); + coursePackagePayment.setOrderNumber(tradeNo); + baseMapper1.updateById(coursePackagePayment); + break; + } + if("WAIT_BUYER_PAY".equals(s)){ + num++; + } + } + } + }catch (Exception e){ + e.printStackTrace(); + } + } + }).start(); + } return alipay; } - public void PlaypaiGoldPayment(String code, ClasspaymentRequest request){ + public ResultUtil PlaypaiGoldPayment(AppUser appUser,String code, Integer wpGold){ + TCoursePackagePayment packagePayment = this.baseMapper.selectOne(new QueryWrapper<TCoursePackagePayment>() + .eq("code",code )); + if (appUser.getPlayPaiCoins() < wpGold){ + return ResultUtil.error("玩牌币不足!"); + } + packagePayment.setPayStatus(2); + packagePayment.setPayUserId(appUser.getId()); + packagePayment.setPlayPaiCoin(wpGold); + this.baseMapper.updateById(packagePayment); + appUser.setPlayPaiCoins(ToolUtil.isNotEmpty(appUser.getPlayPaiCoins()) ? appUser.getPlayPaiCoins()-wpGold : wpGold); + appuClient.updateAppUser(appUser); + return ResultUtil.success(); } @@ -438,12 +584,10 @@ recordVo.setCourseStuRecordId(coursePackageStudent.getId()); String classWeeks = coursePackage.getClassWeeks(); String[] split = classWeeks.split(";"); - List<Integer> integerList = Arrays.stream(split) - .map(Integer::parseInt) - .collect(Collectors.toList()); - int dayOfWeek = DateTimeHelper.getDayOfWeek(new Date()); + List<String> integerList = Arrays.asList(split); + String weekOfDate = DateTimeHelper.getWeekOfDate(new Date()); - if (integerList.contains(dayOfWeek)){ + if (integerList.contains(weekOfDate)){ String dat = simpleDateFormat.format(date) +" "+ classStartTime; Date start = null; @@ -476,4 +620,17 @@ return recordVoList; } + @Override + public ResultUtil insertVipPaymentCallback(String code, String orderNumber) { + TCoursePackagePayment coursePackagePayment = this.baseMapper.getCoursePackagePaymentByCode(code); + if(coursePackagePayment.getPayStatus() != 1){ + return ResultUtil.success(); + } + coursePackagePayment.setPayStatus(2); + coursePackagePayment.setOrderNumber(orderNumber); + this.baseMapper.updateById(coursePackagePayment); + return ResultUtil.success(); + } + + } -- Gitblit v1.7.1