| | |
| | | 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.BasePage; |
| | | 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.TEmploymentInfo; |
| | | import com.ruoyi.system.model.*; |
| | | 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.service.TEmploymentInfoService; |
| | | import com.ruoyi.system.service.*; |
| | | 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.wxPay.model.WeixinPayProperties; |
| | | import com.ruoyi.system.wxPay.model.WxPaymentRefundModel; |
| | | import com.ruoyi.system.wxPay.utils.WxRefundUtil; |
| | | import com.ruoyi.system.wxPay.utils.WxV3Pay; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | |
| | | 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) |
| | |
| | | Page<TCourseOrder> page = new Page<>(query.getPageNum(), query.getPageSize()); |
| | | Page<TCourseOrder> courseOrderPage = courseOrderService.page(page, Wrappers.<TCourseOrder>lambdaQuery() |
| | | .eq(TCourseOrder::getAppUserId, userId) |
| | | .ne(TCourseOrder::getPayStatus, 4) |
| | | .eq(Objects.nonNull(query.getPayStatus()),TCourseOrder::getPayStatus, query.getPayStatus()) |
| | | .ne(TCourseOrder::getPayStatus, 4) |
| | | .orderByDesc(TCourseOrder::getCreateTime)); |
| | | List<TCourseOrder> records = courseOrderPage.getRecords(); |
| | | if(!records.isEmpty()){ |
| | |
| | | String userId = tokenService.getLoginUserApplet().getUserId(); |
| | | TAppUser appUser = appUserService.getById(userId); |
| | | TCourse course = courseService.getById(courseOrder.getCourseId()); |
| | | LocalDate endTime = course.getEndTime(); |
| | | |
| | | |
| | | 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("报名人数已满"); |
| | | } |
| | | |
| | | long userCount = courseOrderService.count(Wrappers.lambdaQuery(TCourseOrder.class) |
| | | .eq(TCourseOrder::getIdCard, courseOrder.getIdCard()) |
| | | .eq(TCourseOrder::getCourseId, course.getId()) |
| | | .in(TCourseOrder::getPayStatus, 1, 2, 5, 6)); |
| | | |
| | | if(userCount>0){ |
| | | return R.fail("该课程已提交相同的报名意向!"); |
| | | } |
| | | |
| | | courseOrder.setAppUserId(userId); |
| | | courseOrder.setPayMoney(course.getCourseCost()); |
| | | courseOrder.setPayStatus(1); |
| | | 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.ok(); |
| | | } |
| | | @PostMapping("/saveOrderAndPay") |
| | | @ApiOperation(value = "课程模块--报名并支付") |
| | | public R<Map<String, Object>> saveOrderAndPay(@RequestBody TCourseOrder courseOrder) { |
| | | String userId = tokenService.getLoginUserApplet().getUserId(); |
| | | TAppUser appUser = appUserService.getById(userId); |
| | | TCourse course = courseService.getById(courseOrder.getCourseId()); |
| | | LocalDate endTime = course.getEndTime(); |
| | | |
| | | TOtherConfig config = otherConfigService.getById(1); |
| | | if(config.getIsOpenInsurance()==1){ |
| | | 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(course.getIsOpenCourse()==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("报名人数已满"); |
| | |
| | | return R.ok(result); |
| | | // return R.ok(); |
| | | } |
| | | return R.fail("报名失败"); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @PostMapping("/payOrder") |
| | | @ApiOperation(value = "课程模块--支付订单") |
| | | public R<Map<String, Object>> payOrder(@RequestBody TCourseOrder courseOrder) { |
| | | // String userId = tokenService.getLoginUserApplet().getUserId(); |
| | | // TAppUser appUser = appUserService.getById(userId); |
| | | String userId = tokenService.getLoginUserApplet().getUserId(); |
| | | TCourseOrder courseOrder1 = courseOrderService.getById(courseOrder.getId()); |
| | | TCourse course = courseService.getById(courseOrder1.getCourseId()); |
| | | |
| | | TOtherConfig config = otherConfigService.getById(1); |
| | | if(config.getIsOpenInsurance()==1){ |
| | | 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); |
| | | |
| | | // 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()); |
| | | courseOrder1.setIdCard(courseOrder.getIdCard()); |
| | | |
| | | courseOrderService.updateById(courseOrder1); |
| | | Map<String, Object> result = wxV3Pay.jsApi(courseOrder1.getOrderNumber(), courseOrder1.getPayMoney().multiply(BigDecimal.valueOf(100)).longValue(), "oz71-1_OevadwmESB_IFAW7PucWY","购买课程",""); |
| | | Map<String, Object> result = wxV3Pay.jsApi(courseOrder1.getOrderNumber(), courseOrder1.getPayMoney().multiply(BigDecimal.valueOf(100)).longValue(), appUser.getOpenId(),"购买课程",""); |
| | | return R.ok(result); |
| | | } |
| | | |
| | |
| | | TCourseOrder courseOrder1 = courseOrderService.getById(courseOrder.getId()); |
| | | courseOrder1.setRefundReason(courseOrder.getRefundReason()); |
| | | courseOrder1.setRefundReasonPictures(courseOrder.getRefundReasonPictures()); |
| | | courseOrder1.setPayStatus(6); |
| | | |
| | | courseOrder1.setRequestRefundTime(LocalDateTime.now()); |
| | | courseOrder1.setRefundMoney(courseOrder1.getPayMoney()); |
| | | |
| | |
| | | if(courseOrder1.getPayStatus()!=2){ |
| | | return R.fail("状态不允许退款"); |
| | | } |
| | | courseOrder1.setPayStatus(6); |
| | | LocalDateTime payTime = courseOrder1.getPayTime(); |
| | | if(payTime==null){ |
| | | return R.fail("状态不允许退款"); |
| | |
| | | courseOrder1.setRefundStatus(1); |
| | | courseOrderService.updateById(courseOrder1); |
| | | }else { |
| | | WxPaymentRefundModel refundModel = new WxPaymentRefundModel(); |
| | | refundModel.setSub_mchid(weixinPayProperties.getMchId()); |
| | | refundModel.setSp_appid(weixinPayProperties.getAppId()); |
| | | refundModel.setTransaction_id(courseOrder1.getTransactionId()); |
| | | refundModel.setOut_trade_no(courseOrder1.getOrderNumber()); |
| | | refundModel.setOut_refund_no(OrderNos.getDid()); |
| | | refundModel.setReason(courseOrder1.getRefundReason()); |
| | | refundModel.setNotify_url(""); |
| | | refundModel.setFunds_account("AVAILABLE"); |
| | | refundModel.setAmount(new WxPaymentRefundModel.RefundAmount(courseOrder1.getPayMoney().multiply(BigDecimal.valueOf(100)).intValue(), "CNY", courseOrder1.getPayMoney().multiply(BigDecimal.valueOf(100)).intValue())); |
| | | Map<String, Object> refund = wxV3Pay.refund(refundModel); |
| | | |
| | | String outRefundNo = OrderNos.getDid(); |
| | | courseOrder1.setRefundNumber(outRefundNo); |
| | | courseOrderService.updateById(courseOrder1); |
| | | // WxPaymentRefundModel refundModel = new WxPaymentRefundModel(); |
| | | //// refundModel.setSub_mchid(weixinPayProperties.getMchId()); |
| | | //// refundModel.setSp_appid(weixinPayProperties.getAppId()); |
| | | //// refundModel.setTransaction_id(courseOrder1.getTransactionId()); |
| | | // refundModel.setOut_trade_no(courseOrder1.getOrderNumber()); |
| | | // refundModel.setOut_refund_no(OrderNos.getDid()); |
| | | // refundModel.setReason(courseOrder1.getRefundReason()); |
| | | // refundModel.setGoods_detail(new ArrayList<>()); |
| | | // refundModel.setAmount(new WxPaymentRefundModel.RefundAmount(courseOrder1.getPayMoney().multiply(BigDecimal.valueOf(100)).intValue(), "CNY", courseOrder1.getPayMoney().multiply(BigDecimal.valueOf(100)).intValue())); |
| | | // Map<String, Object> refund = wxV3Pay.refund(refundModel); |
| | | // System.out.println(refund); |
| | | String result = wxRefundUtil.refund(courseOrder1.getPayMoney().multiply(BigDecimal.valueOf(100)).intValue(), courseOrder1.getOrderNumber(),outRefundNo); |
| | | if(result!=null){ |
| | | return R.fail(result); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Autowired |
| | | private WxRefundUtil wxRefundUtil; |
| | | |
| | | } |