| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.google.common.collect.ImmutableMap; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.OrderNos; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.model.TAppUser; |
| | | import com.ruoyi.system.model.TCourse; |
| | | import com.ruoyi.system.model.TCourseOrder; |
| | | import com.ruoyi.system.model.TInsuranceOrder; |
| | | import com.ruoyi.system.model.TOtherConfig; |
| | | import com.ruoyi.system.query.CourseOrderListQuery; |
| | | import com.ruoyi.system.query.GetCourseListQuery; |
| | | import com.ruoyi.system.service.TAppUserService; |
| | | import com.ruoyi.system.service.TCourseOrderService; |
| | | import com.ruoyi.system.service.TCourseService; |
| | | import com.ruoyi.system.task.base.QuartzManager; |
| | | import com.ruoyi.system.task.base.TimeJobType; |
| | | import com.ruoyi.system.task.jobs.OrderJob; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.wxPay.model.WeixinPayProperties; |
| | | import com.ruoyi.system.wxPay.utils.WxRefundUtil; |
| | | import com.ruoyi.system.wxPay.utils.WxV3Pay; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | |
| | | private final WxV3Pay wxV3Pay; |
| | | private final WeixinPayProperties weixinPayProperties; |
| | | private final TAppUserService appUserService; |
| | | private final TInsuranceOrderService insuranceOrderService; |
| | | private final TOtherConfigService otherConfigService; |
| | | |
| | | public CourseController(TCourseService courseService, TCourseOrderService courseOrderService, TokenService tokenService, WxV3Pay wxV3Pay, WeixinPayProperties weixinPayProperties, TAppUserService appUserService) { |
| | | public CourseController(TCourseService courseService, TCourseOrderService courseOrderService, TokenService tokenService, WxV3Pay wxV3Pay, WeixinPayProperties weixinPayProperties, TAppUserService appUserService, TInsuranceOrderService insuranceOrderService, TOtherConfigService otherConfigService) { |
| | | this.courseService = courseService; |
| | | this.courseOrderService = courseOrderService; |
| | | this.tokenService = tokenService; |
| | | this.wxV3Pay = wxV3Pay; |
| | | this.weixinPayProperties = weixinPayProperties; |
| | | this.appUserService = appUserService; |
| | | this.insuranceOrderService = insuranceOrderService; |
| | | this.otherConfigService = otherConfigService; |
| | | |
| | | } |
| | | |
| | | |
| | | @GetMapping("/getOtherConfig") |
| | | @ApiOperation(value = "课程模块--是否开启课程缴费 1=是 0=否",response = TOtherConfig.class) |
| | | public R<TOtherConfig> getOtherConfig() { |
| | | TOtherConfig tOtherConfig = otherConfigService.getById(1); |
| | | return R.ok(tOtherConfig); |
| | | } |
| | | |
| | | |
| | | @PostMapping("/getCourseList") |
| | | @ApiOperation(value = "课程模块--列表",response = TCourse.class) |
| | |
| | | @ApiOperation(value = "课程模块--报名") |
| | | public R<Map<String, Object>> saveOrder(@RequestBody TCourseOrder courseOrder) { |
| | | String userId = tokenService.getLoginUserApplet().getUserId(); |
| | | TAppUser appUser = appUserService.getById(userId); |
| | | // TAppUser appUser = appUserService.getById(userId); |
| | | TCourse course = courseService.getById(courseOrder.getCourseId()); |
| | | LocalDate endTime = course.getEndTime(); |
| | | |
| | | |
| | | long count1 = insuranceOrderService.count(new LambdaQueryWrapper<TInsuranceOrder>().eq(TInsuranceOrder::getType,course.getCourseType()).eq(TInsuranceOrder::getAppUserId, userId).eq(TInsuranceOrder::getStatus, 2)); |
| | | if(count1<=0){ |
| | | return R.fail("请先缴纳保险费"); |
| | | } |
| | | |
| | | if(endTime.isBefore(LocalDate.now())){ |
| | | return R.fail("课程已截至报名"); |
| | | } |
| | | long count = courseOrderService.count(Wrappers.lambdaQuery(TCourseOrder.class).eq(TCourseOrder::getCourseId, course.getId()).in(TCourseOrder::getPayStatus, Arrays.asList(1, 2, 5))); |
| | | if(count>=course.getPeopleLimit()){ |
| | | return R.fail("报名人数已满"); |
| | |
| | | |
| | | courseOrder.setAppUserId(userId); |
| | | courseOrder.setPayMoney(course.getCourseCost()); |
| | | courseOrder.setPayStatus(1); |
| | | courseOrder.setPayStatus(0); |
| | | courseOrder.setOrderNumber(OrderNos.getDid()); |
| | | boolean save = courseOrderService.save(courseOrder); |
| | | if (save) { |
| | | Map<String, ? extends Object> maps = |
| | | new ImmutableMap.Builder<String, String>(). |
| | | put("id", courseOrder.getId()) |
| | | .build(); |
| | | QuartzManager.addJob( |
| | | OrderJob.class, |
| | | (OrderJob.name+courseOrder.getId()).toUpperCase(), |
| | | TimeJobType.CANCEL_ORDER, |
| | | DateUtils.localDateTimeToDate(LocalDateTime.now().plusMinutes(15)), |
| | | maps |
| | | ); |
| | | Map<String, Object> result = wxV3Pay.jsApi(courseOrder.getOrderNumber(), course.getCourseCost().multiply(BigDecimal.valueOf(100)).longValue(), appUser.getOpenId(),"购买课程",""); |
| | | return R.ok(result); |
| | | // return R.ok(); |
| | | } |
| | | return R.fail("报名失败"); |
| | | // if (save) { |
| | | // Map<String, ? extends Object> maps = |
| | | // new ImmutableMap.Builder<String, String>(). |
| | | // put("id", courseOrder.getId()) |
| | | // .build(); |
| | | // QuartzManager.addJob( |
| | | // OrderJob.class, |
| | | // (OrderJob.name+courseOrder.getId()).toUpperCase(), |
| | | // TimeJobType.CANCEL_ORDER, |
| | | // DateUtils.localDateTimeToDate(LocalDateTime.now().plusMinutes(15)), |
| | | // maps |
| | | // ); |
| | | // Map<String, Object> result = wxV3Pay.jsApi(courseOrder.getOrderNumber(), course.getCourseCost().multiply(BigDecimal.valueOf(100)).longValue(), appUser.getOpenId(),"购买课程",""); |
| | | // return R.ok(result); |
| | | //// return R.ok(); |
| | | // } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @PostMapping("/payOrder") |
| | | @ApiOperation(value = "课程模块--支付订单") |
| | | public R<Map<String, Object>> payOrder(@RequestBody TCourseOrder courseOrder) { |
| | | // String userId = tokenService.getLoginUserApplet().getUserId(); |
| | | String userId = tokenService.getLoginUserApplet().getUserId(); |
| | | |
| | | TCourse course = courseService.getById(courseOrder.getCourseId()); |
| | | long count1 = insuranceOrderService.count(new LambdaQueryWrapper<TInsuranceOrder>().eq(TInsuranceOrder::getType,course.getCourseType()).eq(TInsuranceOrder::getAppUserId, userId).eq(TInsuranceOrder::getStatus, 2)); |
| | | if(count1<=0){ |
| | | return R.fail("请先缴纳保险费"); |
| | | } |
| | | // TAppUser appUser = appUserService.getById(userId); |
| | | TCourseOrder courseOrder1 = courseOrderService.getById(courseOrder.getId()); |
| | | // if(!userId.equals(courseOrder1.getAppUserId())){ |
| | | // return R.fail("无权限操作"); |
| | | // } |
| | | if(courseOrder1.getPayStatus()!=1){ |
| | | return R.fail("订单目前无法支付"); |
| | | } |
| | | courseOrder1.setOrderNumber(OrderNos.getDid()); |
| | | courseOrder1.setRealName(courseOrder.getRealName()); |
| | | courseOrder1.setUserPhone(courseOrder.getUserPhone()); |