puzhibing
2023-07-10 e899587f6d4abdc299b82bed0c043f88276a64c3
cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java
@@ -2,11 +2,8 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsh.course.entity.PostCourseVideo;
import com.dsh.course.entity.TCoursePackage;
import com.dsh.course.entity.TCoursePackageDiscount;
import com.dsh.course.entity.TCoursePackagePayment;
import com.dsh.course.entity.TCoursePackageType;
import com.dsh.course.entity.*;
import com.dsh.course.feignclient.account.StudentClient;
import com.dsh.course.feignclient.model.*;
import com.dsh.course.model.BaseVo;
import com.dsh.course.model.dto.DiscountJsonDto;
@@ -75,6 +72,9 @@
    @Autowired
    private TokenUtil tokenUtil;
    @Autowired
    private CancelledClassesService cancelledClassesService;
    private final SimpleDateFormat format = new SimpleDateFormat("MM-dd HH:mm");
@@ -503,5 +503,94 @@
    }
    /**
     * 获取学员剩余课时
     * @param id
     * @return
     */
    @ResponseBody
    @PostMapping("/coursePackagePayment/queryResidueClassHour")
    public Integer queryResidueClassHour(@RequestBody Integer id){
        try {
            List<TCoursePackagePayment> list = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>().eq("studentId", id).eq("payStatus", 2)
                    .eq("status", 1).eq("state", 1).gt("laveClassHours", 0));
            Integer total = 0;
            for (TCoursePackagePayment coursePackagePayment : list) {
                total += coursePackagePayment.getLaveClassHours();
            }
            return total;
        }catch (Exception e){
            e.printStackTrace();
            return 0;
        }
    }
    /**
     * 课程用于支付进行扣减
     * @param paymentDeductionClassHour
     */
    @ResponseBody
    @PostMapping("/coursePackagePayment/paymentDeductionClassHour")
    public void paymentDeductionClassHour(@RequestBody PaymentDeductionClassHour paymentDeductionClassHour){
        try {
            List<TCoursePackagePayment> list = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>().eq("studentId", paymentDeductionClassHour.getId()).eq("payStatus", 2)
                    .eq("status", 1).eq("state", 1).gt("laveClassHours", 0));
            Integer classHour = paymentDeductionClassHour.getClassHour();
            for (TCoursePackagePayment coursePackagePayment : list) {
                if(coursePackagePayment.getLaveClassHours().compareTo(classHour) >= 0){
                    coursePackagePayment.setLaveClassHours(coursePackagePayment.getLaveClassHours() - classHour);
                    packagePaymentService.updateById(coursePackagePayment);
                    CancelledClasses cancelledClasses = new CancelledClasses();
                    cancelledClasses.setType(2);
                    cancelledClasses.setVoucher(paymentDeductionClassHour.getCode());
                    cancelledClasses.setCoursePackageId(coursePackagePayment.getCoursePackageId());
                    cancelledClasses.setCoursePackagePaymentId(coursePackagePayment.getId());
                    cancelledClasses.setCancelledClassesNumber(classHour);
                    cancelledClasses.setInsertTime(new Date());
                    cancelledClassesService.save(cancelledClasses);
                    break;
                }else{
                    CancelledClasses cancelledClasses = new CancelledClasses();
                    cancelledClasses.setType(2);
                    cancelledClasses.setVoucher(paymentDeductionClassHour.getCode());
                    cancelledClasses.setCoursePackageId(coursePackagePayment.getCoursePackageId());
                    cancelledClasses.setCoursePackagePaymentId(coursePackagePayment.getId());
                    cancelledClasses.setCancelledClassesNumber(coursePackagePayment.getLaveClassHours());
                    cancelledClasses.setInsertTime(new Date());
                    cancelledClassesService.save(cancelledClasses);
                    coursePackagePayment.setLaveClassHours(0);
                    packagePaymentService.updateById(coursePackagePayment);
                    classHour -= cancelledClasses.getCancelledClassesNumber();
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 取消赛事回退支付课时
     * @param paymentDeductionClassHour
     */
    @ResponseBody
    @PostMapping("/coursePackagePayment/rollbackPaymentDeductionClassHour")
    public void rollbackPaymentDeductionClassHour(@RequestBody PaymentDeductionClassHour paymentDeductionClassHour){
        try {
            List<CancelledClasses> voucher = cancelledClassesService.list(new QueryWrapper<CancelledClasses>().eq("voucher", paymentDeductionClassHour.getCode()));
            for (CancelledClasses cancelledClasses : voucher) {
                TCoursePackagePayment coursePackagePayment = packagePaymentService.getById(cancelledClasses.getCoursePackagePaymentId());
                coursePackagePayment.setLaveClassHours(coursePackagePayment.getLaveClassHours() + cancelledClasses.getCancelledClassesNumber());
                packagePaymentService.updateById(coursePackagePayment);
                cancelledClassesService.removeById(cancelledClasses.getId());
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}