liujie
2025-12-29 b97ec797b8f07dbb21ea723e9f2c82b8e4a88e2f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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("购买失败");
    }
 
 
}