huliguo
9 天以前 0440f99f2874e54532c80d644644e04febf51a50
ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/miniapp/AppLotteryEventController.java
@@ -25,6 +25,7 @@
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
@@ -69,6 +70,16 @@
   })
   public R<LotteryEventVo> getLotteryEvent(@PathVariable("id") String id) {
      LotteryEventVo lotteryEvent = lotteryEventService.getLotteryEvent(id);
      TLotteryEvent event = lotteryEventService.getById(id);
      if (LocalDateTime.now().isBefore(event.getStartTime())) {
         lotteryEvent.setStatus(1);
      }
      if (LocalDateTime.now().isAfter(event.getEndTime())) {
         lotteryEvent.setStatus(3);
      }
      if (LocalDateTime.now().isAfter(event.getStartTime()) && LocalDateTime.now().isBefore(event.getEndTime())) {
         lotteryEvent.setStatus(2);
      }
      return R.ok(lotteryEvent);
   }
   
@@ -79,7 +90,7 @@
   @ApiImplicitParams({
         @ApiImplicitParam(name = "id", value = "抽奖活动id", required = true, dataType = "String", paramType = "path")
   })
   public R lotteryDraw(@PathVariable("id") String id) {
   public R<TLotteryEventPrize> lotteryDraw(@PathVariable("id") String id) {
      return lotteryEventService.lotteryDraw(id);
   }
   
@@ -96,13 +107,13 @@
      activityPageVoList.forEach(vo -> {
         String startTime = vo.getStartTime();
         String endTime = vo.getEndTime();
         if (LocalDateTime.now().isBefore(LocalDateTime.parse(startTime))) {
         if (LocalDateTime.now().isBefore(LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) {
            vo.setStatus(1);
         }
         if (LocalDateTime.now().isAfter(LocalDateTime.parse(endTime))) {
         if (LocalDateTime.now().isAfter(LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) {
            vo.setStatus(3);
         }
         if (LocalDateTime.now().isAfter(LocalDateTime.parse(startTime)) && LocalDateTime.now().isBefore(LocalDateTime.parse(endTime))) {
         if (LocalDateTime.now().isAfter(LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))) && LocalDateTime.now().isBefore(LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) {
            vo.setStatus(2);
         }
      });
@@ -124,6 +135,7 @@
      vo.setName(lotteryEvent.getName());
      vo.setActivityProfile(lotteryEvent.getActivityProfile());
      vo.setStartTime(lotteryEvent.getStartTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
      vo.setEndTime(lotteryEvent.getEndTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
      vo.setActivityContent(lotteryEvent.getActivityContent());
      int count = userLotteryEventService.count(new QueryWrapper<TUserLotteryEvent>().eq("lottery_event_id", id).eq("user_id", userId));
      vo.setParticipation(count > 0);
@@ -133,6 +145,12 @@
         vo.setContinueAnswer(null != questionsServiceOne ? questionsServiceOne.getStatus() : 0);
         vo.setAnswerStartTime(null != questionsServiceOne ? questionsServiceOne.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) : null);
         vo.setAnswerTimeLimit(lotteryEvent.getAnsweringTime());
         if (vo.getContinueAnswer() == 1) {
            long remainingTime = (lotteryEvent.getAnsweringTime() * 60) - (LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")) - questionsServiceOne.getCreateTime().toEpochSecond(ZoneOffset.of("+8")));
            int count1 = userLotteryEventQuestionsAnswersService.count(new QueryWrapper<TUserLotteryEventQuestionsAnswers>().eq("lottery_event_id", id).eq("user_id", userId));
            vo.setRemainingTime(remainingTime);
            vo.setCurrent(count1 - 1);
         }
      }
      return R.ok(vo);
   }
@@ -167,16 +185,17 @@
         //上一题
         Integer current = dto.getCurrent();
         if (-1 == dto.getStepOrDown()) {
            if (current - 1 <= 0) {
               return R.fail("操作失败");
            if (current - 1 < 0) {
               current = 0;
            }
            current--;
         } else {
            //下一题
            if (current >= count) {
               return R.fail("操作失败");
            }
            current++;
            //下一题
            current++;
            if (current >= count) {
               current = count - 1;
            }
         }
         List<TLotteryEventQuestions> list = lotteryEventServiceQuestionsService.list(new QueryWrapper<TLotteryEventQuestions>().eq("lottery_event_id", dto.getId()).orderByAsc("sort"));
         TLotteryEventQuestions lotteryEventQuestions = list.get(current);
@@ -190,7 +209,7 @@
            map.put("name", item.getAnswers());
            return map;
         }).collect(Collectors.toList());
         if (-1 == dto.getStepOrDown()) {
         if (-1 == dto.getStepOrDown() || current == list.size() - 1) {
            TUserLotteryEventQuestionsAnswers one = userLotteryEventQuestionsAnswersService.getOne(new QueryWrapper<TUserLotteryEventQuestionsAnswers>().eq("lottery_event_id", dto.getId()).eq("user_id", userId).orderByDesc("create_time").last(" limit 0, 1"));
            if (null != one) {
               vo.setAnswer(lotteryEventQuestionsAnswersService.getById(one.getLotteryEventQuestionsAnswersId()).getAnswers());
@@ -231,6 +250,8 @@
         one.setLotteryEventQuestionId(lotteryEventQuestions.getId());
         one.setLotteryEventQuestionsAnswersId(lotteryEventQuestionsAnswers.getId());
         one.setCreateTime(LocalDateTime.now());
      }else{
         one.setLotteryEventQuestionsAnswersId(lotteryEventQuestionsAnswers.getId());
      }
      one.setIsCorrect(0);
      //答案正确
@@ -238,6 +259,8 @@
         one.setIsCorrect(1);
      }
      userLotteryEventQuestionsAnswersService.saveOrUpdate(one);
      //判断
      return R.ok();
   }
   
@@ -251,6 +274,14 @@
      Long userId = SecurityUtils.getUserId();
      TLotteryEvent lotteryEvent = lotteryEventService.getById(id);
      TUserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsService.getOne(new QueryWrapper<TUserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId));
      if (null == questionsServiceOne) {
         questionsServiceOne = new TUserLotteryEventQuestions();
         questionsServiceOne.setId(IdUtils.simpleUUID());
         questionsServiceOne.setUserId(userId);
         questionsServiceOne.setLotteryEventId(id);
         questionsServiceOne.setStatus(1);
         questionsServiceOne.setCreateTime(LocalDateTime.now());
      }
      questionsServiceOne.setStatus(2);
      questionsServiceOne.setEndTime(LocalDateTime.now());
      //计算正确率
@@ -259,7 +290,7 @@
      int right = list.stream().filter(item -> 1 == item.getIsCorrect()).collect(Collectors.toList()).size();
      BigDecimal multiply = new BigDecimal(right).divide(new BigDecimal(count), 4, BigDecimal.ROUND_HALF_UP).setScale(4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
      questionsServiceOne.setCorrectAnswerRate(multiply);
      userLotteryEventQuestionsService.updateById(questionsServiceOne);
      userLotteryEventQuestionsService.saveOrUpdate(questionsServiceOne);
      if (multiply.compareTo(lotteryEvent.getAccuracy()) >= 0) {
         return R.ok(true);
      }