| | |
| | | import com.ruoyi.system.dto.BuyInsuranceDto; |
| | | import com.ruoyi.system.model.*; |
| | | import com.ruoyi.system.query.GetCourseListQuery; |
| | | import com.ruoyi.system.service.TAppUserService; |
| | | import com.ruoyi.system.service.TBannerService; |
| | | import com.ruoyi.system.service.TInsuranceOrderService; |
| | | import com.ruoyi.system.service.TInsuranceService; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.vo.UserInsuranceVo; |
| | | import com.ruoyi.system.wxPay.utils.WxRefundUtil; |
| | | import com.ruoyi.system.wxPay.utils.WxV3Pay; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | |
| | | private final TInsuranceService tInsuranceService; |
| | | private final WxV3Pay wxV3Pay; |
| | | private final TAppUserService tAppUserService; |
| | | private final TCourseOrderService tCourseOrderService; |
| | | |
| | | public InsuranceController(TInsuranceOrderService tInsuranceOrderService, TokenService tokenService, TInsuranceService tInsuranceService, WxV3Pay wxV3Pay, TAppUserService tAppUserService) { |
| | | |
| | | public InsuranceController(TInsuranceOrderService tInsuranceOrderService, TokenService tokenService, TInsuranceService tInsuranceService, WxV3Pay wxV3Pay, TAppUserService tAppUserService, TCourseOrderService tCourseOrderService) { |
| | | this.tInsuranceOrderService = tInsuranceOrderService; |
| | | this.tokenService = tokenService; |
| | | this.tInsuranceService = tInsuranceService; |
| | | this.wxV3Pay = wxV3Pay; |
| | | this.tAppUserService = tAppUserService; |
| | | this.tCourseOrderService = tCourseOrderService; |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | @GetMapping("/getInsurance") |
| | | @ApiOperation(value = "保险模块--获取用户是否有保险",response = TBanner.class) |
| | | public R<UserInsuranceVo> getCourseList() { |
| | | public R<UserInsuranceVo> getCourseList(int type) { |
| | | String userId = tokenService.getLoginUserApplet().getUserId(); |
| | | UserInsuranceVo insuranceVo = new UserInsuranceVo(); |
| | | TInsuranceOrder one = tInsuranceOrderService.getOne(Wrappers.<TInsuranceOrder>lambdaQuery().eq(TInsuranceOrder::getAppUserId, userId).eq(TInsuranceOrder::getStatus, 2).orderByDesc(BaseModel::getCreateTime).last("LIMIT 1")); |
| | | TInsuranceOrder one = tInsuranceOrderService.getOne(Wrappers.<TInsuranceOrder>lambdaQuery().eq(TInsuranceOrder::getType,type).eq(TInsuranceOrder::getAppUserId, userId).eq(TInsuranceOrder::getStatus, 2).orderByDesc(BaseModel::getCreateTime).last("LIMIT 1")); |
| | | if(one!=null){ |
| | | insuranceVo.setUserId(userId); |
| | | insuranceVo.setPayTime(one.getPayTime()); |
| | |
| | | |
| | | @PostMapping("/buyInsurance") |
| | | @ApiOperation(value = "保险模块--购买保险") |
| | | public R<?> buyInsurance(@RequestBody BuyInsuranceDto dto) throws ParseException { |
| | | public R<?> buyInsurance(@RequestBody @Valid BuyInsuranceDto dto) throws ParseException { |
| | | String userId = tokenService.getLoginUserApplet().getUserId(); |
| | | TAppUser appUser = tAppUserService.getById(userId); |
| | | |
| | | // 查询保险订单 |
| | | TInsuranceOrder one = tInsuranceOrderService.getOne(Wrappers.<TInsuranceOrder>lambdaQuery().eq(TInsuranceOrder::getAppUserId, userId).eq(TInsuranceOrder::getStatus, 2).orderByDesc(BaseModel::getCreateTime).last("LIMIT 1")); |
| | | TInsuranceOrder one = tInsuranceOrderService.getOne(Wrappers.<TInsuranceOrder>lambdaQuery().eq(TInsuranceOrder::getType,dto.getCourseType()).eq(TInsuranceOrder::getAppUserId, userId).eq(TInsuranceOrder::getStatus, 2).orderByDesc(BaseModel::getCreateTime).last("LIMIT 1")); |
| | | if(one!=null){ |
| | | if(one.getEndTime().after(new Date())){ |
| | | return R.fail("您已购买保险"); |
| | |
| | | insuranceOrder.setIdCard(dto.getIdCard()); |
| | | insuranceOrder.setImg(dto.getImg()); |
| | | insuranceOrder.setPayType(dto.getType()); |
| | | TInsurance insurance = tInsuranceService.getOne(new LambdaQueryWrapper<TInsurance>().eq(TInsurance::getStatus, 1)); |
| | | insuranceOrder.setType(dto.getCourseType()); |
| | | TInsurance insurance = tInsuranceService.getOne(new LambdaQueryWrapper<TInsurance>().eq(TInsurance::getInsuranceType, dto.getCourseType()).eq(TInsurance::getStatus, 1)); |
| | | if(insurance==null){ |
| | | return R.fail("保险已关闭"); |
| | | } |
| | | insuranceOrder.setInsuranceId(insurance.getId()); |
| | | insuranceOrder.setPayMoney(BigDecimal.valueOf(insurance.getInsuranceMoney()).setScale(2, RoundingMode.HALF_UP)); |
| | | insuranceOrder.setPayMoney(insurance.getInsuranceMoney().setScale(2, RoundingMode.HALF_UP)); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | Date date = simpleDateFormat.parse(insurance.getValidityTime()); |
| | | insuranceOrder.setEndTime(date); |
| | |
| | | String payNo = OrderNos.getDid(); |
| | | insuranceOrder.setPayNo(payNo); |
| | | boolean save = tInsuranceOrderService.save(insuranceOrder); |
| | | if(dto.getType()==2){ |
| | | return R.ok(); |
| | | } |
| | | Map<String, Object> result = wxV3Pay.jsApiInsurance(payNo, insuranceOrder.getPayMoney().multiply(BigDecimal.valueOf(100)).longValue(), appUser.getOpenId(),"购买保险",""); |
| | | return R.ok(result); |
| | | } |
| | |
| | | |
| | | order1.setRequestRefundTime(new Date()); |
| | | order1.setRefundMoney(order1.getPayMoney().doubleValue()); |
| | | Integer type = order1.getType(); |
| | | |
| | | |
| | | String insuranceId = order1.getInsuranceId(); |
| | | |
| | | TInsurance insurance = tInsuranceService.getById(insuranceId); |
| | | if(insurance==null){ |
| | | return R.fail("保险已关闭,无法退款"); |
| | | } |
| | | |
| | | // 判断是否过期 |
| | | if(order1.getEndTime().before(new Date())){ |
| | | return R.fail("保险已过期,无法退款"); |
| | | } |
| | | |
| | | // 判断是否有当前的课程 待支付 和已完成 |
| | | int count = tCourseOrderService.countOrderNum( userId, type); |
| | | if(count>0){ |
| | | return R.fail("请先完成课程"); |
| | | } |
| | | |
| | | if(!userId.equals(order1.getAppUserId())){ |
| | | return R.fail("无权限操作"); |
| | |
| | | if(payTime==null){ |
| | | return R.fail("状态不允许退款"); |
| | | } |
| | | if(payTime.plusDays(2).isBefore(LocalDateTime.now())){ |
| | | if(payTime.plusDays(2).isBefore(LocalDateTime.now()) || order.getPayType()==2){ |
| | | order1.setBankCardNumber(order.getBankCardNumber()); |
| | | order1.setCardholderName(order.getCardholderName()); |
| | | order1.setRefundStatus(1); |