liujie
2023-09-25 d41358fce9a436d81b9341d06fc1d8f3ddff92ff
cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java
@@ -5,6 +5,7 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dsh.course.entity.*;
import com.dsh.course.feignclient.account.AppUserClient;
@@ -12,9 +13,12 @@
import com.dsh.course.feignclient.account.model.AppUser;
import com.dsh.course.feignclient.account.model.Student;
import com.dsh.course.feignclient.account.model.TCourseInfoRecord;
import com.dsh.course.feignclient.activity.CouponClient;
import com.dsh.course.feignclient.activity.model.Coupon;
import com.dsh.course.feignclient.model.*;
import com.dsh.course.feignclient.other.StoreClient;
import com.dsh.course.feignclient.other.model.Store;
import com.dsh.course.mapper.CoursePackageSchedulingMapper;
import com.dsh.course.model.*;
import com.dsh.course.model.dto.DiscountJsonDto;
import com.dsh.course.model.vo.CourseDetailRequest;
@@ -29,6 +33,9 @@
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import net.bytebuddy.asm.Advice;
import org.aspectj.weaver.ast.Var;
import io.swagger.models.auth.In;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
@@ -105,9 +112,113 @@
    @Autowired
    private RestTemplate internalRestTemplate;
    @Autowired
    private CouponClient couponClient;
    @Autowired
    private StoreClient storeClient;
    @Autowired
    private TCoursePackageDiscountService discountService;
    @Resource
    private CoursePackageSchedulingMapper coursePackageSchedulingMapper;
    private final SimpleDateFormat format = new SimpleDateFormat("MM-dd HH:mm");
    /**
     * 手动支付
     * @return
     */
    @RequestMapping("/base/coursePackagePayment/changeState")
    public Object changeState(@RequestBody CoursePackagePayDTO dto){
        return packagePaymentService.changeState(dto);
    }
    /**
     * 获取购课记录
     */
    @ResponseBody
    @RequestMapping("/coursePackagePayment/listAll")
    public List<CoursePackagePaymentVO> listAll(@RequestBody CoursePackagePaymentQuery query){
        List<CoursePackagePaymentVO> res = packagePaymentService.listAll(query);
        List<CoursePackagePaymentVO> result = new ArrayList<>();
        for (CoursePackagePaymentVO re : res) {
            if (re.getCashPayment()==null){
                String value = String.valueOf(re.getPlayPaiCoin());
                re.setCashPayment(new BigDecimal(value));
            }
            Store store = storeClient.queryStoreById(re.getStoreId());
            AppUser appUser = appUserClient.queryAppUser(re.getAppUserId());
            Student student = studentClient.queryStudentById(re.getStudentId());
            re.setPayStudent(student.getName());
            re.setPayUser(appUser.getName());
            re.setPhone(appUser.getPhone());
            re.setStoreName(store.getName());
            if (query.getPayUser()== null || query.getPayUser().equals("") ){
            }else{
                List<AppUser> appUsers = appUserClient.queryAppUserListByName(query.getPayUser());
                for (AppUser user : appUsers) {
                    if (appUser.getName().equals(user.getName())){
                        result.add(re);
                    }
                }
            }
            if (query.getPayStudent()== null || query.getPayStudent().equals("")){
            }else{
                List<Student> students = studentClient.queryStudentListByName(query.getPayStudent());
                for (Student student1 : students) {
                    if (student.getName().equals(student1.getName())){
                        result.add(re);
                    }
                }
            }
            if (re.getPayType()==1){
                re.setBuyTypeName("微信支付");
            }else if(re.getPayType()==2){
                re.setBuyTypeName("支付宝支付");
            }else if(re.getPayType()==3){
                re.setBuyTypeName("玩湃币支付");
            }else if(re.getPayType()==4){
                re.setBuyTypeName("积分支付");
            }else if(re.getPayType()==5){
                re.setBuyTypeName("积分+微信支付");
            }else if(re.getPayType()==6){
                re.setBuyTypeName("积分+支付宝支付");
            }else if(re.getPayType()==7){
                re.setBuyTypeName("手动支付"+"-"+re.getBuyTypeName());
            }
            // 如果支付用户类型为平台 则购买方式则为1线下购买
            if (re.getPayUserType()== 2){
                re.setBuyType(1);
            }else{
                // 如果当前课包有折扣 则为3折扣购买
                if (discountService.list(new QueryWrapper<TCoursePackageDiscount>()
                        .eq("coursePackageId",re.getCoursePackageId()).eq("auditStatus",2)).size()>0){
                    re.setBuyType(3);
                    re.setDiscountAmount(re.getOriginalPrice().subtract(re.getPayMoney()));
                }else{
                    re.setBuyType(2);
                }
            }
            // 不为空则计算
            if (re.getUserCouponId()!=null){
            }
            // todo 计算优惠金额
//            Coupon coupon = couponClient.queryCouponById(re.getUserCouponId().intValue());
        }
        if (query.getPayStudent()== null || query.getPayStudent().equals("")){
            if (query.getPayUser()== null || query.getPayUser().equals("")){
                return res;
            }else{
                return result;
            }
        }else{
            return result;
        }
    }
    /**
     * 获取 没有学员信息的图片配置
@@ -128,6 +239,7 @@
                TCoursePackage tCoursePackage = tcpService.getById(tCoursePackagePayment.getCoursePackageId());
                StuCourseResp resp = new StuCourseResp();
                resp.setCourseId(tCoursePackage.getId());
                resp.setId(tCoursePackagePayment.getId());
                resp.setCourseName(tCoursePackage.getName());
                resp.setTotalCourseNums(tCoursePackagePayment.getTotalClassHours());
                resp.setResidueNums(tCoursePackagePayment.getLaveClassHours());
@@ -160,12 +272,12 @@
                    .groupBy("coursePackageId"));
            if (list.size() >  0){
                for (TCoursePackagePayment tCoursePackagePayment : list) {
                    CoursePackageStudent packageStudent = cspsService.getOne(new LambdaQueryWrapper<CoursePackageStudent>()
                    List<CoursePackageStudent> packageStudent = cspsService.list(new LambdaQueryWrapper<CoursePackageStudent>()
                            .eq(CoursePackageStudent::getAppUserId, courseRest.getAppUserId())
                            .eq(CoursePackageStudent::getStudentId,courseRest.getStuId())
                            .eq(CoursePackageStudent::getCoursePackagePaymentId,tCoursePackagePayment.getId())
                            .eq(CoursePackageStudent::getCoursePackageId,tCoursePackagePayment.getCoursePackageId()));
                    if (ToolUtil.isEmpty(packageStudent) || (ToolUtil.isNotEmpty(packageStudent) && packageStudent.getReservationStatus() != 1)){
                    if (ToolUtil.isEmpty(packageStudent) || (ToolUtil.isNotEmpty(packageStudent) && packageStudent.get(0).getReservationStatus() == 1)){
//                        没有预约过的/已经取消了的
                        TCoursePackage tCoursePackage = tcpService.getById(tCoursePackagePayment.getCoursePackageId());
                        CoursePackagePaymentConfig paymentConfig = icppcService.getOne(new QueryWrapper<CoursePackagePaymentConfig>()
@@ -438,7 +550,6 @@
        }
    }
    /**
     * 课后视频课表
     */
@@ -492,7 +603,6 @@
        }
    }
    @ResponseBody
    @PostMapping("/api/startCource/payCourseInfo")
    @ApiOperation(value = "课后练习-购课详情(用于购课)", tags = {"APP-开始上课"})
@@ -506,7 +616,6 @@
            return ResultUtil.runErr();
        }
    }
    @ResponseBody
    @PostMapping("/api/startCource/getMyCourseList")
@@ -545,7 +654,6 @@
        }
    }
    /**
     * 更新课后视频学习状态
     */
@@ -566,7 +674,6 @@
            return ResultUtil.runErr();
        }
    }
    @ResponseBody
@@ -610,7 +717,6 @@
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
@@ -651,6 +757,10 @@
            Integer userIdFormRedis = tokenUtil.getUserIdFormRedis();
            if(null == userIdFormRedis){
                return ResultUtil.tokenErr();
            }
            Integer couponId = request.getConponId();
            if(couponId==null || couponId==0){
                request.setConponId(null);
            }
            return packagePaymentService.ContinuationOrpaymentCourse(userIdFormRedis,request);
        }catch (Exception e){
@@ -924,6 +1034,11 @@
                .eq("code",code));
    }
    @PostMapping("/base/coursePack/getCoursePackagePaymentById")
    public TCoursePackagePayment getCoursePackagePaymentById(@RequestBody Integer id){
        return packagePaymentService.getById(id);
    }
    @PostMapping("/base/coursePack/delPaymentCoursePackage")
    public boolean delPaymentCoursePackage(@RequestBody Integer payId){
        return packagePaymentService.removeById(payId);
@@ -981,11 +1096,17 @@
    // 2.0 送课时
    @PostMapping("/base/coursePack/sendHours")
    public Boolean sendHours(@RequestBody  String s){
    public Integer sendHours(@RequestBody  String s){
        String[] split = s.split("_");
        TCoursePackagePayment byId = packagePaymentService.getById(Integer.valueOf(split[0]));
        TCoursePackagePayment byId = packagePaymentService.getById(Long.valueOf(split[0]));
        byId.setTotalClassHours(byId.getTotalClassHours()+Integer.valueOf(split[2]));
        return packagePaymentService.updateById(byId);
        boolean b = packagePaymentService.updateHoursById(byId,Integer.valueOf(split[2]));
        if(b){
            return 1;
        }else {
            return 0;
        }
    }
@@ -1040,6 +1161,16 @@
    }
    @ResponseBody
    @PostMapping("/coursePackagePayment/CountqueryByClassId")
   public   Integer  CountqueryByClassId(@RequestBody Integer id){
        int coursePackageId = packagePaymentService.count(new QueryWrapper<TCoursePackagePayment>().eq("coursePackageId", id));
        return coursePackageId;
    }
    /**
     * 修改数据
     * @param coursePackagePayment
@@ -1070,28 +1201,27 @@
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            TCoursePackagePayment packagePayment = packagePaymentService.getOne(new LambdaQueryWrapper<TCoursePackagePayment>()
            List<TCoursePackagePayment> packagePayment = packagePaymentService.list(new LambdaQueryWrapper<TCoursePackagePayment>()
                    .eq(TCoursePackagePayment::getCoursePackageId,courseID )
                    .eq(TCoursePackagePayment::getAppUserId,appUserId)
                    .eq(TCoursePackagePayment::getStudentId,stuId)
            );
            if (ToolUtil.isEmpty(packagePayment)){
            if (ToolUtil.isEmpty(packagePayment) || packagePayment.size()==0){
                return ResultUtil.error("该用户未购买该课包");
            }
            List<CoursePackageStudent> coursePackageStudent = cspsService.list(new LambdaQueryWrapper<CoursePackageStudent>()
                    .eq(CoursePackageStudent::getCoursePackageId,packagePayment.getCoursePackageId())
                    .eq(CoursePackageStudent::getCoursePackagePaymentId,courseID)
                    .in(CoursePackageStudent::getCoursePackagePaymentId,packagePayment.stream().map(TCoursePackagePayment::getId).collect(Collectors.toList()))
                    .eq(CoursePackageStudent::getCoursePackageId,courseID)
                    .eq(CoursePackageStudent::getStudentId,stuId)
                    .eq(CoursePackageStudent::getAppUserId,appUserId)
            );
            if (ToolUtil.isNotEmpty(coursePackageStudent)){
                for (CoursePackageStudent packageStudent : coursePackageStudent) {
                    if(packageStudent.getReservationStatus()==0){
                    if(packageStudent.getReservationStatus()==1){
                        packageStudent.setSignInOrNot(2);
                        packageStudent.setInsertTime(simpleDateFormat.parse(time));
                        cspsService.updateById(packageStudent);
                        cspsService.updateSignInOrNotById(packageStudent.getId());
                    }
                }
@@ -1124,6 +1254,8 @@
            map.put("lon",lon);
            map.put("lat",lat);
            String time1 = courseDetailReq.getTime();
            // 找出门店的所有课程 排出体验
            List<TCoursePackage> list = tcpService.list(new LambdaQueryWrapper<TCoursePackage>().eq(TCoursePackage::getStoreId, courseDetailReq.getStoreId()).ne(TCoursePackage::getType, 3).like(TCoursePackage::getClassWeeks,week));
            List<Integer> collect = list.stream().map(TCoursePackage::getId).collect(Collectors.toList());
@@ -1133,6 +1265,7 @@
            // 找出购买的课包
            List<TCoursePackagePayment> list1 = packagePaymentService.list(new LambdaQueryWrapper<TCoursePackagePayment>().eq(TCoursePackagePayment::getAppUserId, courseDetailReq.getAppUserId()).eq(TCoursePackagePayment::getStudentId, courseDetailReq.getStuId()).in(TCoursePackagePayment::getCoursePackageId, collect));
            List<Integer> collect1 = list1.stream().map(TCoursePackagePayment::getCoursePackageId).collect(Collectors.toList());
            List<Long> ids = list1.stream().map(TCoursePackagePayment::getId).collect(Collectors.toList());
            for (TCoursePackage tCoursePackage : list) {
                DetailsListVo detailsListVo = new DetailsListVo();
                detailsListVo.setId(tCoursePackage.getId());
@@ -1154,7 +1287,30 @@
                }
                detailsListVo.setNum(tCoursePackage.getNeedNum());
                if (collect1.contains(tCoursePackage.getId())) {
                    detailsListVo.setType(1);
                    // 找出排课记录
                    List<CoursePackageScheduling> list3 = coursePackageSchedulingMapper.selectList(new LambdaQueryWrapper<CoursePackageScheduling>()
                            .eq(CoursePackageScheduling::getCoursePackageId, tCoursePackage.getId())
                            .like(CoursePackageScheduling::getClassDate, courseDetailReq.getTime())
                    );
                    List<Long> collect2 = list3.stream().map(CoursePackageScheduling::getId).collect(Collectors.toList());
                    if(collect2.size()==0){
                        collect2.add(-1l);
                    }
                    List<CoursePackageStudent> list4 = cspsService.list(new LambdaQueryWrapper<CoursePackageStudent>()
                            .eq(CoursePackageStudent::getAppUserId, courseDetailReq.getAppUserId())
                            .eq(CoursePackageStudent::getCoursePackageId, tCoursePackage.getId())
                            .in(CoursePackageStudent::getCoursePackageSchedulingId, collect2).
                                    in(CoursePackageStudent::getCoursePackagePaymentId, ids)
                    );
                        detailsListVo.setType(1);
                    if(list4.size()>0){
                        Integer signInOrNot = list4.get(0).getSignInOrNot();
                        if(signInOrNot==2){
                            detailsListVo.setType(3);
                        }
                    }
                } else {
                    detailsListVo.setType(2);
                }