Pu Zhibing
5 天以前 ea1a62ba6484d6c6cb1ca67dcea938a95ba18fc6
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.ruoyi.goods.controller.miniapp;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.goods.api.domain.LotteryEvent;
import com.ruoyi.goods.api.domain.UserLotteryEvent;
import com.ruoyi.goods.api.domain.UserLotteryEventQuestions;
import com.ruoyi.goods.domain.vo.AppLotteryEventPageVo;
import com.ruoyi.goods.domain.vo.LotteryEventInfoVo;
import com.ruoyi.goods.domain.vo.LotteryEventVo;
import com.ruoyi.goods.service.lottery.ILotteryEventService;
import com.ruoyi.goods.service.lottery.IUserLotteryEventQuestionsService;
import com.ruoyi.goods.service.lottery.IUserLotteryEventService;
import com.ruoyi.system.api.domain.dto.LotteryEventListDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.time.format.DateTimeFormatter;
import java.util.List;
 
/**
 * @author zhibing.pu
 * @Date 2025/5/26 15:26
 */
@Validated
@RestController
@RequiredArgsConstructor
@Api(tags = "小程序抽奖相关接口")
@RequestMapping("/app/lotteryEvent")
public class AppLotteryEventController {
    
    @Resource
    private ILotteryEventService lotteryEventService;
    
    @Resource
    private IUserLotteryEventService userLotteryEventService;
    
    @Resource
    private IUserLotteryEventQuestionsService userLotteryEventQuestionsService;
    
    
    
    
    @ResponseBody
    @PostMapping("/getLotteryEvent/{id}")
    @ApiOperation(value = "获取抽奖页详情【2.0】", tags = "抽奖活动")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "抽奖活动id", required = true, dataType = "String", paramType = "path")
    })
    public R<LotteryEventVo> getLotteryEvent(@PathVariable("id") String id) {
        LotteryEventVo lotteryEvent = lotteryEventService.getLotteryEvent(id);
        return R.ok(lotteryEvent);
    }
    
    
    @ResponseBody
    @PostMapping("/lotteryDraw/{id}")
    @ApiOperation(value = "抽奖操作【2.0】", tags = "抽奖活动", notes = "返回奖品ID")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "抽奖活动id", required = true, dataType = "String", paramType = "path")
    })
    public R lotteryDraw(@PathVariable("id") String id) {
        return lotteryEventService.lotteryDraw(id);
    }
    
    
    @ResponseBody
    @PostMapping("/getLotteryEventList")
    @ApiOperation(value = "获取普通抽奖列表【2.0】", tags = "抽奖活动")
    public R<Page<AppLotteryEventPageVo>> getLotteryEventList(@RequestBody LotteryEventListDto dto){
        Long userId = SecurityUtils.getUserId();
        Page<AppLotteryEventPageVo> page = new Page<>();
        page.setSize(dto.getPageSize());
        page.setCurrent(dto.getPageNum());
        List<AppLotteryEventPageVo> activityPageVoList = lotteryEventService.pageAppLotteryEvent(page,userId);
        return R.ok(page.setRecords(activityPageVoList));
    }
    
    
    @ResponseBody
    @PostMapping("/getLotteryEventInfo/{id}")
    @ApiOperation(value = "获取抽奖活动详情【2.0】", tags = "抽奖活动")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "抽奖活动id", required = true, dataType = "String", paramType = "path")
    })
    public R<LotteryEventInfoVo> getLotteryEventInfo(@PathVariable("id") String id){
        Long userId = SecurityUtils.getUserId();
        LotteryEvent lotteryEvent = lotteryEventService.getById(id);
        LotteryEventInfoVo vo = new LotteryEventInfoVo();
        vo.setId(lotteryEvent.getId());
        vo.setName(lotteryEvent.getName());
        vo.setActivityProfile(lotteryEvent.getActivityProfile());
        vo.setStartTime(lotteryEvent.getStartTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        vo.setActivityContent(lotteryEvent.getActivityContent());
        int count = userLotteryEventService.count(new QueryWrapper<UserLotteryEvent>().eq("lottery_event_id", id).eq("user_id", userId));
        vo.setParticipation(count > 0);
        //答题抽奖需要判断是否答题完成
        if(5 == lotteryEvent.getActivityType()){
            UserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsService.getOne(new QueryWrapper<UserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId));
            vo.setContinueAnswer(null != questionsServiceOne ? questionsServiceOne.getStatus() : 0);
        }
        return R.ok(vo);
    }
    
}