From 1aa309700fb7e12d85f98bed22a45bdac448ec1c Mon Sep 17 00:00:00 2001 From: liujie <liujie> Date: 星期六, 16 九月 2023 11:18:46 +0800 Subject: [PATCH] app 2.0 --- cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java | 350 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 310 insertions(+), 40 deletions(-) diff --git a/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java b/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java index 0934313..c350bf2 100644 --- a/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java +++ b/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java @@ -1,6 +1,9 @@ package com.dsh.course.controller; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.dsh.course.entity.*; @@ -8,19 +11,20 @@ import com.dsh.course.feignclient.account.StudentClient; import com.dsh.course.feignclient.account.model.AppUser; import com.dsh.course.feignclient.account.model.Student; +import com.dsh.course.feignclient.account.model.TCourseInfoRecord; import com.dsh.course.feignclient.model.*; import com.dsh.course.feignclient.other.StoreClient; import com.dsh.course.feignclient.other.model.Store; import com.dsh.course.model.BaseVo; import com.dsh.course.model.QueryRegistrationRecord; import com.dsh.course.model.QueryWalkInStudentList; +import com.dsh.course.model.BillingRequest; +import com.dsh.course.model.BillingRequestVo; import com.dsh.course.model.dto.DiscountJsonDto; import com.dsh.course.model.vo.CourseDetailRequest; import com.dsh.course.model.vo.RegisterCourseVo; import com.dsh.course.model.vo.request.*; -import com.dsh.course.model.vo.response.AppUserVideoResponse; -import com.dsh.course.model.vo.response.CourseDetailsResponse; -import com.dsh.course.model.vo.response.CourseOfVideoResponse; +import com.dsh.course.model.vo.response.*; import com.dsh.course.service.*; import com.dsh.course.util.*; import com.fasterxml.jackson.core.JsonProcessingException; @@ -33,7 +37,10 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @@ -88,6 +95,10 @@ @Autowired private CancelledClassesService cancelledClassesService; + @Resource + private CoursePackageStudentService cspsService; + + @Autowired private PayMoneyUtil payMoneyUtil; @Resource @@ -95,6 +106,13 @@ @Resource private StoreClient sreClient; + + @Autowired + private AppUserClient appUserClient; + + @Autowired + private RestTemplate internalRestTemplate; + private final SimpleDateFormat format = new SimpleDateFormat("MM-dd HH:mm"); @@ -149,28 +167,42 @@ .groupBy("coursePackageId")); if (list.size() > 0){ for (TCoursePackagePayment tCoursePackagePayment : list) { - TCoursePackage tCoursePackage = tcpService.getById(tCoursePackagePayment.getCoursePackageId()); - CoursePackagePaymentConfig paymentConfig = icppcService.getOne(new QueryWrapper<CoursePackagePaymentConfig>() - .eq("coursePackageId",tCoursePackage.getId() ) - .eq("classHours",tCoursePackagePayment.getClassHours())); + CoursePackageStudent packageStudent = cspsService.getOne(new LambdaQueryWrapper<CoursePackageStudent>() + .eq(CoursePackageStudent::getAppUserId, courseRest.getAppUserId()) + .eq(CoursePackageStudent::getStudentId,courseRest.getStuId()) + .eq(CoursePackageStudent::getCoursePackagePaymentId,tCoursePackagePayment.getId()) + .eq(CoursePackageStudent::getCoursePackageId,tCoursePackagePayment.getCoursePackageId())); + if (ToolUtil.isEmpty(packageStudent) || (ToolUtil.isNotEmpty(packageStudent) && packageStudent.getReservationStatus() != 1)){ +// 没有预约过的/已经取消了的 + TCoursePackage tCoursePackage = tcpService.getById(tCoursePackagePayment.getCoursePackageId()); + CoursePackagePaymentConfig paymentConfig = icppcService.getOne(new QueryWrapper<CoursePackagePaymentConfig>() + .eq("coursePackageId",tCoursePackage.getId() ) + .eq("classHours",tCoursePackagePayment.getClassHours())); // 获取课程有效结束时间,判断 查询的日期parse 是否在有效期范围内 - Date expirationDate = DateTimeHelper.getExpirationDate(tCoursePackagePayment.getInsertTime(),tCoursePackage.getValidDays()); - System.out.println(expirationDate.after(parse)); - String classWeeks = tCoursePackage.getClassWeeks(); - System.out.println(StrUtils.dealStrToList(classWeeks).contains(DateTimeHelper.getDayOfWeek(parse))); - if (expirationDate.after(parse) && StrUtils.dealStrToList(classWeeks).contains(DateTimeHelper.getDayOfWeek(parse))){ - CourseOfStoreVo storeVo = new CourseOfStoreVo(); - storeVo.setCourseId(tCoursePackage.getId()); - storeVo.setCourseName(tCoursePackage.getName()); - storeVo.setClassStartTime(tCoursePackage.getClassStartTime()); - storeVo.setClassEndTime(tCoursePackage.getClassEndTime()); - storeVo.setStoreId(tCoursePackage.getStoreId()); - Store store = sreClient.queryStoreById(tCoursePackage.getStoreId()); - storeVo.setStoreAddress(store.getAddress()); - storeVo.setLat(store.getLat()); - storeVo.setLon(store.getLon()); - storeVo.setCoursePrice(ToolUtil.isEmpty(paymentConfig.getCashPayment()) ? (double) paymentConfig.getPlayPaiCoin():paymentConfig.getCashPayment()); - course.add(storeVo); + Date expirationDate = DateTimeHelper.getExpirationDate(tCoursePackagePayment.getInsertTime(),tCoursePackage.getValidDays()); + System.out.println(expirationDate.after(parse)); + String classWeeks = tCoursePackage.getClassWeeks(); + System.out.println(StrUtils.dealStrToList(classWeeks).contains(DateTimeHelper.getDayOfWeek(parse))); + if (expirationDate.after(parse) && StrUtils.dealStrToList(classWeeks).contains(DateTimeHelper.getDayOfWeek(parse))){ + CourseOfStoreVo storeVo = new CourseOfStoreVo(); + storeVo.setCourseId(tCoursePackagePayment.getId()); + storeVo.setCourseName(tCoursePackage.getName()); + storeVo.setClassStartTime(tCoursePackage.getClassStartTime()); + storeVo.setClassEndTime(tCoursePackage.getClassEndTime()); + storeVo.setStoreId(tCoursePackage.getStoreId()); + Store store = sreClient.queryStoreById(tCoursePackage.getStoreId()); + storeVo.setStoreAddress(store.getAddress()); + storeVo.setLat(store.getLat()); + storeVo.setLon(store.getLon()); + storeVo.setCoursePrice(ToolUtil.isEmpty(paymentConfig.getCashPayment()) ? (double) paymentConfig.getPlayPaiCoin():paymentConfig.getCashPayment()); + storeVo.setStatus(1); + // 2.0 + storeVo.setAllNum(tCoursePackagePayment.getTotalClassHours()); + storeVo.setLastNum(tCoursePackagePayment.getLaveClassHours()); + storeVo.setUseNum(tCoursePackagePayment.getTotalClassHours()-tCoursePackagePayment.getLaveClassHours()); + + course.add(storeVo); + } } } } @@ -352,22 +384,36 @@ } @PostMapping("/base/coursePack/allPaymentCourseList") - public List<TCoursePackagePayment> getAppuserCourseList(@RequestBody Integer appUserId){ - return packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>() - .eq("appUserId",appUserId) - .eq("payType",3) - .eq("payStatus",2) - .eq("state",1)); + @ResponseBody + public List<CouponPaymentVo> getAppuserCourseList(@RequestBody Integer appUserId){ + List<CouponPaymentVo> paymentVos = new ArrayList<>(); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd HH:mm"); + List<TCoursePackagePayment> list = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>() + .eq("appUserId", appUserId) + .eq("payType", 3) + .eq("payStatus", 2) + .eq("state", 1)); + if (list.size() > 0 ){ + for (TCoursePackagePayment tCoursePackagePayment : list) { + CouponPaymentVo couponPaymentVo = new CouponPaymentVo(); + couponPaymentVo.setTime(simpleDateFormat.format(tCoursePackagePayment.getInsertTime())); + couponPaymentVo.setAmount( tCoursePackagePayment.getPlayPaiCoin()); + paymentVos.add(couponPaymentVo); + } + } + return paymentVos; } + + @ResponseBody @PostMapping("/base/coursePack/allAmountPayRecordOfUser") - public List<TCoursePackagePayment> getAmountPayRecord(@RequestBody BillingDataRequestVo billingDataRequestVo){ - return packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>() - .eq("appUserId",billingDataRequestVo.getAppUserId()) - .notIn("payType",3) - .eq("payStatus",2) - .eq("state",1) - .between("insertTime",billingDataRequestVo.getMonthStart(),billingDataRequestVo.getMonthEnd())); + public BillingRequestVo getAmountPayRecord(@RequestBody BillingDataRequestVo billingDataRequestVo){ + BillingRequestVo requestVo = new BillingRequestVo(); + List<BillingRequest> billingRequests = packagePaymentService.queryAmountDatas(billingDataRequestVo.getAppUserId(), billingDataRequestVo.getMonthStart(), billingDataRequestVo.getMonthEnd()); + if (billingRequests.size() >0){ + requestVo.setRequests(billingRequests); + } + return requestVo; } @@ -448,6 +494,59 @@ return ResultUtil.tokenErr(); } return ResultUtil.success(packagePaymentService.queryVideoDetails(detailsRequest,appUserId)); + }catch (Exception e){ + return ResultUtil.runErr(); + } + } + + + @ResponseBody + @PostMapping("/api/startCource/payCourseInfo") + @ApiOperation(value = "课后练习-购课详情(用于购课)", tags = {"APP-开始上课"}) + @ApiImplicitParams({ + @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), + }) + public ResultUtil<PayCourseInfoReq> payCourseInfo(Integer courseId){ + try { + return ResultUtil.success(packagePaymentService.payCourseInfo(courseId)); + }catch (Exception e){ + return ResultUtil.runErr(); + } + } + + + @ResponseBody + @PostMapping("/api/startCource/getMyCourseList") + @ApiOperation(value = "课后练习-可支付课程列表(用于购课)", tags = {"APP-开始上课"}) + @ApiImplicitParams({ + @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), + }) + public ResultUtil<List<PayCourseRes>> getMyCourseList(Integer storeId){ + try { + Integer appUserId = tokenUtil.getUserIdFormRedis(); + if(null == appUserId){ + return ResultUtil.tokenErr(); + } + return ResultUtil.success(packagePaymentService.getMyCourseList(storeId,appUserId)); + }catch (Exception e){ + return ResultUtil.runErr(); + } + } + + // 2.0 + @ResponseBody + @PostMapping("/api/startCource/payCourse") + @ApiOperation(value = "课后练习-确认购课", tags = {"APP-开始上课"}) + @ApiImplicitParams({ + @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), + }) + public ResultUtil<?> payCourse(@RequestBody PayCourseReq req){ + try { + Integer appUserId = tokenUtil.getUserIdFormRedis(); + if(null == appUserId){ + return ResultUtil.tokenErr(); + } + return packagePaymentService.payCourse(req,appUserId); }catch (Exception e){ return ResultUtil.runErr(); } @@ -641,6 +740,22 @@ return 0; } } + /** + * 获取学员剩余课时 + * @param id + * @return + */ + @ResponseBody + @PostMapping("/coursePackagePayment/queryResidueClassHourById") + public Integer queryResidueClassHourById(@RequestBody Long id){ + try { + TCoursePackagePayment list = packagePaymentService.getById(id); + return list.getLaveClassHours(); + }catch (Exception e){ + e.printStackTrace(); + return 0; + } + } /** @@ -651,13 +766,31 @@ @PostMapping("/coursePackagePayment/paymentDeductionClassHour") public void paymentDeductionClassHour(@RequestBody PaymentDeductionClassHour paymentDeductionClassHour){ try { - List<TCoursePackagePayment> list = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>().eq("studentId", paymentDeductionClassHour.getId()).eq("payStatus", 2) + // 2.0 用id进行查询 + List<TCoursePackagePayment> list = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>().eq("id", paymentDeductionClassHour.getCourseId()).eq("payStatus", 2) .eq("status", 1).eq("state", 1).gt("laveClassHours", 0)); Integer classHour = paymentDeductionClassHour.getClassHour(); for (TCoursePackagePayment coursePackagePayment : list) { if(coursePackagePayment.getLaveClassHours().compareTo(classHour) >= 0){ coursePackagePayment.setLaveClassHours(coursePackagePayment.getLaveClassHours() - classHour); packagePaymentService.updateById(coursePackagePayment); + + // 2.0 少于3课时 推送 + if(coursePackagePayment.getLaveClassHours()<=3){ + Integer appUserId = coursePackagePayment.getAppUserId(); + + //调用推送 + HttpHeaders headers = new HttpHeaders(); + // 以表单的方式提交 + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + String s1 = appUserId + "_" + "Three"; + //定时修改排课状态 + String s = internalRestTemplate.getForObject("http://mb-cloud-gateway/netty/sendMsgToClient?id="+s1, String.class); + JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class); + if(jsonObject1.getIntValue("code") != 200){ + System.err.println(jsonObject1.getString("msg")); + } + } CancelledClasses cancelledClasses = new CancelledClasses(); cancelledClasses.setType(2); @@ -713,6 +846,42 @@ /** + * 找出符合门店的课包 + * @param s + * @return + */ + @ResponseBody + @PostMapping("/coursePackagePayment/paymentCompetitionCourseList") + public List<PayCourseRes> paymentCompetitionCourseList(@RequestBody String s){ + ArrayList<PayCourseRes> objects = new ArrayList<>(); + + String[] split = s.split("_"); + // 用户id + Integer integer = Integer.valueOf(split[0]); + String s1 = split[1]; + // 门店id + String[] split1 = s1.split(","); + ArrayList<Integer> storeIds = new ArrayList<>(); + for (String s2 : split1) { + storeIds.add(Integer.valueOf(s2)); + } + List<TCoursePackagePayment> list = packagePaymentService.list(new LambdaQueryWrapper<TCoursePackagePayment>().eq(TCoursePackagePayment::getAppUserId, integer).ge(TCoursePackagePayment::getLaveClassHours, 0).eq(TCoursePackagePayment::getStatus, 1).eq(TCoursePackagePayment::getState, 1)); + for (TCoursePackagePayment tCoursePackagePayment : list) { + Integer coursePackageId = tCoursePackagePayment.getCoursePackageId(); + TCoursePackage byId = tcpService.getById(coursePackageId); + if(storeIds.contains(byId.getStoreId())){ + PayCourseRes payCourseRes = new PayCourseRes(); + payCourseRes.setCourseNum(tCoursePackagePayment.getLaveClassHours()); + payCourseRes.setId(tCoursePackagePayment.getId()); + payCourseRes.setName(byId.getName()); + objects.add(payCourseRes); + } + } + return objects; + } + + + /** * 课包续费玩湃币支付 * @param */ @@ -740,6 +909,16 @@ appUser.setPlayPaiCoins(appUser.getPlayPaiCoins()-paymentConfig.getPlayPaiCoin()); auClitn.updateAppUser(appUser); + + // 2.0 + TCourseInfoRecord tCourseInfoRecord = new TCourseInfoRecord(); + tCourseInfoRecord.setUserId(userIdFormRedis); + tCourseInfoRecord.setCourseId(coursePackage.getCoursePackageId()); + tCourseInfoRecord.setName("续课"); + tCourseInfoRecord.setTime(new Date()); + tCourseInfoRecord.setType(1); + tCourseInfoRecord.setNum(paymentConfig.getClassHours()); + auClitn.addCourseInfoRecord(tCourseInfoRecord); } catch (Exception e) { return 4; } @@ -758,12 +937,25 @@ } @PostMapping("/base/coursePack/updatePaymentCoursePackage") public boolean updatePaymentCoursePackage(@RequestBody TCoursePackagePayment packagePayment){ - return packagePaymentService.update(packagePayment,new QueryWrapper<TCoursePackagePayment>() - .eq("id",packagePayment.getId())); + boolean id = packagePaymentService.update(packagePayment, new QueryWrapper<TCoursePackagePayment>() + .eq("id", packagePayment.getId())); + if(id){ + // 2.0 + TCourseInfoRecord tCourseInfoRecord = new TCourseInfoRecord(); + tCourseInfoRecord.setNum(packagePayment.getTotalClassHours()); + tCourseInfoRecord.setName("续课"); + tCourseInfoRecord.setCourseId(packagePayment.getCoursePackageId()); + tCourseInfoRecord.setUserId(packagePayment.getAppUserId()); + tCourseInfoRecord.setType(1); + tCourseInfoRecord.setTime(new Date()); + id = appUserClient.addCourseInfoRecord(tCourseInfoRecord); + } + return id; } @PostMapping("/base/coursePack/savePaymentCoursePackage") public boolean savePaymentCoursePackage(@RequestBody TCoursePackagePayment packagePayment){ + packagePayment.setInsertTime(new Date()); return packagePaymentService.save(packagePayment); } @@ -793,6 +985,27 @@ .eq("code",code)); } + + // 2.0 送课时 + @PostMapping("/base/coursePack/sendHours") + public Boolean sendHours(@RequestBody String s){ + String[] split = s.split("_"); + TCoursePackagePayment byId = packagePaymentService.getById(Integer.valueOf(split[0])); + byId.setTotalClassHours(byId.getTotalClassHours()+Integer.valueOf(split[2])); + return packagePaymentService.updateById(byId); + } + + + /** + * 查询课时 + * @param courseConfigId + * @return + */ + @PostMapping("/base/coursePack/getClassHour") + public Integer getClassHour(@RequestBody Integer courseConfigId){ + CoursePackagePaymentConfig byId = icppcService.getById(courseConfigId); + return byId.getClassHours(); + } /** * 获取课包报名信息列表 @@ -843,4 +1056,61 @@ public void editCoursePackagePayment(TCoursePackagePayment coursePackagePayment){ packagePaymentService.updateById(coursePackagePayment); } + + + /** + * 上课主页-预约操作 + */ + @ResponseBody + @PostMapping("/api/startCource/reverse") + @ApiOperation(value = "上课主页-预约操作--2.0改请假操作", tags = {"APP-开始上课"}) + @ApiImplicitParams({ + @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), + @ApiImplicitParam(value = "课包id", name = "courseID", required = true, dataType = "String"), + @ApiImplicitParam(value = "时间 yyyy-MM-dd", name = "time", required = true, dataType = "String"), + @ApiImplicitParam(value = "学员id", name = "stuId", required = true, dataType = "int"), + }) + public ResultUtil reverse(String courseID,String time,Integer stuId){ + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + try { + Integer appUserId = tokenUtil.getUserIdFormRedis(); + if(null == appUserId){ + return ResultUtil.tokenErr(); + } + TCoursePackagePayment packagePayment = packagePaymentService.getOne(new LambdaQueryWrapper<TCoursePackagePayment>() + .eq(TCoursePackagePayment::getCoursePackageId,courseID ) + .eq(TCoursePackagePayment::getAppUserId,appUserId) + .eq(TCoursePackagePayment::getStudentId,stuId) + ); + + if (ToolUtil.isEmpty(packagePayment)){ + return ResultUtil.error("该用户未购买该课包"); + } + CoursePackageStudent coursePackageStudent = cspsService.getOne(new LambdaQueryWrapper<CoursePackageStudent>() + .eq(CoursePackageStudent::getCoursePackageId,packagePayment.getCoursePackageId()) + .eq(CoursePackageStudent::getCoursePackagePaymentId,courseID) + .eq(CoursePackageStudent::getStudentId,stuId) + .eq(CoursePackageStudent::getAppUserId,appUserId) + ); + + if (ToolUtil.isNotEmpty(coursePackageStudent) && coursePackageStudent.getReservationStatus() == 0){ + coursePackageStudent.setSignInOrNot(2); + coursePackageStudent.setInsertTime(simpleDateFormat.parse(time)); + cspsService.updateById(coursePackageStudent); + }else { + coursePackageStudent = new CoursePackageStudent(); + coursePackageStudent.setAppUserId(appUserId); + coursePackageStudent.setStudentId(stuId); + coursePackageStudent.setCoursePackageId(packagePayment.getCoursePackageId()); + coursePackageStudent.setCoursePackagePaymentId(Long.parseLong(courseID)); + coursePackageStudent.setSignInOrNot(2); + coursePackageStudent.setInsertTime(simpleDateFormat.parse(time)); + cspsService.save(coursePackageStudent); + } + return ResultUtil.success(); + }catch (Exception e){ + return ResultUtil.runErr(); + } + } + } -- Gitblit v1.7.1