| New file |
| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.core.domain.BaseModel; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.dto.BuyInsuranceDto; |
| | | import com.ruoyi.system.model.TBanner; |
| | | import com.ruoyi.system.model.TCourse; |
| | | import com.ruoyi.system.model.TInsuranceOrder; |
| | | import com.ruoyi.system.query.GetCourseListQuery; |
| | | import com.ruoyi.system.service.TInsuranceOrderService; |
| | | import com.ruoyi.system.vo.UserInsuranceVo; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.Objects; |
| | | |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping("/insurance") |
| | | @Api(tags = "保险模块") |
| | | public class InsuranceController { |
| | | |
| | | private final TInsuranceOrderService tInsuranceOrderService; |
| | | private final TokenService tokenService; |
| | | |
| | | public InsuranceController(TInsuranceOrderService tInsuranceOrderService, TokenService tokenService) { |
| | | this.tInsuranceOrderService = tInsuranceOrderService; |
| | | this.tokenService = tokenService; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取是否支付了保险费 是否到期 |
| | | */ |
| | | @GetMapping("/getInsurance") |
| | | @ApiOperation(value = "保险模块--获取用户是否有保险",response = TBanner.class) |
| | | public R<UserInsuranceVo> getCourseList() { |
| | | 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")); |
| | | if(one!=null){ |
| | | insuranceVo.setUserId(userId); |
| | | insuranceVo.setPayTime(one.getPayTime()); |
| | | insuranceVo.setEndTime(one.getEndTime()); |
| | | } |
| | | return R.ok(insuranceVo); |
| | | } |
| | | |
| | | |
| | | |
| | | @PostMapping("/buyInsurance") |
| | | @ApiOperation(value = "保险模块--购买保险") |
| | | public R<?> buyInsurance(@RequestBody BuyInsuranceDto dto) { |
| | | String userId = tokenService.getLoginUserApplet().getUserId(); |
| | | // 查询保险订单 |
| | | TInsuranceOrder one = tInsuranceOrderService.getOne(Wrappers.<TInsuranceOrder>lambdaQuery().eq(TInsuranceOrder::getAppUserId, userId).eq(TInsuranceOrder::getStatus, 2).orderByDesc(BaseModel::getCreateTime).last("LIMIT 1")); |
| | | if(one!=null){ |
| | | return R.fail("您已购买保险"); |
| | | } |
| | | TInsuranceOrder insuranceOrder = new TInsuranceOrder(); |
| | | insuranceOrder.setAppUserId(userId); |
| | | insuranceOrder.setName(dto.getName()); |
| | | insuranceOrder.setPhone(dto.getPhone()); |
| | | insuranceOrder.setIdCard(dto.getIdCard()); |
| | | insuranceOrder.setImg(dto.getImg()); |
| | | insuranceOrder.setPayType(dto.getType()); |
| | | |
| | | |
| | | |
| | | boolean save = tInsuranceOrderService.save(insuranceOrder); |
| | | if(save){ |
| | | return R.ok("购买成功"); |
| | | } |
| | | return R.fail("购买失败"); |
| | | } |
| | | |
| | | |
| | | } |