From a30f3b966f6b3c1748d2976364369596327cbfba Mon Sep 17 00:00:00 2001
From: liujie <liujie>
Date: 星期一, 21 八月 2023 17:40:04 +0800
Subject: [PATCH] 后台代码 积分商品

---
 cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java |  292 +++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 228 insertions(+), 64 deletions(-)

diff --git a/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java b/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java
index 346ebf8..a5bbd2e 100644
--- a/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java
+++ b/cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java
@@ -1,12 +1,22 @@
 package com.dsh.course.controller;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.dsh.course.entity.*;
 import com.dsh.course.feignclient.account.AppUserClient;
+import com.dsh.course.feignclient.account.StudentClient;
 import com.dsh.course.feignclient.account.model.AppUser;
+import com.dsh.course.feignclient.account.model.Student;
 import com.dsh.course.feignclient.model.*;
+import com.dsh.course.feignclient.other.StoreClient;
+import com.dsh.course.feignclient.other.model.Store;
 import com.dsh.course.model.BaseVo;
+import com.dsh.course.model.QueryRegistrationRecord;
+import com.dsh.course.model.QueryWalkInStudentList;
+import com.dsh.course.model.BillingRequest;
+import com.dsh.course.model.BillingRequestVo;
 import com.dsh.course.model.dto.DiscountJsonDto;
 import com.dsh.course.model.vo.CourseDetailRequest;
 import com.dsh.course.model.vo.RegisterCourseVo;
@@ -33,6 +43,7 @@
 import javax.servlet.http.HttpServletResponse;
 import java.io.PrintWriter;
 import java.math.BigDecimal;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
@@ -68,7 +79,8 @@
     @Autowired
     private TCourseService tcService;
 
-
+    @Resource
+    private StudentClient studentClient;
 
     @Autowired
     private TCoursePackageTypeService coursePackageTypeService;
@@ -79,10 +91,17 @@
     @Autowired
     private CancelledClassesService cancelledClassesService;
 
+    @Resource
+    private CoursePackageStudentService cspsService;
+
+
     @Autowired
     private PayMoneyUtil payMoneyUtil;
     @Resource
     private AppUserClient auClitn;
+
+    @Resource
+    private StoreClient sreClient;
 
     private final SimpleDateFormat format = new SimpleDateFormat("MM-dd HH:mm");
 
@@ -91,11 +110,13 @@
      * @param stuId 学员id
      * @return  课包列表
      */
+    @ResponseBody
     @PostMapping("/base/coursePack/queryPayment")
-    public List<StuCourseResp> getStuCoursePackagePayment(@RequestParam("stuId") Integer stuId,@RequestParam("appUserId") Integer appUserId){
+    public List<StuCourseResp> getStuCoursePackagePayment(@RequestBody Integer stuId){
         List<StuCourseResp> resps = new ArrayList<>();
+        Student student = studentClient.queryStudentById(stuId);
         List<TCoursePackagePayment> byUserId = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
-                .eq("appUserId",appUserId)
+                .eq("appUserId",student.getAppUserId())
                 .eq("studentId",stuId));
 
         if (byUserId.size() > 0 ){
@@ -107,6 +128,8 @@
                 resp.setTotalCourseNums(tCoursePackagePayment.getTotalClassHours());
                 resp.setResidueNums(tCoursePackagePayment.getLaveClassHours());
                 resp.setDeductionNums(tCoursePackagePayment.getTotalClassHours()-tCoursePackagePayment.getLaveClassHours());
+                String afterDayDate = DateUtil.getAfterDayDate2(tCoursePackage.getInsertTime(),tCoursePackage.getValidDays() + "");
+                resp.setPeriodOfValidity(afterDayDate);
                 resps.add(resp);
             }
         }
@@ -117,21 +140,61 @@
      *
      * 获取发布的 课包列表
      */
+    @ResponseBody
     @PostMapping("/base/coursePack/storeOfCourse")
-    public List<CourseOfStoreVo> getStuCourseWithStores(){
-        List<CourseOfStoreVo> courseOfStoreVos = tcpService.queryStoreOfCourse();
-        if (courseOfStoreVos.size() > 0){
-            for (CourseOfStoreVo courseOfStoreVo : courseOfStoreVos) {
-                String[] split = courseOfStoreVo.getClassWeeks().split(";");
-                List<Integer> integers = new ArrayList<>();
-                for (String s : split) {
-                    int num = Integer.parseInt(s);
-                    integers.add(num);
+    public List<CourseOfStoreVo> getStuCourseWithStores(@RequestBody WeeksOfCourseRest courseRest){
+        List<CourseOfStoreVo> course = new ArrayList<>();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        try {
+            Date parse = simpleDateFormat.parse(courseRest.getTime());
+            List<TCoursePackagePayment> list = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
+                    .eq("appUserId",courseRest.getAppUserId() )
+                    .eq("studentId",courseRest.getStuId())
+                    .eq("payStatus",2)
+                    .eq("status",1)
+                    .eq("state",1)
+                    .groupBy("coursePackageId"));
+            if (list.size() >  0){
+                for (TCoursePackagePayment tCoursePackagePayment : list) {
+                    CoursePackageStudent packageStudent = cspsService.getOne(new LambdaQueryWrapper<CoursePackageStudent>()
+                            .eq(CoursePackageStudent::getAppUserId, courseRest.getAppUserId())
+                            .eq(CoursePackageStudent::getStudentId,courseRest.getStuId())
+                            .eq(CoursePackageStudent::getCoursePackagePaymentId,tCoursePackagePayment.getId())
+                            .eq(CoursePackageStudent::getCoursePackageId,tCoursePackagePayment.getCoursePackageId()));
+                    if (ToolUtil.isEmpty(packageStudent) || (ToolUtil.isNotEmpty(packageStudent) && packageStudent.getReservationStatus() != 1)){
+//                        没有预约过的/已经取消了的
+                        TCoursePackage tCoursePackage = tcpService.getById(tCoursePackagePayment.getCoursePackageId());
+                        CoursePackagePaymentConfig paymentConfig = icppcService.getOne(new QueryWrapper<CoursePackagePaymentConfig>()
+                                .eq("coursePackageId",tCoursePackage.getId() )
+                                .eq("classHours",tCoursePackagePayment.getClassHours()));
+//                    获取课程有效结束时间,判断 查询的日期parse 是否在有效期范围内
+                        Date expirationDate = DateTimeHelper.getExpirationDate(tCoursePackagePayment.getInsertTime(),tCoursePackage.getValidDays());
+                        System.out.println(expirationDate.after(parse));
+                        String classWeeks = tCoursePackage.getClassWeeks();
+                        System.out.println(StrUtils.dealStrToList(classWeeks).contains(DateTimeHelper.getDayOfWeek(parse)));
+                        if (expirationDate.after(parse) && StrUtils.dealStrToList(classWeeks).contains(DateTimeHelper.getDayOfWeek(parse))){
+                            CourseOfStoreVo storeVo = new CourseOfStoreVo();
+                            storeVo.setCourseId(tCoursePackagePayment.getId());
+                            storeVo.setCourseName(tCoursePackage.getName());
+                            storeVo.setClassStartTime(tCoursePackage.getClassStartTime());
+                            storeVo.setClassEndTime(tCoursePackage.getClassEndTime());
+                            storeVo.setStoreId(tCoursePackage.getStoreId());
+                            Store store = sreClient.queryStoreById(tCoursePackage.getStoreId());
+                            storeVo.setStoreAddress(store.getAddress());
+                            storeVo.setLat(store.getLat());
+                            storeVo.setLon(store.getLon());
+                            storeVo.setCoursePrice(ToolUtil.isEmpty(paymentConfig.getCashPayment()) ? (double) paymentConfig.getPlayPaiCoin():paymentConfig.getCashPayment());
+                            storeVo.setStatus(1);
+                            course.add(storeVo);
+                        }
+                    }
                 }
-                courseOfStoreVo.setClassWeekList(integers);
             }
+            System.out.println(course);
+            return course;
+        } catch (ParseException e) {
+            return null;
         }
-        return tcpService.queryStoreOfCourse();
     }
 
 
@@ -163,13 +226,13 @@
     }
 
     @PostMapping("/base/coursePack/paymentCourse")
-    public List<PurchaseRecordVo> queryCourseDetails(@RequestParam("startTime") Date startTime, @RequestParam("endTime") Date  endTime,@RequestParam("stuId") Integer stuId, @RequestParam("appUserId") Integer appUserId) {
+    public List<PurchaseRecordVo> queryCourseDetails(@RequestBody GetStuSessionList sessionList) {
         List<PurchaseRecordVo> purchaseRecordVos = new ArrayList<>();
 
         List<TCoursePackagePayment> coursePackage = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
-                .between("insertTime", startTime,endTime)
-                .eq("appUserId",appUserId)
-                .eq("studentId",stuId));
+                .between("insertTime", sessionList.getStartTime(),sessionList.getEndTime())
+                .eq("appUserId",sessionList.getAppUserId())
+                .eq("studentId",sessionList.getStuId()));
         if (coursePackage.size() > 0 ){
             coursePackage.forEach( cspackage -> {
                 PurchaseRecordVo recordVo = new PurchaseRecordVo();
@@ -237,33 +300,9 @@
             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);
                 }
                 courseVo.setCourseWeek(courWeeks.toString());
@@ -329,21 +368,36 @@
     }
 
     @PostMapping("/base/coursePack/allPaymentCourseList")
-    public List<TCoursePackagePayment> getAppuserCourseList(@RequestBody Integer appUserId){
-        return packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
-                .eq("appUserId",appUserId)
-                .eq("payType",3)
-                .eq("payStatus",2)
-                .eq("state",1));
+    @ResponseBody
+    public List<CouponPaymentVo> getAppuserCourseList(@RequestBody Integer appUserId){
+        List<CouponPaymentVo> paymentVos = new ArrayList<>();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd HH:mm");
+        List<TCoursePackagePayment> list = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
+                .eq("appUserId", appUserId)
+                .eq("payType", 3)
+                .eq("payStatus", 2)
+                .eq("state", 1));
+        if (list.size() > 0 ){
+            for (TCoursePackagePayment tCoursePackagePayment : list) {
+                CouponPaymentVo couponPaymentVo = new CouponPaymentVo();
+                couponPaymentVo.setTime(simpleDateFormat.format(tCoursePackagePayment.getInsertTime()));
+                couponPaymentVo.setAmount( tCoursePackagePayment.getPlayPaiCoin());
+                paymentVos.add(couponPaymentVo);
+            }
+        }
+        return paymentVos;
     }
 
+
+    @ResponseBody
     @PostMapping("/base/coursePack/allAmountPayRecordOfUser")
-    public List<TCoursePackagePayment> getAmountPayRecord(@RequestBody Integer appUserId){
-        return packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
-                .eq("appUserId",appUserId)
-                .notIn("payType",3)
-                .eq("payStatus",2)
-                .eq("state",1));
+    public BillingRequestVo getAmountPayRecord(@RequestBody BillingDataRequestVo billingDataRequestVo){
+        BillingRequestVo requestVo = new BillingRequestVo();
+        List<BillingRequest> billingRequests = packagePaymentService.queryAmountDatas(billingDataRequestVo.getAppUserId(), billingDataRequestVo.getMonthStart(), billingDataRequestVo.getMonthEnd());
+        if (billingRequests.size() >0){
+            requestVo.setRequests(billingRequests);
+        }
+        return requestVo;
     }
 
 
@@ -368,7 +422,7 @@
                 baseVo.setName(coursePackage.getName());
                 list.add(baseVo);
             });
-            return ResultUtil.success();
+            return ResultUtil.success(list);
         }catch (Exception e){
             e.printStackTrace();
             return ResultUtil.runErr();
@@ -393,9 +447,12 @@
                 return ResultUtil.tokenErr();
             }
             List<Integer> courseIds = new ArrayList<>();
-            List<TCoursePackagePayment> tCoursePackagePayments = packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
-                    .eq("coursePackageId",search.getCourseTypeId())
-                    .eq("appUserId",appUserId));
+            QueryWrapper<TCoursePackagePayment> queryWrapper = new QueryWrapper<TCoursePackagePayment>().eq("appUserId", appUserId)
+                    .groupBy("coursePackageId");
+            if (ToolUtil.isNotEmpty(search.getCourseTypeId())){
+                queryWrapper.eq("coursePackageId",search.getCourseTypeId());
+            }
+            List<TCoursePackagePayment> tCoursePackagePayments = packagePaymentService.list(queryWrapper);
             if (tCoursePackagePayments.size() > 0 ){
                 courseIds = tCoursePackagePayments.stream().map(TCoursePackagePayment::getCoursePackageId).collect(Collectors.toList());
             }
@@ -505,7 +562,7 @@
             @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
             @ApiImplicitParam(name = "coursePayId" ,value = "课包记录id",dataType = "long"),
     })
-    public ResultUtil<CourseDetailsResponse> getRegisteredData( Integer coursePayId){
+    public ResultUtil<CourseDetailsResponse> getRegisteredData(Long coursePayId){
         try {
             Integer appUserId = tokenUtil.getUserIdFormRedis();
             if(null == appUserId){
@@ -737,15 +794,15 @@
 
     @PostMapping("/base/coursePack/savePaymentCoursePackage")
     public boolean savePaymentCoursePackage(@RequestBody TCoursePackagePayment packagePayment){
+        packagePayment.setInsertTime(new Date());
         return packagePaymentService.save(packagePayment);
     }
 
 
     @PostMapping("/base/coursePack/obtainStudentClassDetails")
-    public List<RecordAppoint> obtainStudentClassDetailsData(@RequestBody Integer stuId){
+    public List<RecordAppoint> obtainStudentClassDetailsData(@RequestBody WeeksOfCourseRest stuId){
         try {
-            Integer appUserId = tokenUtil.getUserIdFormRedis();
-            return packagePaymentService.obtainStuClassDetails(stuId,appUserId);
+            return packagePaymentService.obtainStuClassDetails(stuId.getStuId(),stuId.getAppUserId());
         }catch (Exception e){
             e.printStackTrace();
             throw new RuntimeException();
@@ -767,4 +824,111 @@
                 .eq("code",code));
     }
 
+
+    /**
+     * 获取课包报名信息列表
+     * @param queryRegistrationRecord
+     * @return
+     */
+    @ResponseBody
+    @PostMapping("/coursePackagePayment/queryRegistrationRecord")
+    public Page<Map<String, Object>> queryRegistrationRecord(@RequestBody QueryRegistrationRecord queryRegistrationRecord){
+        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage(queryRegistrationRecord.getLimit(), queryRegistrationRecord.getOffset(), queryRegistrationRecord.getSort(), queryRegistrationRecord.getOrder());
+        Page<Map<String, Object>> mapPage = page.setRecords(packagePaymentService.queryRegistrationRecord(page, queryRegistrationRecord));
+        return mapPage;
+    }
+
+
+    /**
+     * 获取未预约排课学员列表
+     * @param queryWalkInStudentList
+     * @return
+     */
+    @ResponseBody
+    @PostMapping("/coursePackagePayment/queryWalkInStudentList")
+    public Page<Map<String, Object>> queryWalkInStudentList(@RequestBody QueryWalkInStudentList queryWalkInStudentList){
+        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage(queryWalkInStudentList.getLimit(), queryWalkInStudentList.getOffset(), queryWalkInStudentList.getSort(), queryWalkInStudentList.getOrder());
+        Page<Map<String, Object>> mapPage = page.setRecords(packagePaymentService.queryWalkInStudentList(page, queryWalkInStudentList));
+        return mapPage;
+    }
+
+
+    /**
+     * 根据id获取数据
+     * @param id
+     * @return
+     */
+    @ResponseBody
+    @PostMapping("/coursePackagePayment/queryCoursePackagePaymentById")
+    public TCoursePackagePayment queryCoursePackagePaymentById(@RequestBody Long id){
+        return packagePaymentService.getById(id);
+    }
+
+
+    /**
+     * 修改数据
+     * @param coursePackagePayment
+     */
+    @ResponseBody
+    @PostMapping("/coursePackagePayment/editCoursePackagePayment")
+    public void editCoursePackagePayment(TCoursePackagePayment coursePackagePayment){
+        packagePaymentService.updateById(coursePackagePayment);
+    }
+
+
+    /**
+     * 上课主页-预约操作
+     */
+    @ResponseBody
+    @PostMapping("/api/startCource/reverse")
+    @ApiOperation(value = "上课主页-预约操作", tags = {"APP-开始上课"})
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
+            @ApiImplicitParam(value = "课包id", name = "courseID", required = true, dataType = "String"),
+            @ApiImplicitParam(value = "时间 yyyy-MM-dd", name = "time", required = true, dataType = "String"),
+            @ApiImplicitParam(value = "学员id", name = "stuId", required = true, dataType = "int"),
+    })
+    public ResultUtil reverse(String courseID,String time,Integer stuId){
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        try {
+            Integer appUserId = tokenUtil.getUserIdFormRedis();
+            if(null == appUserId){
+                return ResultUtil.tokenErr();
+            }
+            TCoursePackagePayment packagePayment = packagePaymentService.getOne(new LambdaQueryWrapper<TCoursePackagePayment>()
+                    .eq(TCoursePackagePayment::getCoursePackageId,courseID )
+                    .eq(TCoursePackagePayment::getAppUserId,appUserId)
+                    .eq(TCoursePackagePayment::getStudentId,stuId)
+            );
+
+            if (ToolUtil.isEmpty(packagePayment)){
+                return ResultUtil.error("该用户未购买该课包");
+            }
+            CoursePackageStudent coursePackageStudent = cspsService.getOne(new LambdaQueryWrapper<CoursePackageStudent>()
+                    .eq(CoursePackageStudent::getCoursePackageId,packagePayment.getCoursePackageId())
+                    .eq(CoursePackageStudent::getCoursePackagePaymentId,courseID)
+                    .eq(CoursePackageStudent::getStudentId,stuId)
+                    .eq(CoursePackageStudent::getAppUserId,appUserId)
+            );
+
+            if (ToolUtil.isNotEmpty(coursePackageStudent) && coursePackageStudent.getReservationStatus() == 0){
+                coursePackageStudent.setReservationStatus(1);
+                coursePackageStudent.setInsertTime(simpleDateFormat.parse(time));
+                cspsService.updateById(coursePackageStudent);
+            }else {
+                coursePackageStudent = new CoursePackageStudent();
+                coursePackageStudent.setAppUserId(appUserId);
+                coursePackageStudent.setStudentId(stuId);
+                coursePackageStudent.setCoursePackageId(packagePayment.getCoursePackageId());
+                coursePackageStudent.setCoursePackagePaymentId(Long.parseLong(courseID));
+                coursePackageStudent.setReservationStatus(1);
+                coursePackageStudent.setInsertTime(simpleDateFormat.parse(time));
+                cspsService.save(coursePackageStudent);
+            }
+            return ResultUtil.success();
+        }catch (Exception e){
+            return ResultUtil.runErr();
+        }
+    }
+
 }

--
Gitblit v1.7.1