lisy
2023-07-20 c678894e37d15cca116d962eba5c107c99176945
cloud-server-course/src/main/java/com/dsh/course/controller/CoursePackagePaymentController.java
@@ -28,11 +28,14 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
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;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Api
@@ -75,7 +78,9 @@
    private CancelledClassesService cancelledClassesService;
    @Autowired
    private AppUserClient appuClient;
    private PayMoneyUtil payMoneyUtil;
    @Resource
    private AppUserClient auClitn;
    private final SimpleDateFormat format = new SimpleDateFormat("MM-dd HH:mm");
@@ -111,20 +116,43 @@
     * 获取发布的 课包列表
     */
    @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) {
                    TCoursePackage tCoursePackage = tcpService.getById(tCoursePackagePayment.getCoursePackageId());
//                    获取课程有效结束时间,判断 查询的日期parse 是否在有效期范围内
                    Date expirationDate = DateTimeHelper.getExpirationDate(tCoursePackagePayment.getInsertTime(),tCoursePackage.getValidDays());
                    String classWeeks = tCoursePackage.getClassWeeks();
                    if (expirationDate.after(parse) && StrUtils.dealStrToList(classWeeks).contains(DateTimeHelper.getDayOfWeek(parse))){
                        CourseOfStoreVo storeVo = new CourseOfStoreVo();
                        storeVo.setCourseId(tCoursePackage.getId());
                        // TODO: 2023/7/20 查询课包对应门店信息
//                        storeVo.setCourseName();
//                        storeVo.setClassStartTime();
//                        storeVo.setClassEndTime();
//                        storeVo.setStoreId();
//                        storeVo.setStoreName();
//                        storeVo.setLat();
//                        storeVo.setLon();
                        course.add(storeVo);
                    }
                }
                courseOfStoreVo.setClassWeekList(integers);
            }
            return course;
        } catch (ParseException e) {
            return null;
        }
        return tcpService.queryStoreOfCourse();
    }
@@ -342,7 +370,7 @@
    @ResponseBody
    @PostMapping("/api/course/queryArrangeCourseList")
    @ApiOperation(value = "获取布置课程列表", tags = {"APP-课程列表"})
    @ApiOperation(value = "课后练习-获取布置课程列表", tags = {"APP-开始上课"})
    @ApiImplicitParams({
    })
    public ResultUtil<List<BaseVo>> queryArrangePackageType(){
@@ -374,7 +402,7 @@
     */
    @ResponseBody
    @PostMapping("/api/startCource/afterSourceList")
    @ApiOperation(value = "课后视频课表", tags = {"APP-开始上课"})
    @ApiOperation(value = "课后练习-课后视频列表", tags = {"APP-开始上课"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
@@ -403,7 +431,7 @@
     */
    @ResponseBody
    @PostMapping("/api/startCource/afterSourceDetail")
    @ApiOperation(value = "课后视频详情", tags = {"APP-开始上课"})
    @ApiOperation(value = "课后练习-课后视频详情", tags = {"APP-开始上课"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
@@ -534,6 +562,58 @@
    }
    /**
     * 课包续课支付宝支付回调接口
     */
    @PostMapping("/base/coursePackage/alipayRegisteredCoursesCallback")
    public void alipayCallback(HttpServletRequest request, HttpServletResponse response){
        try {
            Map<String, String> map = payMoneyUtil.alipayCallback(request);
            if(null != map){
                String out_trade_no = map.get("out_trade_no");
                String transaction_id = map.get("transaction_id");
                ResultUtil resultUtil = packagePaymentService.insertVipPaymentCallback(out_trade_no, transaction_id);
                if(resultUtil.getCode() == 200){
                    PrintWriter out = response.getWriter();
                    out.write("success");
                    out.flush();
                    out.close();
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 课包续课微信支付回调接口
     */
    @PostMapping("/base/coursePackage/wechatRegisteredCoursesCallback")
    public void weChatCallback(HttpServletRequest request, HttpServletResponse response){
        try {
            Map<String, String> map = payMoneyUtil.weixinpayCallback(request);
            if(null != map){
                String out_trade_no = map.get("out_trade_no");
                String transaction_id = map.get("transaction_id");
                String result = map.get("result");
                ResultUtil resultUtil = packagePaymentService.insertVipPaymentCallback(out_trade_no, transaction_id);
                if(resultUtil.getCode() == 200){
                    PrintWriter out = response.getWriter();
                    out.write(result);
                    out.flush();
                    out.close();
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 获取学员剩余课时
     * @param id
@@ -638,7 +718,7 @@
                return 2;
            }
            CoursePackagePaymentConfig paymentConfig = icppcService.getById(coursePackage.getCoursePayConfigId());
            AppUser appUser = appuClient.queryAppUser(userIdFormRedis);
            AppUser appUser = auClitn.queryAppUser(userIdFormRedis);
            if (appUser.getPlayPaiCoins() < paymentConfig.getPlayPaiCoin()){
                return 3;
            }
@@ -653,7 +733,7 @@
            packagePaymentService.updateById(packagePayment);
            appUser.setPlayPaiCoins(appUser.getPlayPaiCoins()-paymentConfig.getPlayPaiCoin());
            appuClient.updateAppUser(appUser);
            auClitn.updateAppUser(appUser);
        } catch (Exception e) {
            return 4;
        }
@@ -700,4 +780,12 @@
                .eq("coursePackageId",coursePackageId));
    }
    @PostMapping("/base/coursePack/getCoursePackagePaymentOfCode")
    public List<TCoursePackagePayment> getCoursePackagePaymentOfCode(@RequestBody String code){
        return packagePaymentService.list(new QueryWrapper<TCoursePackagePayment>()
                .eq("code",code));
    }
}