nickchange
2023-11-09 c036557db88c6297b9a626a892dce35c14ab8ee5
cloud-server-course/src/main/java/com/dsh/course/service/impl/TCoursePackageServiceImpl.java
@@ -1,5 +1,6 @@
package com.dsh.course.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
@@ -35,6 +36,7 @@
import com.dsh.course.model.*;
import com.dsh.course.service.*;
import com.dsh.course.util.*;
import io.vertx.core.json.Json;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -43,6 +45,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Period;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
@@ -146,7 +149,14 @@
                wrapper.or().in("storeId", collect);
            }
        }
        List<TCoursePackage> list = this.list(wrapper.last(" order by sort desc, insertTime desc"));
        List<TCoursePackage> list1 = this.list(wrapper.last(" order by sort desc, insertTime desc"));
        Date currentTime = new Date();
// Filter the list based on the conditions
        List<TCoursePackage> list = list1.stream()
                .filter(coursePackage -> coursePackage.getType() != 2 || currentTime.before(coursePackage.getEndTime()))
                .collect(Collectors.toList());
        List<CoursePackageListVo> listVos = new ArrayList<>();
        for (TCoursePackage coursePackage : list) {
            Store store = storeClient.queryStoreById(coursePackage.getStoreId());
@@ -195,7 +205,7 @@
            //会员显示原价和会员价(最低)。非会员显示会员价和支付价(最低)
            if(appUser.getIsVip() == 0){//非会员
                List<TCoursePackageDiscount> list2 = coursePackageDiscountService.list(new QueryWrapper<TCoursePackageDiscount>().eq("coursePackagePaymentConfigId", coursePackagePaymentConfig.getId())
                        .eq("type", 1).eq("auditStatus", 2));
                        .eq("type", 1).eq("auditStatus", 2).eq("status",1));
                Double vipPrice = coursePackagePaymentConfig.getCashPayment();
                for (TCoursePackageDiscount coursePackageDiscount : list2) {
                    Double num1 = JSON.parseObject(coursePackageDiscount.getContent()).getDouble("discountMember");
@@ -207,7 +217,7 @@
                Double paymentPrice = coursePackagePaymentConfig.getCashPayment();
                List<TCoursePackageDiscount> list3 = coursePackageDiscountService.list(new QueryWrapper<TCoursePackageDiscount>().eq("coursePackagePaymentConfigId", coursePackagePaymentConfig.getId())
                        .eq("type", 3).eq("auditStatus", 2));
                        .eq("type", 3).eq("auditStatus", 2).eq("status",1));
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                for (TCoursePackageDiscount coursePackageDiscount : list3) {
                    /**
@@ -284,7 +294,7 @@
                coursePackageListVo.setPaymentPrice(paymentPrice);
            }else{
                List<TCoursePackageDiscount> list2 = coursePackageDiscountService.list(new QueryWrapper<TCoursePackageDiscount>().eq("coursePackagePaymentConfigId", coursePackagePaymentConfig.getId())
                        .eq("type", 1).eq("auditStatus", 2));
                        .eq("type", 1).eq("auditStatus", 2).eq("status",1));
                Double vipPrice = coursePackagePaymentConfig.getCashPayment();
                for (TCoursePackageDiscount coursePackageDiscount : list2) {
                    Double num1 = JSON.parseObject(coursePackageDiscount.getContent()).getDouble("discountMember");
@@ -302,21 +312,41 @@
        }
        //销量排行
        if(ToolUtil.isNotEmpty(coursePackageList.getSalesRanking())){
        if(ToolUtil.isNotEmpty(coursePackageList.getSalesRanking())&&coursePackageList.getSalesRanking().equals("asc")){
            Collections.sort(listVos, new Comparator<CoursePackageListVo>() {
                public int compare(CoursePackageListVo s1, CoursePackageListVo s2) {
                    return Integer.compare(s1.getApplicantsNumber(), s2.getApplicantsNumber());
                }
            });
        }
        if(ToolUtil.isNotEmpty(coursePackageList.getSalesRanking())&&coursePackageList.getSalesRanking().equals("desc")){
            Collections.sort(listVos, new Comparator<CoursePackageListVo>() {
                public int compare(CoursePackageListVo s1, CoursePackageListVo s2) {
                    return Integer.compare(s2.getApplicantsNumber(), s1.getApplicantsNumber());
                }
            });
        }
        //距离排行
        if(ToolUtil.isNotEmpty(coursePackageList.getDistanceSort())){
        if(ToolUtil.isNotEmpty(coursePackageList.getDistanceSort())&&coursePackageList.getDistanceSort().equals("asc")){
            Collections.sort(listVos, new Comparator<CoursePackageListVo>() {
                public int compare(CoursePackageListVo s1, CoursePackageListVo s2) {
                    return Double.compare(s1.getDistance(), s2.getDistance());
                }
            });
        }
        if (ToolUtil.isNotEmpty(coursePackageList.getDistanceSort())&&coursePackageList.getDistanceSort().equals("desc")) {
            Collections.sort(listVos, new Comparator<CoursePackageListVo>() {
                public int compare(CoursePackageListVo s1, CoursePackageListVo s2) {
                    return Double.compare(s2.getDistance(), s1.getDistance());
                }
            });
        }
        return listVos;
    }
@@ -358,7 +388,18 @@
            coursePackageListVo.setId(coursePackage.getId());
            coursePackageListVo.setName(coursePackage.getName());
            coursePackageListVo.setStoreName(null != store ? store.getName() : "");
//            coursePackageListVo.setPayType();
            coursePackageListVo.setCoverDrawing(coursePackage.getCoverDrawing());
            Double cashPayment1 = coursePackagePaymentConfig.getCashPayment();
            Integer playPaiCoin = coursePackagePaymentConfig.getPlayPaiCoin();
            if(ToolUtil.isNotEmpty(cashPayment1) && cashPayment1>0 && ToolUtil.isNotEmpty(playPaiCoin) && playPaiCoin>0){
                coursePackageListVo.setPayType(3);
            }else if(ToolUtil.isNotEmpty(cashPayment1) && cashPayment1>0){
                coursePackageListVo.setPayType(1);
            }else if(ToolUtil.isNotEmpty(playPaiCoin) && playPaiCoin>0){
                coursePackageListVo.setPayType(2);
            }
            // 2.0修改
            String classStartTime = coursePackage.getClassStartTime();
@@ -715,14 +756,10 @@
        //校验是否已经报满
        Integer integer = coursePackagePaymentService.queryCountNumber(paymentCourseVo.getId());
        TCoursePackage course = coursePackageService.getById(paymentCourseVo.getId());
        if (integer>=course.getMaxSubscribeNumber()){
        if (integer+paymentCourseVo.getStudentIds().split(";").length>course.getMaxSubscribeNumber()){
            return ResultUtil.error("报名失败,已达最大报名人数");
        }
        List<CoursePackagePaymentConfigVo> list = coursePackageInfo.getList();
        String[] students = paymentCourseVo.getStudentIds().split(";");
        for (CoursePackagePaymentConfigVo coursePackagePaymentConfigVo : list) {
            if(paymentCourseVo.getCoursePackagePaymentConfigId().compareTo(coursePackagePaymentConfigVo.getId()) == 0){
@@ -739,7 +776,6 @@
                if((cashPayment!=null || cashPayment>0) &&(playPaiCoin1!=null || playPaiCoin1>0)){
                    payType=3;
                }
                if(cashPayment!=null && cashPayment>0 && playPaiCoin1 !=null && playPaiCoin1>0){
                }else {
                    if(payType == 1 && paymentCourseVo.getPayType() == 3){//现金支付
@@ -749,12 +785,11 @@
                        return ResultUtil.error("支付方式错误,请刷新后重试");
                    }
                }
                Double paymentPrice = coursePackagePaymentConfigVo.getPaymentPrice();//支付价
                paymentPrice = new BigDecimal(students.length).multiply(new BigDecimal(paymentPrice)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
                Double playPaiCoin = coursePackagePaymentConfigVo.getPlayPaiCoin().doubleValue();//支付币
                playPaiCoin = new BigDecimal(students.length).multiply(new BigDecimal(playPaiCoin)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
                if(paymentCourseVo.getPayType() != 3 && paymentPrice.compareTo(paymentCourseVo.getPrice()) != 0){
                if(paymentCourseVo.getPayType() != 3 && paymentPrice.compareTo(paymentCourseVo.getPrice()) != 0&&paymentCourseVo.getCouponId()!=null){
                    return ResultUtil.error("支付金额异常,请刷新后重试");
                }
                if(paymentCourseVo.getPayType() == 3 && playPaiCoin.compareTo(paymentCourseVo.getPrice()) != 0){
@@ -762,9 +797,7 @@
                }
            }
        }
        Double price = paymentCourseVo.getPrice();//支付金额
        //校验优惠券
        Long couponId = paymentCourseVo.getCouponId();
        if(null != couponId && paymentCourseVo.getPayType() != 3){
@@ -850,6 +883,15 @@
            coursePackagePayment.setState(1);
            coursePackagePayment.setInsertTime(new Date());
            coursePackagePaymentService.save(coursePackagePayment);
            CourseCounsum courseCounsum = new CourseCounsum();
            courseCounsum.setPaymentId(coursePackagePayment.getId());
            courseCounsum.setChangeType(1);
            courseCounsum.setNum(coursePackagePaymentConfig.getClassHours());
            courseCounsum.setInsertTime(new Date());
            courseCounsum.setReason("购买课包");
            courseCounsumService.save(courseCounsum);
        }
        Student student = studentClient.queryDefaultStudent(uid);
@@ -905,7 +947,7 @@
                                    // 2.0
                                    userCouponClient.sendUserCoupon(new SendCouponReq(uid,coursePackagePaymentConfig.getCouponIds()));
                                    addPackageStudent(paymentCourseVo.getId(),uid, finalSid,one.getId());
                                    addPackageStudent(paymentCourseVo.getId(),uid, finalSid,one.getId(),null);
                                    break;
                                }
                                if("USERPAYING".equals(s)){
@@ -937,26 +979,109 @@
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
        for (String s : split) {
            TCoursePackagePayment coursePackagePayment = new TCoursePackagePayment();
            coursePackagePayment.setCode(code);
            coursePackagePayment.setAppUserId(uid);
            coursePackagePayment.setStudentId(Integer.valueOf(s));
            coursePackagePayment.setCoursePackageId(paymentCourseVo.getId());
            coursePackagePayment.setPayType(paymentCourseVo.getPayType());
            coursePackagePayment.setClassHours(coursePackagePaymentConfig.getClassHours());
            coursePackagePayment.setOriginalPrice(paymentCourseVo.getPrice());
            coursePackagePayment.setUserCouponId(paymentCourseVo.getCouponId());
            coursePackagePayment.setCashPayment(new BigDecimal(paymentPrice));
            coursePackagePayment.setTotalClassHours(coursePackagePaymentConfig.getClassHours());
            coursePackagePayment.setLaveClassHours(coursePackagePaymentConfig.getClassHours());
            coursePackagePayment.setAbsencesNumber(0);
            coursePackagePayment.setPayUserType(1);
            coursePackagePayment.setPayStatus(1);
            coursePackagePayment.setPayUserId(uid);
            coursePackagePayment.setStatus(1);
            coursePackagePayment.setState(1);
            coursePackagePayment.setInsertTime(new Date());
            coursePackagePaymentService.save(coursePackagePayment);
//            TCoursePackagePayment coursePackagePayment = new TCoursePackagePayment();
//            coursePackagePayment.setCode(code);
//            coursePackagePayment.setAppUserId(uid);
//            coursePackagePayment.setStudentId(Integer.valueOf(s));
//            coursePackagePayment.setCoursePackageId(paymentCourseVo.getId());
//            coursePackagePayment.setPayType(paymentCourseVo.getPayType());
//            coursePackagePayment.setClassHours(coursePackagePaymentConfig.getClassHours());
//            coursePackagePayment.setOriginalPrice(paymentCourseVo.getPrice());
//            coursePackagePayment.setUserCouponId(paymentCourseVo.getCouponId());
//            coursePackagePayment.setCashPayment(new BigDecimal(paymentPrice));
//            coursePackagePayment.setTotalClassHours(coursePackagePaymentConfig.getClassHours());
//            coursePackagePayment.setLaveClassHours(coursePackagePaymentConfig.getClassHours());
//            coursePackagePayment.setAbsencesNumber(0);
//            coursePackagePayment.setPayUserType(1);
//            coursePackagePayment.setPayStatus(1);
//            coursePackagePayment.setPayUserId(uid);
//            coursePackagePayment.setStatus(1);
//            coursePackagePayment.setState(1);
//            coursePackagePayment.setInsertTime(new Date());
//            coursePackagePaymentService.save(coursePackagePayment);
//
//
//            CourseCounsum courseCounsum = new CourseCounsum();
//            courseCounsum.setPaymentId(coursePackagePayment.getId());
//            courseCounsum.setChangeType(1);
//            courseCounsum.setNum(coursePackagePaymentConfig.getClassHours());
//            courseCounsum.setInsertTime(new Date());
//            courseCounsum.setReason("购买课包");
//            courseCounsumService.save(courseCounsum);
            TCoursePackagePayment coursePackagePaymentServiceOne = coursePackagePaymentService.getOne(new QueryWrapper<TCoursePackagePayment>().eq("studentId", s).eq("coursePackageId", paymentCourseVo.getId()));
            if (coursePackagePaymentServiceOne==null) {
                TCoursePackagePayment coursePackagePayment = new TCoursePackagePayment();
                coursePackagePayment.setCode(code);
                coursePackagePayment.setAppUserId(uid);
                coursePackagePayment.setStudentId(Integer.valueOf(s));
                coursePackagePayment.setCoursePackageId(paymentCourseVo.getId());
                coursePackagePayment.setPayType(paymentCourseVo.getPayType());
                coursePackagePayment.setClassHours(coursePackagePaymentConfig.getClassHours());
                coursePackagePayment.setOriginalPrice(paymentCourseVo.getPrice());
                coursePackagePayment.setPlayPaiCoin(paymentPrice.intValue());
                coursePackagePayment.setTotalClassHours(coursePackagePaymentConfig.getClassHours());
                coursePackagePayment.setLaveClassHours(coursePackagePaymentConfig.getClassHours());
                coursePackagePayment.setAbsencesNumber(0);
                coursePackagePayment.setPayUserType(1);
                coursePackagePayment.setPayStatus(1);
                coursePackagePayment.setPayUserId(uid);
                coursePackagePayment.setStatus(1);
                coursePackagePayment.setState(1);
                coursePackagePayment.setInsertTime(new Date());
                coursePackagePaymentService.save(coursePackagePayment);
                Integer sId = null;
                Student student = studentClient.queryDefaultStudent(uid);
                if (student != null) {
                    sId = student.getId();
                }
//                coursePackagePaymentServiceOne.setPlayPaiCoin(coursePackagePaymentServiceOne.getPlayPaiCoin()+paymentPrice.intValue());
//                addPackageStudent(paymentCourseVo.getId(), uid, Integer.valueOf(s), coursePackagePayment.getId());
                CourseCounsum courseCounsum = new CourseCounsum();
                courseCounsum.setPaymentId(coursePackagePayment.getId());
                courseCounsum.setChangeType(1);
                courseCounsum.setNum(coursePackagePaymentConfig.getClassHours());
                courseCounsum.setInsertTime(new Date());
                courseCounsum.setReason("购买课包");
                courseCounsumService.save(courseCounsum);
            }else {
                coursePackagePaymentServiceOne.setClassHours(coursePackagePaymentServiceOne.getClassHours()+coursePackagePaymentConfig.getClassHours());
                coursePackagePaymentServiceOne.setOriginalPrice(coursePackagePaymentServiceOne.getOriginalPrice()+paymentCourseVo.getPrice());
                coursePackagePaymentServiceOne.setPlayPaiCoin(coursePackagePaymentServiceOne.getPlayPaiCoin()+paymentPrice.intValue());
                coursePackagePaymentServiceOne.setTotalClassHours(coursePackagePaymentServiceOne.getTotalClassHours()+coursePackagePaymentConfig.getClassHours());
                coursePackagePaymentServiceOne.setLaveClassHours(coursePackagePaymentServiceOne.getLaveClassHours()+coursePackagePaymentConfig.getClassHours());
                coursePackagePaymentServiceOne.setCode(code);
                coursePackagePaymentServiceOne.setAppUserId(null);
                coursePackagePaymentServiceOne.setPayStatus(1);
                coursePackagePaymentService.updateById(coursePackagePaymentServiceOne);
//                coursePackagePaymentService.save(coursePackagePayment);
                Integer sId = null;
                Student student = studentClient.queryDefaultStudent(uid);
                if (student != null) {
                    sId = student.getId();
                }
                coursePackagePaymentServiceOne.setPlayPaiCoin(coursePackagePaymentServiceOne.getPlayPaiCoin()+paymentPrice.intValue());
//                addPackageStudent(paymentCourseVo.getId(), uid, Integer.valueOf(s), coursePackagePaymentServiceOne.getId());
                CourseCounsum courseCounsum = new CourseCounsum();
                courseCounsum.setPaymentId(coursePackagePaymentServiceOne.getId());
                courseCounsum.setChangeType(1);
                courseCounsum.setNum(coursePackagePaymentConfig.getClassHours());
                courseCounsum.setInsertTime(new Date());
                courseCounsum.setReason("续课");
                courseCounsumService.save(courseCounsum);
            }
        }
        Student student = studentClient.queryDefaultStudent(uid);
@@ -1016,8 +1141,15 @@
                                    userCouponClient.sendUserCoupon(new SendCouponReq(uid,coursePackagePaymentConfig.getCouponIds()));
                                    for (TCoursePackagePayment coursePackagePayment : list) {
                                        addPackageStudent(paymentCourseVo.getId(),uid, finalSid,coursePackagePayment.getId(),paymentCourseVo.getPrice());
                                    }
                                    moneyOut(tradeNo,tradeNo);
@@ -1025,7 +1157,6 @@
                                    if(student!=null){
                                    }
                                    addPackageStudent(paymentCourseVo.getId(),uid, finalSid,one.getId());
                                    break;
                                }
                                if("WAIT_BUYER_PAY".equals(s)){
@@ -1129,6 +1260,10 @@
    @Autowired
    private  CourseCounsumService courseCounsumService;
    /**
     * 玩湃币支付课程
@@ -1143,33 +1278,96 @@
        String[] split = paymentCourseVo.getStudentIds().split(";");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
        for (String s : split) {
            TCoursePackagePayment coursePackagePayment = new TCoursePackagePayment();
            coursePackagePayment.setCode(code);
            coursePackagePayment.setAppUserId(appUser.getId());
            coursePackagePayment.setStudentId(Integer.valueOf(s));
            coursePackagePayment.setCoursePackageId(paymentCourseVo.getId());
            coursePackagePayment.setPayType(paymentCourseVo.getPayType());
            coursePackagePayment.setClassHours(coursePackagePaymentConfig.getClassHours());
            coursePackagePayment.setOriginalPrice(paymentCourseVo.getPrice());
            coursePackagePayment.setPlayPaiCoin(paymentPrice.intValue());
            coursePackagePayment.setTotalClassHours(coursePackagePaymentConfig.getClassHours());
            coursePackagePayment.setLaveClassHours(coursePackagePaymentConfig.getClassHours());
            coursePackagePayment.setAbsencesNumber(0);
            coursePackagePayment.setPayUserType(1);
            coursePackagePayment.setPayStatus(2);
            coursePackagePayment.setPayUserId(appUser.getId());
            coursePackagePayment.setStatus(1);
            coursePackagePayment.setState(1);
            coursePackagePayment.setInsertTime(new Date());
            coursePackagePaymentService.save(coursePackagePayment);
            Integer sId=null;
            Student student = studentClient.queryDefaultStudent(appUser.getId());
            if(student!=null){
                sId=student.getId();
        //赠送课时
        int weekday = DateUtil.dayOfWeek(new Date()) - 1;
        TCoursePackageDiscount discount = coursePackageDiscountService.getOne(new QueryWrapper<TCoursePackageDiscount>().eq("type",4).eq("coursePackageId", paymentCourseVo.getId()).last("limit 1"));
        Integer hour = 0;
        if (discount!=null) {
            JSONArray objects = JSONObject.parseArray(discount.getContent());
            JSONObject parse = JSONObject.parseObject(JSONObject.toJSONString(objects.get(0)));
             hour = parse.getInteger("hour");
            if (hour == null) {
                hour = 0;
            }
            addPackageStudent(paymentCourseVo.getId(),appUser.getId(), Integer.valueOf(s),coursePackagePayment.getId());
        }
        for (String s : split) {
            TCoursePackagePayment coursePackagePaymentServiceOne = coursePackagePaymentService.getOne(new QueryWrapper<TCoursePackagePayment>().eq("studentId", s).eq("coursePackageId", paymentCourseVo.getId()));
            if (coursePackagePaymentServiceOne==null) {
                TCoursePackagePayment coursePackagePayment = new TCoursePackagePayment();
                coursePackagePayment.setCode(code);
                coursePackagePayment.setAppUserId(appUser.getId());
                coursePackagePayment.setStudentId(Integer.valueOf(s));
                coursePackagePayment.setCoursePackageId(paymentCourseVo.getId());
                coursePackagePayment.setPayType(paymentCourseVo.getPayType());
                coursePackagePayment.setClassHours(coursePackagePaymentConfig.getClassHours()+hour);
                coursePackagePayment.setOriginalPrice(paymentCourseVo.getPrice());
                coursePackagePayment.setPlayPaiCoin(paymentPrice.intValue());
                coursePackagePayment.setTotalClassHours(coursePackagePaymentConfig.getClassHours()+hour);
                coursePackagePayment.setLaveClassHours(coursePackagePaymentConfig.getClassHours()+hour);
                coursePackagePayment.setAbsencesNumber(0);
                coursePackagePayment.setPayUserType(1);
                coursePackagePayment.setPayStatus(2);
                coursePackagePayment.setPayUserId(appUser.getId());
                coursePackagePayment.setStatus(1);
                coursePackagePayment.setState(1);
                coursePackagePayment.setInsertTime(new Date());
                coursePackagePaymentService.save(coursePackagePayment);
                Integer sId = null;
                Student student = studentClient.queryDefaultStudent(appUser.getId());
                if (student != null) {
                    sId = student.getId();
                }
                addPackageStudent(paymentCourseVo.getId(), appUser.getId(), Integer.valueOf(s), coursePackagePayment.getId(),null);
                //课时记录
                CourseCounsum courseCounsum = new CourseCounsum();
                courseCounsum.setPaymentId(coursePackagePayment.getId());
                courseCounsum.setChangeType(1);
                courseCounsum.setNum(coursePackagePaymentConfig.getClassHours());
                courseCounsum.setInsertTime(new Date());
                courseCounsum.setReason("购买课包");
                courseCounsumService.save(courseCounsum);
            }else {
                coursePackagePaymentServiceOne.setClassHours(coursePackagePaymentServiceOne.getClassHours()+coursePackagePaymentConfig.getClassHours()+hour);
                coursePackagePaymentServiceOne.setOriginalPrice(coursePackagePaymentServiceOne.getOriginalPrice()+paymentCourseVo.getPrice());
                if (coursePackagePaymentServiceOne.getPlayPaiCoin()==null){
                    coursePackagePaymentServiceOne.setPlayPaiCoin(paymentPrice.intValue());
                }else {
                coursePackagePaymentServiceOne.setPlayPaiCoin(coursePackagePaymentServiceOne.getPlayPaiCoin()+paymentPrice.intValue());}
                coursePackagePaymentServiceOne.setTotalClassHours(coursePackagePaymentServiceOne.getTotalClassHours()+coursePackagePaymentConfig.getClassHours()+hour);
                coursePackagePaymentServiceOne.setLaveClassHours(coursePackagePaymentServiceOne.getLaveClassHours()+coursePackagePaymentConfig.getClassHours()+hour);
                coursePackagePaymentServiceOne.setAppUserId(null);
                coursePackagePaymentService.updateById(coursePackagePaymentServiceOne);
//                coursePackagePaymentService.save(coursePackagePayment);
                Integer sId = null;
                Student student = studentClient.queryDefaultStudent(appUser.getId());
                if (student != null) {
                    sId = student.getId();
                }
                addPackageStudent(paymentCourseVo.getId(), appUser.getId(), Integer.valueOf(s), coursePackagePaymentServiceOne.getId(),null);
                CourseCounsum courseCounsum = new CourseCounsum();
                courseCounsum.setPaymentId(coursePackagePaymentServiceOne.getId());
                courseCounsum.setChangeType(1);
                courseCounsum.setNum(coursePackagePaymentConfig.getClassHours());
                courseCounsum.setInsertTime(new Date());
                courseCounsum.setReason("续课");
                courseCounsumService.save(courseCounsum);
            }
        }
        Integer playPaiCoins = appUser.getPlayPaiCoins();
@@ -1189,235 +1387,167 @@
    private void addPackageStudent(Integer courseId, Integer userId, Integer sId,Long paymentId) throws ParseException {
    private void addPackageStudent(Integer courseId, Integer userId, Integer sId,Long paymentId,Double price) throws ParseException {
        // 课包
        TCoursePackage tCoursePackage = this.baseMapper.selectById(courseId);
        String classWeeks = tCoursePackage.getClassWeeks();
        List<Integer> week = week(classWeeks);
        if (tCoursePackage.getType()==1) {
            String classWeeks = tCoursePackage.getClassWeeks();
        String[] split = tCoursePackage.getClassStartTime().split(",");
        String[] split1 = tCoursePackage.getClassEndTime().split(",");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            List<Integer> week = week(classWeeks);
        //查出当前用户当前学员当前课包最后一天的排课数据
        List<CoursePackageStudent> studentCourse = coursePackageStudentService.list(new QueryWrapper<CoursePackageStudent>().eq("studentId", sId).eq("coursePackageId", courseId));
        List<Long> collect = studentCourse.stream().map(CoursePackageStudent::getCoursePackageSchedulingId).collect(Collectors.toList());
        //拿到最后一天的排课记录
            String[] split = tCoursePackage.getClassStartTime().split(",");
            String[] split1 = tCoursePackage.getClassEndTime().split(",");
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        CoursePackageScheduling cs = null;
        if (collect.size()>0) {
             cs = coursePackageSchedulingService.getOne(new QueryWrapper<CoursePackageScheduling>().in("id", collect).orderByDesc("classDate").last("limit 1"));
        }
        int i = -1;
//        Calendar calendar = Calendar.getInstance();
//        Date currentDate = calendar.getTime();
//        calendar.add(Calendar.DAY_OF_MONTH, -1);
//        Date today = calendar.getTime();
        Date today = new Date();
        //判断最后一天是否超过当前日期
        if (cs==null||cs.getClassDate().before(new Date())){
            i = DateUtil.dayOfWeek(new Date())-1;
        }else {
            i = DateUtil.dayOfWeek(cs.getClassDate())-1;
            today = cs.getClassDate();
        }
            //查出当前用户当前学员当前课包最后一天的排课数据
            List<CoursePackageStudent> studentCourse = coursePackageStudentService.list(new QueryWrapper<CoursePackageStudent>().eq("studentId", sId).eq("coursePackageId", courseId));
            List<Long> collect = studentCourse.stream().map(CoursePackageStudent::getCoursePackageSchedulingId).collect(Collectors.toList());
        TCoursePackagePayment pay = coursePackagePaymentService.getById(paymentId);
        Integer laveClassHours = pay.getLaveClassHours();
        Integer codeTime = tCoursePackage.getCodeTime();
        Integer can = 0;
        int count = 0;
            //拿到最后一天的排课记录
            if (collect.size() > 0){
                coursePackageSchedulingService.remove(new QueryWrapper<CoursePackageScheduling>().in("id", collect));
                coursePackageStudentService.remove(new QueryWrapper<CoursePackageStudent>().eq("studentId", sId).eq("coursePackageId", courseId));
                if (price!=null) {
                    CourseCounsum courseCounsum = new CourseCounsum();
                    courseCounsum.setPaymentId(paymentId);
                    courseCounsum.setChangeType(3);
                    courseCounsum.setInsertTime(new Date());
                    courseCounsum.setReason("续课;" + price);
                    courseCounsum.setAppUserId(userId);
                    courseCounsumService.save(courseCounsum);
                }
        // 本周周几
//        int i = DateUtil.dayOfWeek(new Date())-1;
            }else {
                if (price!=null) {
                    CourseCounsum courseCounsum = new CourseCounsum();
                    courseCounsum.setPaymentId(paymentId);
                    courseCounsum.setChangeType(3);
                    courseCounsum.setInsertTime(new Date());
                    courseCounsum.setReason("报名课程;" + price);
                    courseCounsum.setAppUserId(userId);
                    courseCounsumService.save(courseCounsum);
                }
            }
            Date today = new Date();
            TCoursePackagePayment pay = coursePackagePaymentService.getById(paymentId);
            Integer laveClassHours = pay.getLaveClassHours();
            Integer codeTime = tCoursePackage.getCodeTime();
            Integer can = 0;
            int count = 0;
            // 本周周几
            Date[] dates = generateDateArray(14, today);
            if (tCoursePackage.getType() == 1) {
                can = laveClassHours / codeTime;
            }
            if (tCoursePackage.getType() == 2) {
                Date startDate = tCoursePackage.getStartTime();
                Date endDate = tCoursePackage.getEndTime();
                dates = generateDateArray1(startDate, endDate);
                can = 999;
            }
            for (Date date : dates) {
                if (count == can) {
                    break;
                }
                int wei = DateUtil.dayOfWeek(date);
                if (week.contains(wei)) {
                    for (int i1 = 0; i1 < split.length; i1++) {
                        if (count == can) {
                            break;
                        }
                        CoursePackageScheduling coursePackageScheduling = new CoursePackageScheduling();
                        coursePackageScheduling.setCoursePackageId(tCoursePackage.getId());
                        Date parse = format1.parse(format.format(date) + " " + split[i1]);
                        Date parse1 = format1.parse(format.format(date) + " " + split1[i1]);
                        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(paymentId);
                        student1.setCoursePackageSchedulingId(coursePackageScheduling.getId());
                        student1.setSignInOrNot(1);
                        student1.setReservationStatus(1);
                        student1.setInsertTime(new Date());
                        cpsMapper.insert(student1);
                        count++;
                    }
                }
            }
        Date[] dates = generateDateArray(14,today);
        if (tCoursePackage.getType()==1){
            can = laveClassHours/codeTime;
        }
        if (tCoursePackage.getType()==2){
            Date startDate = tCoursePackage.getStartTime();
            Date endDate = tCoursePackage.getEndTime();
            dates = generateDateArray1(startDate, endDate);
            can = 999;
        }
        }else if (tCoursePackage.getType()==2){
            String classWeeks = tCoursePackage.getClassWeeks();
            List<Integer> week = week(classWeeks);
        for (Date date : dates) {
            if (count==can){
                     break;
                  }
                int wei =  DateUtil.dayOfWeek(date);
            if (week.contains(wei)){
                for (int i1 = 0; i1 < split.length; i1++) {
                    if (count==can){
                        break;
                            }
                    CoursePackageScheduling coursePackageScheduling = new CoursePackageScheduling();
                    coursePackageScheduling.setCoursePackageId(tCoursePackage.getId());
                    Date parse = format1.parse(format.format(date) + " " + split[i1]);
                    Date parse1 = format1.parse(format.format(date) + " " + split1[i1]);
                    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(paymentId);
                    student1.setCoursePackageSchedulingId(coursePackageScheduling.getId());
                    student1.setSignInOrNot(1);
                    student1.setReservationStatus(1);
                    student1.setInsertTime(new Date());
                    cpsMapper.insert(student1);
                    count++;
            Date today = new Date();
            Date startTime = tCoursePackage.getStartTime();
            Date endTime = tCoursePackage.getEndTime();
            LocalDate startDate = startTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            LocalDate endDate = endTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            Period period = Period.between(startDate, endDate);
            int days = period.getDays() + 1;
            Integer can =999;
            int count = 0;
            String[] split = tCoursePackage.getClassStartTime().split(",");
            String[] split1 = tCoursePackage.getClassEndTime().split(",");
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(startTime);
            calendar.add(Calendar.DAY_OF_MONTH, -1);
            TCoursePackagePayment pay = coursePackagePaymentService.getById(paymentId);
            Date[] dates = generateDateArray(days,calendar.getTime());
            for (Date date : dates) {
                if (count==can){
                    break;
                }
                int wei =  cn.hutool.core.date.DateUtil.dayOfWeek(date)-1;
                if (wei == 0){
                    wei =7;
                }
                if (week.contains(wei)){
                    for (int i1 = 0; i1 < split.length; i1++) {
                        if (count==can){
                            break;
                        }
                        CoursePackageScheduling coursePackageScheduling = new CoursePackageScheduling();
                        coursePackageScheduling.setCoursePackageId(tCoursePackage.getId());
                        Date parse = format1.parse(format.format(date) + " " + split[i1]);
                        Date parse1 = format1.parse(format.format(date) + " " + split1[i1]);
                        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(pay.getId());
                        student1.setCoursePackageSchedulingId(coursePackageScheduling.getId());
                        student1.setSignInOrNot(1);
                        student1.setReservationStatus(1);
                        student1.setInsertTime(new Date());
                        cpsMapper.insert(student1);
                        count++;
                    }
                }
            }
        }
//        for (Integer integer : week) {
//            if (count==can){
//                break;
//            }
//            if(integer<i){
//                // 找下一周的时间
//                Calendar instance = Calendar.getInstance();
//                if (cs==null||cs.getClassDate().before(new Date())){
//                    instance = Calendar.getInstance();
//                }else {
////                    i = DateUtil.dayOfWeek(cs.getClassDate())-1;
//                    instance.setTime(cs.getClassDate());
//                }
//                instance.add(Calendar.DATE,7-(i-integer));
//                Date time = instance.getTime();
//
//                for (int i1 = 0; i1 < split.length; i1++) {
//                    if (count==can){
//                        break;
//                    }
//
//                    CoursePackageScheduling coursePackageScheduling = new CoursePackageScheduling();
//                    coursePackageScheduling.setCoursePackageId(tCoursePackage.getId());
//                                            Date parse = format1.parse(format.format(time) + " " + split[i1]);
//                        Date parse1 = format1.parse(format.format(time) + " " + split1[i1]);
//                        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(paymentId);
//                    student1.setCoursePackageSchedulingId(coursePackageScheduling.getId());
//                    student1.setSignInOrNot(1);
//                    student1.setReservationStatus(1);
//                    student1.setInsertTime(new Date());
//                    cpsMapper.insert(student1);
//                    count++;
//                }
//
//
//            }else if(integer>i) {
//                if (count==can){
//                    break;
//                }
//
////                Calendar instance = Calendar.getInstance();
//
//                Calendar instance = Calendar.getInstance();
//                if (cs==null||cs.getClassDate().before(new Date())){
//                    instance = Calendar.getInstance();
//                }else {
////                    i = DateUtil.dayOfWeek(cs.getClassDate())-1;
//                    instance.setTime(cs.getClassDate());
//                }
//                instance.add(Calendar.DATE,integer-i);
//                Date time1 = instance.getTime();
//                List<Date> list = new ArrayList<>();
//                list.add(time1);
//                instance.add(Calendar.DATE,7);
//                Date time2 = instance.getTime();
//                list.add(time2);
//                for (Date time : list) {
//                    for (int i1 = 0; i1 < split.length; i1++) {
//                        CoursePackageScheduling coursePackageScheduling = new CoursePackageScheduling();
//                        coursePackageScheduling.setCoursePackageId(tCoursePackage.getId());
//                                                    Date parse = format1.parse(format.format(time) + " " + split[i1]);
//                            Date parse1 = format1.parse(format.format(time) + " " + split1[i1]);
//                            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(paymentId);
//                        student1.setCoursePackageSchedulingId(coursePackageScheduling.getId());
//                        student1.setSignInOrNot(1);
//                        student1.setReservationStatus(1);
//                        student1.setInsertTime(new Date());
//                        cpsMapper.insert(student1);
//                        count++;
//
//                    }
//                }
//
//            }else {
////                Calendar instance = Calendar.getInstance();
//                Calendar instance = Calendar.getInstance();
//                if (cs==null||cs.getClassDate().before(new Date())){
//                    instance = Calendar.getInstance();
//                }else {
////                    i = DateUtil.dayOfWeek(cs.getClassDate())-1;
//                    instance.setTime(cs.getClassDate());
//                }
//                instance.add(Calendar.DATE,7);
//                Date time = instance.getTime();
//
//                for (int i1 = 0; i1 < split.length; i1++) {
//                    if (count==can){
//                        break;
//                    }
//
//                    CoursePackageScheduling coursePackageScheduling = new CoursePackageScheduling();
//                    coursePackageScheduling.setCoursePackageId(tCoursePackage.getId());
//                                            Date parse = format1.parse(format.format(time) + " " + split[i1]);
//                        Date parse1 = format1.parse(format.format(time) + " " + split1[i1]);
//                        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(paymentId);
//                    student1.setCoursePackageSchedulingId(coursePackageScheduling.getId());
//                    student1.setSignInOrNot(1);
//                    student1.setReservationStatus(1);
//                    student1.setInsertTime(new Date());
//                    cpsMapper.insert(student1);
//                    count++;
//
//                }
//            }
//        }
        // 2.0
        TCourseInfoRecord tCourseInfoRecord = new TCourseInfoRecord();
        tCourseInfoRecord.setUserId(userId);
@@ -1738,22 +1868,27 @@
    @Override
    public ResultUtil paymentCourseCouponList(Integer uid, Integer coursePackagePaymentConfigId) {
        CoursePackagePaymentConfig coursePackagePaymentConfig = coursePackagePaymentConfigService.getById(coursePackagePaymentConfigId);
        if(ToolUtil.isEmpty(coursePackagePaymentConfig.getCouponIds())){
            coursePackagePaymentConfig.setCouponIds("-1");
        }
        List<Coupon> coupons = couponClient.getCoupons(coursePackagePaymentConfig.getCouponIds());
//        CoursePackagePaymentConfig coursePackagePaymentConfig = coursePackagePaymentConfigService.getById(coursePackagePaymentConfigId);
//        if(ToolUtil.isEmpty(coursePackagePaymentConfig.getCouponIds())){
//            coursePackagePaymentConfig.setCouponIds("-1");
//        }
//        List<Coupon> coupons = couponClient.getCoupons(coursePackagePaymentConfig.getCouponIds());
        for (Coupon coupon : coupons) {
            Date date1 = coupon.getStartTime(); // 2023-10-01 00:00:00
            Date date2 = coupon.getEndTime(); // 2023-10-12 00:00:00
        List<Coupon> coupons = couponClient.queryCouponByUid(uid);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
            String dateString1 = sdf.format(date1);
            String dateString2 = sdf.format(date2);
            String result = dateString1 + "-" + dateString2;
            coupon.setTimePeriod(result);
        if (CollectionUtil.isNotEmpty(coupons)) {
            for (Coupon coupon : coupons){
                Date date1 = coupon.getStartTime(); // 2023-10-01 00:00:00
                Date date2 = coupon.getEndTime(); // 2023-10-12 00:00:00
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
                String dateString1 = sdf.format(date1);
                String dateString2 = sdf.format(date2);
                String result = dateString1 + "-" + dateString2;
                coupon.setTimePeriod(result);
            }
        }
        return ResultUtil.success(coupons);
    }