| | |
| | | package com.dsh.course.service.impl; |
| | | |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alipay.api.domain.Person; |
| | | import com.alipay.api.response.AlipayTradeQueryResponse; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.dsh.course.entity.*; |
| | | import com.dsh.course.entity.TAppUser; |
| | | import com.dsh.course.entity.dto.StudentQeryDto; |
| | | import com.dsh.course.feignclient.account.AppUserClient; |
| | | import com.dsh.course.feignclient.account.CoachClient; |
| | | import com.dsh.course.feignclient.account.StudentClient; |
| | | import com.dsh.course.feignclient.account.model.AppUser; |
| | | import com.dsh.course.feignclient.account.model.Coach; |
| | | import com.dsh.course.feignclient.account.model.Student; |
| | | import com.dsh.course.feignclient.account.model.TCourseInfoRecord; |
| | | import com.dsh.course.feignclient.activity.BenefitVideoClient; |
| | | import com.dsh.course.feignclient.activity.CouponClient; |
| | | import com.dsh.course.feignclient.activity.model.BenefitsVideos; |
| | |
| | | import com.dsh.course.feignclient.other.StoreClient; |
| | | import com.dsh.course.feignclient.other.model.Store; |
| | | import com.dsh.course.mapper.*; |
| | | import com.dsh.course.model.*; |
| | | import com.dsh.course.model.dto.DiscountJsonDto; |
| | | import com.dsh.course.model.vo.RegisterCourseVo; |
| | | import com.dsh.course.model.vo.request.ClasspaymentRequest; |
| | | import com.dsh.course.model.vo.request.CourseOfAfterRequest; |
| | | import com.dsh.course.model.vo.request.CourseWithDetailsRequest; |
| | | import com.dsh.course.model.vo.request.UpdateCourseVideoStatusRequest; |
| | | 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.request.*; |
| | | import com.dsh.course.model.vo.response.*; |
| | | import com.dsh.course.service.CoursePackageSchedulingService; |
| | | import com.dsh.course.service.ICoursePackageSchedulingService; |
| | | import com.dsh.course.service.TCoursePackagePaymentService; |
| | | 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.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.persistence.criteria.CriteriaBuilder; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | |
| | | |
| | | @Resource |
| | | private BenefitVideoClient bfvoClient; |
| | | |
| | | |
| | | @Resource |
| | | private UserVideoDetailsMapper uvdmapper; |
| | |
| | | private TCoursePackageDiscountMapper tcpdMapper; |
| | | |
| | | @Resource |
| | | private CoursePackagePaymentConfigMapper cpConfigMapper; |
| | | |
| | | @Resource |
| | | private CouponClient client; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private PayMoneyUtil payMoneyUtil; |
| | | |
| | | @Resource |
| | | private AppUserClient appuClient; |
| | | |
| | | @Resource |
| | | private StudentClient studentClient; |
| | | |
| | | @Autowired |
| | | private ICoursePackageSchedulingService coursePackageSchedulingService; |
| | | |
| | | |
| | | @Autowired |
| | | private RestTemplate internalRestTemplate; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public List<CoursePackagePaymentVO> listAll(CoursePackagePaymentQuery query) { |
| | | return cpConfigMapper.listAll(query); |
| | | } |
| | | |
| | | @Override |
| | | public int changeState(CoursePackagePayDTO dto) { |
| | | List<String> ids = dto.getIds(); |
| | | List<Long> list = new ArrayList<>(); |
| | | for (String id : ids) { |
| | | long value = Long.parseLong(id); |
| | | list.add(value); |
| | | } |
| | | return cpConfigMapper.changeState(list,dto.getPayUserName(),dto.getUserId()); |
| | | } |
| | | |
| | | @Override |
| | | public void updateBytime(TCoursePackagePayment coursePackagePayment) { |
| | | this.baseMapper.updateBytime(coursePackagePayment); |
| | | } |
| | | |
| | | @Override |
| | | public List<RegisterOrderVO> listAllRegister(RegisterOrderQuery query) { |
| | | String STime = null; |
| | | String ETime = null; |
| | | if (StringUtils.hasLength(query.getRegisterTime())) { |
| | | STime = query.getRegisterTime().split(" - ")[0] + " 00:00:00"; |
| | | ETime = query.getRegisterTime().split(" - ")[1] + " 23:59:59"; |
| | | } |
| | | return cpConfigMapper.listAllRegister(query,STime,ETime,query.getAmount()); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getStudentTotal(StudentQeryDto studentQeryDto) { |
| | | List<Map<String, Object>> studentTotal = this.baseMapper.getStudentTotal(studentQeryDto); |
| | | |
| | | for (Map<String, Object> student : studentTotal) { |
| | | BigDecimal cashPayment = (BigDecimal) student.get("cashPayment"); |
| | | BigDecimal totalClassHours = (BigDecimal) student.get("totalClassHours"); |
| | | BigDecimal hasHours = (BigDecimal) student.get("hasHours"); |
| | | |
| | | BigDecimal hasPayment = cashPayment.divide(totalClassHours, 2, RoundingMode.HALF_UP) |
| | | .multiply(hasHours).setScale(2, RoundingMode.HALF_UP); |
| | | student.put("hasPayment", hasPayment); |
| | | |
| | | |
| | | Integer appUserId = (Integer) student.get("appUserId"); |
| | | AppUser appUser = appuClient.queryAppUser(appUserId); |
| | | student.put("province", appUser.getProvince()); |
| | | student.put("provinceCode", appUser.getProvinceCode()); |
| | | |
| | | student.put("city", appUser.getCity()); |
| | | student.put("cityCode", appUser.getCityCode()); |
| | | |
| | | Student studentId = studentClient.queryStudentById((Integer) student.get("studentId")); |
| | | student.put("studentName", studentId.getName()); |
| | | |
| | | |
| | | } |
| | | |
| | | if (studentQeryDto.getCityCode()!=null&&studentQeryDto.getCityCode()!="") { |
| | | String value = studentQeryDto.getCityCode(); |
| | | boolean allZeros = value.substring(value.length() - 4).endsWith("0000"); |
| | | System.out.println(allZeros); // Output: true |
| | | if (allZeros){ |
| | | Iterator<Map<String, Object>> iterator = studentTotal.iterator(); |
| | | while (iterator.hasNext()) { |
| | | Map<String, Object> student = iterator.next(); |
| | | String cityCode = (String) student.get("provinceCode"); |
| | | if (!cityCode.equals(studentQeryDto.getCityCode())) { |
| | | iterator.remove(); // Remove the element from the list |
| | | } |
| | | } |
| | | }else{ |
| | | Iterator<Map<String, Object>> iterator = studentTotal.iterator(); |
| | | while (iterator.hasNext()) { |
| | | Map<String, Object> student = iterator.next(); |
| | | String cityCode = (String) student.get("cityCode"); |
| | | if (!cityCode.equals(studentQeryDto.getCityCode())) { |
| | | iterator.remove(); // Remove the element from the list |
| | | } |
| | | }} |
| | | } |
| | | |
| | | if (studentQeryDto.getStudentName()!=null&&studentQeryDto.getStudentName()!=""){ |
| | | List<Map<String, Object>> totallike = new ArrayList<>(); |
| | | for (Map<String, Object> student : studentTotal) { |
| | | String studentName = (String) student.get("studentName"); |
| | | if (studentName.contains(studentQeryDto.getStudentName())){ |
| | | totallike.add(student); |
| | | } |
| | | |
| | | } |
| | | return totallike; |
| | | } |
| | | return studentTotal; |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> bypac(PacQueryDto pacQueryDto) { |
| | | if (pacQueryDto.getCityCode()!=null&&pacQueryDto.getCityCode()!=""){ |
| | | String value = pacQueryDto.getCityCode(); |
| | | boolean allZeros = value.substring(value.length() - 4).endsWith("0000"); |
| | | System.out.println(allZeros); // Output: true |
| | | |
| | | if (allZeros){ |
| | | pacQueryDto.setProvinceCode(pacQueryDto.getCityCode()); |
| | | pacQueryDto.setCityCode(null); |
| | | } |
| | | |
| | | } |
| | | List<Map<String, Object>> maps = this.baseMapper.pacQueryDto(pacQueryDto); |
| | | |
| | | if (pacQueryDto.getName()!=null&&pacQueryDto.getName()!=""){ |
| | | List<Map<String, Object>> totallike = new ArrayList<>(); |
| | | for (Map<String, Object> student : maps) { |
| | | String studentName = (String) student.get("name"); |
| | | if (studentName.contains(pacQueryDto.getName())){ |
| | | totallike.add(student); |
| | | } |
| | | |
| | | } |
| | | return totallike; |
| | | } |
| | | |
| | | |
| | | return maps; |
| | | } |
| | | |
| | | @Override |
| | | public List<TCoursePackagePayment> listOne(List<Integer> ids) { |
| | | return this.baseMapper.listOne(ids); |
| | | } |
| | | |
| | | @Override |
| | | public Integer listStoreId(String code) { |
| | | return this.baseMapper.queryStore(code); |
| | | } |
| | | |
| | | /** |
| | | * 获取课包购买人数 |
| | |
| | | @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>() |
| | |
| | | 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; |
| | |
| | | response.setPackageName(coursePackage.getName()); |
| | | response.setSynopsis(videosWithIds.getIntroduction()); |
| | | response.setDetailedDiagram(coursePackage.getIntroduceDrawing()); |
| | | response.setCover(videosWithIds.getCover()); |
| | | } |
| | | |
| | | return response; |
| | |
| | | uvdmapper.updateById(userVideoDetails); |
| | | return "SUCCESS"; |
| | | } |
| | | return null; |
| | | return "ERROR"; |
| | | } |
| | | |
| | | @Override |
| | |
| | | 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()); |
| | | Store store = stoClient.queryStoreById(coursePackage.getStoreId()); |
| | | RegisterCourseVo registerCourseVo = new RegisterCourseVo(); |
| | | registerCourseVo.setCoursePayId(tCoursePackagePayment.getId()); |
| | | registerCourseVo.setCoursePackageId(tCoursePackagePayment.getCoursePackageId()); |
| | | 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()); |
| | | List<CoursePackageStudent> coursePackageStudents = cpsMapper.selectList(new QueryWrapper<CoursePackageStudent>() |
| | | .eq("coursePackageId",coursePackage.getId()) |
| | | .eq("studentId",appUserId )); |
| | | registerCourseVo.setCourseNums(coursePackageStudents.size() * 2); |
| | | registerCourseVo.setPayStatus(tCoursePackagePayment.getPayStatus()); |
| | | courseVos.add(registerCourseVo); |
| | | try { |
| | | for (TCoursePackagePayment tCoursePackagePayment : tCoursePackagePayments) { |
| | | TCoursePackage coursePackage = tcpmapper.selectById(tCoursePackagePayment.getCoursePackageId()); |
| | | Store store = stoClient.queryStoreById(coursePackage.getStoreId()); |
| | | RegisterCourseVo registerCourseVo = new RegisterCourseVo(); |
| | | // 2.0 |
| | | registerCourseVo.setType(coursePackage.getType()); |
| | | |
| | | 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()); |
| | | // 2.0 |
| | | registerCourseVo.setCourseTime(new SimpleDateFormat("yyyy-MM-dd").format(tCoursePackagePayment.getInsertTime())); |
| | | Coach coach = coachClient.queryCoachById(coursePackage.getCoachId()); |
| | | registerCourseVo.setCourseTeacher(ToolUtil.isEmpty(coach) ? "" : coach.getName()); |
| | | List<CoursePackageStudent> coursePackageStudents = cpsMapper.selectList(new QueryWrapper<CoursePackageStudent>() |
| | | .eq("coursePackageId",coursePackage.getId()) |
| | | .eq("studentId",appUserId )); |
| | | if (coursePackageStudents.size() > 0 ){ |
| | | registerCourseVo.setCourseNums(coursePackageStudents.size() * 2); |
| | | } |
| | | registerCourseVo.setPayStatus(tCoursePackagePayment.getPayStatus()); |
| | | courseVos.add(registerCourseVo); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |
| | | @Override |
| | | public CourseDetailsResponse queryRegisteredCourseDetails(Integer coursePayId, Integer appUserId) { |
| | | public CourseDetailsResponse queryRegisteredCourseDetails(Long coursePayId, Integer appUserId) { |
| | | CourseDetailsResponse response = new CourseDetailsResponse(); |
| | | TCoursePackagePayment tCoursePackagePayment = this.baseMapper.selectById(coursePayId); |
| | | |
| | |
| | | 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()); |
| | |
| | | |
| | | Integer payType = tCoursePackagePayment.getPayType(); |
| | | BigDecimal cashPayment = tCoursePackagePayment.getCashPayment(); |
| | | double cashPaymentValue = cashPayment.doubleValue(); |
| | | double cashPaymentValue = 0.0; |
| | | if(cashPayment!=null){ |
| | | |
| | | cashPaymentValue = cashPayment.doubleValue(); |
| | | } |
| | | Integer playPaiCoin = tCoursePackagePayment.getPlayPaiCoin(); |
| | | TCoursePackageDiscount coursePackageDiscount = tcpdMapper.selectOne(new QueryWrapper<TCoursePackageDiscount>() |
| | | .eq("coursePackageId",coursePackage.getId() ) |
| | | .eq("type",1) |
| | | .eq("auditStatus",2)); |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | String content = coursePackageDiscount.getContent(); |
| | | double discountMember = 0.0; |
| | | DiscountJsonDto discountJsonDto = null; |
| | | try { |
| | | discountJsonDto = objectMapper.readValue(content, DiscountJsonDto.class); |
| | | discountMember = discountJsonDto.getDiscountMember(); |
| | | } catch (JsonProcessingException e) { |
| | | throw new RuntimeException(e); |
| | | if(coursePackageDiscount!=null){ |
| | | String content = coursePackageDiscount.getContent(); |
| | | DiscountJsonDto discountJsonDto = null; |
| | | try { |
| | | discountJsonDto = objectMapper.readValue(content, DiscountJsonDto.class); |
| | | discountMember = discountJsonDto.getDiscountMember(); |
| | | } catch (JsonProcessingException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | switch (payType) { |
| | | case 1: |
| | | case 2: |
| | |
| | | } |
| | | |
| | | @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); |
| | |
| | | } |
| | | 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; |
| | |
| | | } |
| | | |
| | | |
| | | 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(交易结束,不可退款) |
| | | // */ |
| | | 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; |
| | | } |
| | | AlipayTradeQueryResponse alipayTradeQueryResponse = payMoneyUtil.queryALIOrder(code); |
| | | |
| | | if(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(); |
| | | // } |
| | | String s = alipayTradeQueryResponse.getTradeStatus(); |
| | | String tradeNo = alipayTradeQueryResponse.getTradeNo(); |
| | | 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(); |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public List<RecordAppoint> obtainStuClassDetails(Integer stuId, Integer appUserId) { |
| | | public List<RecordAppoint> obtainStuClassDetails(Integer stuId, Integer appUserId,Integer pageNum) { |
| | | |
| | | |
| | | List<RecordAppoint> recordVoList = new ArrayList<>(); |
| | | List<TCoursePackagePayment> tCoursePackagePayments = this.baseMapper.selectList(new QueryWrapper<TCoursePackagePayment>() |
| | | .eq("studentId",stuId ) |
| | |
| | | .eq("payStatus",2 ) |
| | | .eq("status",1 ) |
| | | .orderByDesc("insertTime")); |
| | | |
| | | List<Integer> ids = new ArrayList<>(); |
| | | for (TCoursePackagePayment tCoursePackagePayment : tCoursePackagePayments) { |
| | | ids.add(tCoursePackagePayment.getCoursePackageId()); |
| | | } |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd"); |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm"); |
| | | if (tCoursePackagePayments.size() > 0 ){ |
| | | for (TCoursePackagePayment tCoursePackagePayment : tCoursePackagePayments) { |
| | | RecordAppoint recordVo = new RecordAppoint(); |
| | | recordVo.setCoursePackageId(tCoursePackagePayment.getCoursePackageId()); |
| | | |
| | | TCoursePackage coursePackage = tcpmapper.selectById(tCoursePackagePayment.getCoursePackageId()); |
| | | // int pageNum = 1; // 页码 |
| | | int pageSize = 5; // 每页记录数 |
| | | Page<CoursePackageStudent> page = new Page<>(1, pageSize); |
| | | |
| | | recordVo.setCoursePackageName(coursePackage.getName()); |
| | | recordVo.setCourseHours(tCoursePackagePayment.getClassHours()); |
| | | Date date = DateUtil.getDate(); |
| | | // for (TCoursePackagePayment tCoursePackagePayment : tCoursePackagePayments) { |
| | | // List<CoursePackageStudent> coursePackageStudent1 = cpsMapper.selectList(new QueryWrapper<CoursePackageStudent>() |
| | | // .in("coursePackageId",ids) |
| | | // .eq("studentId",stuId) |
| | | // .eq("appUserId",appUserId) |
| | | // .eq("reservationStatus",1)); |
| | | IPage<CoursePackageStudent> coursePackageStudentPage = cpsMapper.selectPage(page, new QueryWrapper<CoursePackageStudent>() |
| | | .in("coursePackageId", ids) |
| | | .eq("studentId", stuId) |
| | | .eq("appUserId", appUserId) |
| | | .eq("reservationStatus", 1)); |
| | | List<CoursePackageStudent> coursePackageStudent1 = coursePackageStudentPage.getRecords(); |
| | | |
| | | String classStartTime = coursePackage.getClassStartTime(); |
| | | String classEndTime = coursePackage.getClassEndTime(); |
| | | recordVo.setTimeFrame(simpleDateFormat.format(date)+" "+classStartTime+"-"+classEndTime); |
| | | Store store = stoClient.queryStoreById(coursePackage.getStoreId()); |
| | | recordVo.setStoreNameAddr(store.getName()+store.getAddress()); |
| | | CoursePackageStudent coursePackageStudent = cpsMapper.selectOne(new QueryWrapper<CoursePackageStudent>() |
| | | .eq("coursePackageId",tCoursePackagePayment.getCoursePackageId() ) |
| | | .eq("studentId",stuId) |
| | | .eq("appUserId",appUserId) |
| | | .eq("reservationStatus",1)); |
| | | if (ToolUtil.isNotEmpty(coursePackageStudent) && coursePackageStudent.getReservationStatus() == 1){ |
| | | |
| | | 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()); |
| | | if (ToolUtil.isNotEmpty(coursePackageStudent1) && coursePackageStudent1.size() > 0){ |
| | | TCoursePackage coursePackage = new TCoursePackage(); |
| | | Integer coursePackageId = -1; |
| | | for (CoursePackageStudent coursePackageStudent : coursePackageStudent1) { |
| | | RecordAppoint recordVo = new RecordAppoint(); |
| | | recordVo.setCoursePackageId(coursePackageStudent.getCoursePackageId()); |
| | | |
| | | if (integerList.contains(dayOfWeek)){ |
| | | String dat = simpleDateFormat.format(date) +" "+ classStartTime; |
| | | |
| | | Date start = null; |
| | | try { |
| | | start = format.parse(dat); |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException(e); |
| | | if (!coursePackageStudent.getCoursePackageId().equals(coursePackageId)) { |
| | | coursePackage = tcpmapper.selectById(coursePackageStudent.getCoursePackageId()); |
| | | coursePackageId = coursePackageStudent.getCoursePackageId(); |
| | | } |
| | | if (start.after(new Date())){ |
| | | recordVo.setStatus(1); |
| | | }else { |
| | | CancelledClasses cancelledClasses = cacMapper.selectOne(new QueryWrapper<CancelledClasses>() |
| | | .eq("coursePackageId",tCoursePackagePayment.getCoursePackageId() )); |
| | | if (ToolUtil.isNotEmpty(cancelledClasses)){ |
| | | recordVo.setStatus(3); |
| | | }else { |
| | | recordVo.setStatus(2); |
| | | |
| | | recordVo.setSid(Arrays.asList(coursePackage.getStoreId())); |
| | | List<Integer> rid = stoClient.querySiteId(coursePackage.getStoreId()); |
| | | recordVo.setRid(rid); |
| | | recordVo.setUserId(appUserId); |
| | | recordVo.setSiteId(coursePackage.getSiteId()); |
| | | List<Integer> ids1 = getIds(coursePackage.getSiteId()); |
| | | recordVo.setIds(ids1); |
| | | |
| | | recordVo.setCoursePackageName(coursePackage.getName()); |
| | | for (TCoursePackagePayment tCoursePackagePayment : tCoursePackagePayments) { |
| | | if (Objects.equals(coursePackageStudent.getCoursePackageId(), tCoursePackagePayment.getCoursePackageId())){ |
| | | recordVo.setCourseHours(tCoursePackagePayment.getClassHours()); |
| | | |
| | | } |
| | | } |
| | | }else { |
| | | recordVo.setStatus(1); |
| | | |
| | | // recordVo.setCourseHours(tCoursePackagePayment.getClassHours()); |
| | | Date date = DateUtil.getDate(); |
| | | |
| | | |
| | | CoursePackageScheduling byId = coursePackageSchedulingService.getById(coursePackageStudent.getCoursePackageSchedulingId()); |
| | | // String classStartTime = coursePackage.getClassStartTime(); |
| | | // String classEndTime = coursePackage.getClassEndTime(); |
| | | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String dateString1 = sdf.format(byId.getClassDate()); |
| | | String dateString2 = sdf.format(byId.getEndDate()); |
| | | |
| | | |
| | | recordVo.setTimeFrame(dateString1 + "-" + dateString2.substring(11)); |
| | | |
| | | // recordVo.setTimeFrame(simpleDateFormat.format(date)+" "+classStartTime+"-"+classEndTime); |
| | | Store store = stoClient.queryStoreById(coursePackage.getStoreId()); |
| | | recordVo.setStoreNameAddr(store.getName()+store.getAddress()); |
| | | recordVo.setCourseStuRecordId(coursePackageStudent.getId()); |
| | | String classWeeks = coursePackage.getClassWeeks(); |
| | | String[] split = classWeeks.split(";"); |
| | | List<String> integerList = Arrays.asList(split); |
| | | String weekOfDate = DateTimeHelper.getWeekOfDate(new Date()); |
| | | if (integerList.contains(weekOfDate)){ |
| | | String dat = simpleDateFormat.format(date) +" "+ dateString2.substring(11); |
| | | |
| | | Date start = null; |
| | | try { |
| | | start = format.parse(dat); |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | if (start.after(new Date())){ |
| | | recordVo.setStatus(1); |
| | | }else if(coursePackageStudent.getSignInOrNot()==2){ |
| | | recordVo.setStatus(5); |
| | | }else { |
| | | CancelledClasses cancelledClasses = cacMapper.selectOne(new QueryWrapper<CancelledClasses>() |
| | | .eq("coursePackageId",coursePackageStudent.getCoursePackageId() )); |
| | | if (ToolUtil.isNotEmpty(cancelledClasses)){ |
| | | recordVo.setStatus(3); |
| | | // 消课 到课状态0 旷课 |
| | | if(coursePackageStudent.getSignInOrNot()==0){ |
| | | recordVo.setStatus(6); |
| | | } |
| | | |
| | | }else { |
| | | recordVo.setStatus(2); |
| | | } |
| | | } |
| | | }else { |
| | | recordVo.setStatus(1); |
| | | } |
| | | recordVoList.add(recordVo); |
| | | } |
| | | |
| | | }else { |
| | | recordVo.setStatus(4); |
| | | // recordVo.setStatus(4); |
| | | } |
| | | |
| | | recordVoList.add(recordVo); |
| | | } |
| | | } |
| | | // } |
| | | |
| | | return recordVoList; |
| | | } |
| | | public List<Integer> getIds(Integer siteId) { |
| | | HttpRequest httpRequest = HttpRequest.get("https://try.daowepark.com/v7/user_api/general/get_space_area?space_id=" + siteId); |
| | | HttpResponse execute = httpRequest.execute(); |
| | | String body = execute.body(); |
| | | JSONObject jsonObject = JSONObject.parseObject(body); |
| | | Object data = jsonObject.get("data"); |
| | | JSONArray array = JSONArray.parseArray(data.toString()); |
| | | List<Integer> ids =new ArrayList<>(); |
| | | for (Object o : array) { |
| | | JSONObject jsonObject1 = JSONObject.parseObject(o.toString()); |
| | | Object id = jsonObject1.get("id"); |
| | | Integer integer = Integer.valueOf(id.toString()); |
| | | ids.add(integer); |
| | | } |
| | | return ids; |
| | | |
| | | } |
| | | @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(); |
| | | } |
| | | |
| | | @Override |
| | | public List<BillingRequest> queryAmountDatas(Integer appUserId, String monthStart, String monthEnd) { |
| | | return this.baseMapper.billingDataRequestVo(appUserId,monthStart,monthEnd); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取课包报名信息 |
| | | * @param page |
| | | * @param queryRegistrationRecord |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<Map<String, Object>> queryRegistrationRecord(Page<Map<String, Object>> page, QueryRegistrationRecord queryRegistrationRecord) { |
| | | Integer coursePackageId = queryRegistrationRecord.getCoursePackageId(); |
| | | String userName = queryRegistrationRecord.getUserName(); |
| | | List<Integer> userIds = null; |
| | | List<Integer> studentIds = null; |
| | | if(ToolUtil.isNotEmpty(userName)){ |
| | | List<AppUser> appUsers = appuClient.queryAppUserListByName(userName); |
| | | if(appUsers.size() > 0){ |
| | | userIds = appUsers.stream().map(AppUser::getId).collect(Collectors.toList()); |
| | | } |
| | | } |
| | | String studentName = queryRegistrationRecord.getStudentName(); |
| | | if(ToolUtil.isNotEmpty(studentName)){ |
| | | List<Student> students = studentClient.queryStudentListByName(studentName); |
| | | if(students.size() > 0){ |
| | | studentIds = students.stream().map(Student::getId).collect(Collectors.toList()); |
| | | } |
| | | } |
| | | List<Map<String, Object>> list = this.baseMapper.queryRegistrationRecord(page, coursePackageId, userIds, studentIds); |
| | | for (Map<String, Object> map : list) { |
| | | |
| | | Long id = Long.valueOf(map.get("id").toString()); |
| | | Integer appUserId = Integer.valueOf(map.get("appUserId").toString()); |
| | | Integer studentId = Integer.valueOf(map.get("studentId").toString()); |
| | | |
| | | TAppUser appUser = appuClient.queryAppUser1(appUserId); |
| | | map.put("userName", null != appUser ? appUser.getName() : ""); |
| | | map.put("phone", null != appUser ? appUser.getPhone() : ""); |
| | | Student student = studentClient.queryStudentById(studentId); |
| | | map.put("studentName", null != student ? student.getName() : ""); |
| | | Integer integer = cpsMapper.selectCount(new QueryWrapper<CoursePackageStudent>().eq("appUserId", appUserId) |
| | | .eq("studentId", studentId).eq("coursePackagePaymentId", id).eq("signInOrNot", 2)); |
| | | map.put("already", integer); |
| | | // if (student != null && student.getName().equals("杨锴1")) { |
| | | // map.put("totalClassHours", "测试"); |
| | | // } |
| | | ; |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取未预约排课学员列表 |
| | | * @param page |
| | | * @param queryWalkInStudentList |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<Map<String, Object>> queryWalkInStudentList(Page<Map<String, Object>> page, QueryWalkInStudentList queryWalkInStudentList) { |
| | | Long coursePackageSchedulingId = queryWalkInStudentList.getCoursePackageSchedulingId(); |
| | | CoursePackageScheduling coursePackageScheduling = coursePackageSchedulingService.getById(coursePackageSchedulingId); |
| | | String userName = queryWalkInStudentList.getUserName(); |
| | | List<Integer> userIds = null; |
| | | List<Integer> studentIds = null; |
| | | if(ToolUtil.isNotEmpty(userName)){ |
| | | List<AppUser> appUsers = appuClient.queryAppUserListByName(userName); |
| | | if(appUsers.size() > 0){ |
| | | userIds = appUsers.stream().map(AppUser::getId).collect(Collectors.toList()); |
| | | } |
| | | } |
| | | String studentName = queryWalkInStudentList.getStudentName(); |
| | | if(ToolUtil.isNotEmpty(studentName)){ |
| | | List<Student> students = studentClient.queryStudentListByName(studentName); |
| | | if(students.size() > 0){ |
| | | studentIds = students.stream().map(Student::getId).collect(Collectors.toList()); |
| | | } |
| | | } |
| | | List<Long> coursePackagePaymentId = null; |
| | | List<CoursePackageStudent> coursePackageStudents = cpsMapper.selectList(new QueryWrapper<CoursePackageStudent>().eq("coursePackageSchedulingId", coursePackageSchedulingId).eq("reservationStatus", 1)); |
| | | if(coursePackageStudents.size() > 0){ |
| | | coursePackagePaymentId = coursePackageStudents.stream().map(CoursePackageStudent::getCoursePackagePaymentId).collect(Collectors.toList()); |
| | | } |
| | | |
| | | List<Map<String, Object>> list = this.baseMapper.queryWalkInStudentList(page, coursePackageScheduling.getCoursePackageId(), coursePackagePaymentId, userIds, studentIds); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy"); |
| | | Integer now = Integer.valueOf(sdf.format(new Date())); |
| | | for (Map<String, Object> map : list) { |
| | | Integer appUserId = Integer.valueOf(map.get("appUserId").toString()); |
| | | Integer student_Id = Integer.valueOf(map.get("studentId").toString()); |
| | | AppUser appUser = appuClient.queryAppUser(appUserId); |
| | | Student student = studentClient.queryStudentById(student_Id); |
| | | map.put("userName", appUser.getName()); |
| | | map.put("phone", student.getPhone()); |
| | | map.put("studentName", student.getName()); |
| | | map.put("age", null != student.getBirthday() ? now - Integer.valueOf(sdf.format(student.getBirthday())) : "-"); |
| | | map.put("sex", student.getSex()); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public List<PayCourseRes> getMyCourseList(Integer storeId, Integer appUserId) { |
| | | // 找到购买的课包 |
| | | List<TCoursePackagePayment> tCoursePackagePayments = this.baseMapper.selectList(new LambdaQueryWrapper<TCoursePackagePayment>().eq(TCoursePackagePayment::getAppUserId, appUserId)); |
| | | ArrayList<PayCourseRes> payCourseRes = new ArrayList<>(); |
| | | for (TCoursePackagePayment tCoursePackagePayment : tCoursePackagePayments) { |
| | | TCoursePackage tCoursePackage = tcpmapper.selectById(tCoursePackagePayment.getCoursePackageId()); |
| | | if(tCoursePackage.getStoreId().equals(storeId)){ |
| | | PayCourseRes payCourseRes1 = new PayCourseRes(); |
| | | payCourseRes1.setId(tCoursePackagePayment.getId()); |
| | | payCourseRes1.setName(tCoursePackage.getName()); |
| | | payCourseRes1.setCourseNum(tCoursePackagePayment.getLaveClassHours()); |
| | | payCourseRes.add(payCourseRes1); |
| | | |
| | | } |
| | | } |
| | | return payCourseRes; |
| | | } |
| | | |
| | | @Override |
| | | public PayCourseInfoReq payCourseInfo(Integer courseId){ |
| | | PayCourseInfoReq payCourseInfoReq = new PayCourseInfoReq(); |
| | | TCoursePackage tCoursePackage = tcpmapper.selectById(courseId); |
| | | payCourseInfoReq.setId(courseId); |
| | | payCourseInfoReq.setName(tCoursePackage.getName()); |
| | | payCourseInfoReq.setNum(tCoursePackage.getNeedNum()); |
| | | payCourseInfoReq.setWeek(tCoursePackage.getClassWeeks()); |
| | | String classStartTime = tCoursePackage.getClassStartTime(); |
| | | String classEndTime = tCoursePackage.getClassEndTime(); |
| | | String[] split = classStartTime.split(","); |
| | | String[] split1 = classEndTime.split(","); |
| | | ArrayList<String> strings = new ArrayList<>(); |
| | | for (int i = 0; i < classStartTime.split(",").length; i++) { |
| | | String s = split[i] + "-" + split1[i]; |
| | | strings.add(s); |
| | | } |
| | | payCourseInfoReq.setTime(strings); |
| | | List<Integer> week = week(tCoursePackage.getClassWeeks()); |
| | | |
| | | // 今天周几 |
| | | int i = cn.hutool.core.date.DateUtil.dayOfWeek(new Date())-1; |
| | | |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd"); |
| | | ArrayList<String> strings1 = new ArrayList<>(); |
| | | |
| | | for (Integer integer : week) { |
| | | if(integer<i){ |
| | | // 找下一周的时间 |
| | | Calendar instance = Calendar.getInstance(); |
| | | instance.add(Calendar.DATE,7-(i-integer)); |
| | | Date time = instance.getTime(); |
| | | strings1.add(format.format(time)); |
| | | |
| | | }else if(integer>i) { |
| | | Calendar instance = Calendar.getInstance(); |
| | | instance.add(Calendar.DATE,integer-i); |
| | | Date time = instance.getTime(); |
| | | strings1.add(format.format(time)); |
| | | }else { |
| | | Calendar instance = Calendar.getInstance(); |
| | | instance.add(Calendar.DATE,7); |
| | | Date time = instance.getTime(); |
| | | strings1.add(format.format(time)); |
| | | } |
| | | } |
| | | payCourseInfoReq.setDay(strings1); |
| | | return payCourseInfoReq; |
| | | } |
| | | private static List<Integer> week(String week){ |
| | | String[] split = week.split(";"); |
| | | ArrayList<Integer> integers = new ArrayList<>(); |
| | | for (String s : split) { |
| | | switch (s){ |
| | | case "周一": |
| | | integers.add(1); |
| | | break; |
| | | case "周二": |
| | | integers.add(2); |
| | | break; |
| | | case "周三": |
| | | integers.add(3); |
| | | break; |
| | | case "周四": |
| | | integers.add(4); |
| | | break; |
| | | case "周五": |
| | | integers.add(5); |
| | | break; |
| | | case "周六": |
| | | integers.add(6); |
| | | break; |
| | | case "周日": |
| | | integers.add(7); |
| | | break; |
| | | } |
| | | } |
| | | return integers; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW) |
| | | public ResultUtil payCourse(PayCourseReq req,Integer userId){ |
| | | // 扣除 原来的课时数 |
| | | // 添加购买课时 paytyoe为7 |
| | | // 排课可期 判断课程时间段 添加排课表 添加上课记录表 |
| | | // 找到原来的课包 扣课时 |
| | | TCoursePackagePayment tCoursePackagePayment = this.baseMapper.selectById(req.getOldCourseId()); |
| | | if(req.getNum()>tCoursePackagePayment.getLaveClassHours()){ |
| | | return ResultUtil.error("当前课包课时数不足"); |
| | | } |
| | | tCoursePackagePayment.setLaveClassHours(tCoursePackagePayment.getLaveClassHours()-req.getNum()); |
| | | this.baseMapper.updateHoursById(tCoursePackagePayment.getId(),-req.getNum()); |
| | | |
| | | |
| | | TCoursePackage tCoursePackage = tcpmapper.selectById(req.getCourseId()); |
| | | // 添加课包 |
| | | TCoursePackagePayment tCoursePackagePayment1 = new TCoursePackagePayment(); |
| | | tCoursePackagePayment1.setAppUserId(userId); |
| | | Student student = studentClient.queryDefaultStudent(userId); |
| | | // student ID |
| | | Integer sId=null; |
| | | if(student!=null){ |
| | | tCoursePackagePayment1.setStudentId(student.getId()); |
| | | sId=student.getId(); |
| | | } |
| | | tCoursePackagePayment1.setCoursePackageId(tCoursePackage.getId()); |
| | | tCoursePackagePayment1.setPayType(7); |
| | | tCoursePackagePayment1.setClassHours(req.getNum()); |
| | | tCoursePackagePayment1.setOriginalPrice(0.0); |
| | | tCoursePackagePayment1.setTotalClassHours(req.getNum()); |
| | | tCoursePackagePayment1.setLaveClassHours(req.getNum()); |
| | | tCoursePackagePayment1.setAbsencesNumber(0); |
| | | tCoursePackagePayment1.setPayUserType(1); |
| | | tCoursePackagePayment1.setPayStatus(2); |
| | | tCoursePackagePayment1.setPayUserId(userId); |
| | | tCoursePackagePayment1.setStatus(1); |
| | | tCoursePackagePayment1.setState(1); |
| | | tCoursePackagePayment1.setInsertTime(new Date()); |
| | | this.baseMapper.insert(tCoursePackagePayment1); |
| | | // 找出课包时间段 |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
| | | String classStartTime = tCoursePackage.getClassStartTime(); |
| | | String classEndTime = tCoursePackage.getClassEndTime(); |
| | | String[] split = classStartTime.split(","); |
| | | String[] split1 = classEndTime.split(","); |
| | | List<String> time = req.getTime(); |
| | | for (String s : time) { |
| | | for (int i = 0; i < split.length; i++) { |
| | | CoursePackageScheduling coursePackageScheduling = new CoursePackageScheduling(); |
| | | coursePackageScheduling.setCoursePackageId(tCoursePackage.getId()); |
| | | try { |
| | | Date parse = format.parse(s + " " + split[i]); |
| | | Date parse1 = format.parse(s + " " + split1[i]); |
| | | coursePackageScheduling.setClassDate(parse); |
| | | coursePackageScheduling.setEndDate(parse1); |
| | | coursePackageScheduling.setStatus(1); |
| | | coursePackageSchedulingService.save(coursePackageScheduling); |
| | | |
| | | CoursePackageStudent student1 = new CoursePackageStudent(); |
| | | student1.setAppUserId(userId); |
| | | student1.setStudentId(sId); |
| | | student1.setCoursePackageId(tCoursePackage.getId()); |
| | | student1.setCoursePackagePaymentId(tCoursePackagePayment1.getId()); |
| | | student1.setCoursePackageSchedulingId(coursePackageScheduling.getId()); |
| | | student1.setSignInOrNot(1); |
| | | student1.setReservationStatus(1); |
| | | student1.setInsertTime(new Date()); |
| | | student1.setType(1); |
| | | cpsMapper.insert(student1); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | // 2.0 |
| | | TCourseInfoRecord tCourseInfoRecord = new TCourseInfoRecord(); |
| | | tCourseInfoRecord.setUserId(userId); |
| | | tCourseInfoRecord.setCourseId(req.getCourseId()); |
| | | tCourseInfoRecord.setName("体验购课"); |
| | | tCourseInfoRecord.setNum(req.getNum()); |
| | | tCourseInfoRecord.setTime(new Date()); |
| | | tCourseInfoRecord.setType(2); |
| | | appuClient.addCourseInfoRecord(tCourseInfoRecord); |
| | | |
| | | |
| | | if(tCoursePackagePayment.getLaveClassHours()<=3){ |
| | | Integer appUserId = userId; |
| | | |
| | | //调用推送 |
| | | 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")); |
| | | } |
| | | } |
| | | |
| | | return ResultUtil.success(); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void updateUseTime(Long id, Date date) { |
| | | this.baseMapper.updateUseTime(id,date); |
| | | } |
| | | |
| | | @Override |
| | | public List<Integer> getStudentIds(Long payId, Integer classId, Integer appId) { |
| | | return this.baseMapper.getStudentIds(payId,classId,appId); |
| | | } |
| | | |
| | | @Override |
| | | public boolean updateHoursById(TCoursePackagePayment byId, int i) { |
| | | return this.baseMapper.updateHoursById(byId.getId(),i); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |