From b646898adf3f2ad119dd9fd1c7c01d7f0742bf97 Mon Sep 17 00:00:00 2001
From: huliguo <2023611923@qq.com>
Date: 星期四, 31 七月 2025 11:41:31 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/2.0' into 2.0

---
 ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/miniapp/AppLotteryEventController.java |   68 +++++++++++++++++++++------------
 1 files changed, 43 insertions(+), 25 deletions(-)

diff --git a/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/miniapp/AppLotteryEventController.java b/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/miniapp/AppLotteryEventController.java
index 06010bc..284d34d 100644
--- a/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/miniapp/AppLotteryEventController.java
+++ b/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/miniapp/AppLotteryEventController.java
@@ -56,19 +56,19 @@
 	private IUserLotteryEventQuestionsAnswersService userLotteryEventQuestionsAnswersService;
 	
 	@Resource
-	private ILotteryEventQuestionsService lotteryEventServiceQuestionsService;
+	private ILotteryEventQuestionsService lotteryEventQuestionsService;
 	
 	@Resource
 	private ILotteryEventQuestionsAnswersService lotteryEventQuestionsAnswersService;
 	
 	
 	@ResponseBody
-	@PostMapping("/getLotteryEvent/{id}")
+	@PostMapping("/getLotteryEvent/{id}/{orderId}")
 	@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) {
+	public R<LotteryEventVo> getLotteryEvent(@PathVariable("id") String id, @PathVariable("orderId") String orderId) {
 		LotteryEventVo lotteryEvent = lotteryEventService.getLotteryEvent(id);
 		TLotteryEvent event = lotteryEventService.getById(id);
 		if (LocalDateTime.now().isBefore(event.getStartTime())) {
@@ -85,12 +85,12 @@
 	
 	
 	@ResponseBody
-	@PostMapping("/lotteryDraw/{id}")
+	@PostMapping("/lotteryDraw/{id}/{orderId}")
 	@ApiOperation(value = "抽奖操作【2.0】", tags = "抽奖活动", notes = "返回奖品ID")
 	@ApiImplicitParams({
 			@ApiImplicitParam(name = "id", value = "抽奖活动id", required = true, dataType = "String", paramType = "path")
 	})
-	public R<TLotteryEventPrize> lotteryDraw(@PathVariable("id") String id) {
+	public R<TLotteryEventPrize> lotteryDraw(@PathVariable("id") String id, @PathVariable("orderId") String orderId) {
 		return lotteryEventService.lotteryDraw(id);
 	}
 	
@@ -122,12 +122,12 @@
 	
 	
 	@ResponseBody
-	@PostMapping("/getLotteryEventInfo/{id}")
+	@PostMapping("/getLotteryEventInfo/{id}/{orderId}")
 	@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){
+	public R<LotteryEventInfoVo> getLotteryEventInfo(@PathVariable("id") String id, @PathVariable("orderId") String orderId){
 		Long userId = SecurityUtils.getUserId();
 		TLotteryEvent lotteryEvent = lotteryEventService.getById(id);
 		LotteryEventInfoVo vo = new LotteryEventInfoVo();
@@ -162,14 +162,15 @@
 		Long userId = SecurityUtils.getUserId();
 		TUserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsService.getOne(new QueryWrapper<TUserLotteryEventQuestions>().eq("lottery_event_id", dto.getId()).eq("user_id", userId));
 		LotteryEventQuestionsVo vo = new LotteryEventQuestionsVo();
-		int count = lotteryEventServiceQuestionsService.count(new QueryWrapper<TLotteryEventQuestions>().eq("lottery_event_id", dto.getId()));
+		vo.setId(dto.getId());
+		int count = lotteryEventQuestionsService.count(new QueryWrapper<TLotteryEventQuestions>().eq("lottery_event_id", dto.getId()));
 		vo.setTotal(count);
 		//没有答题,直接从第一题开始
 		if (null == questionsServiceOne) {
 			if (-1 == dto.getStepOrDown()) {
 				return R.fail("操作失败");
 			}
-			TLotteryEventQuestions questions = lotteryEventServiceQuestionsService.getOne(new QueryWrapper<TLotteryEventQuestions>().eq("lottery_event_id", dto.getId()).orderByAsc("sort").last(" limit 1"));
+			TLotteryEventQuestions questions = lotteryEventQuestionsService.getOne(new QueryWrapper<TLotteryEventQuestions>().eq("lottery_event_id", dto.getId()).orderByAsc("sort").last(" limit 1"));
 			vo.setCurrent(0);
 			vo.setName(questions.getName());
 			List<TLotteryEventQuestionsAnswers> list = lotteryEventQuestionsAnswersService.list(new QueryWrapper<TLotteryEventQuestionsAnswers>().eq("lottery_event_questions_id", questions.getId()));
@@ -186,17 +187,17 @@
 			Integer current = dto.getCurrent();
 			if (-1 == dto.getStepOrDown()) {
 				if (current - 1 < 0) {
-					return R.fail("操作失败");
+					current = 0;
 				}
 				current--;
 			} else {
 				//下一题
-				if (current >= count) {
-					return R.fail("操作失败");
-				}
 				current++;
+				if (current >= count) {
+					current = count - 1;
+				}
 			}
-			List<TLotteryEventQuestions> list = lotteryEventServiceQuestionsService.list(new QueryWrapper<TLotteryEventQuestions>().eq("lottery_event_id", dto.getId()).orderByAsc("sort"));
+			List<TLotteryEventQuestions> list = lotteryEventQuestionsService.list(new QueryWrapper<TLotteryEventQuestions>().eq("lottery_event_id", dto.getId()).orderByAsc("sort"));
 			TLotteryEventQuestions lotteryEventQuestions = list.get(current);
 			vo.setCurrent(current);
 			vo.setName(lotteryEventQuestions.getName());
@@ -208,12 +209,18 @@
 				map.put("name", item.getAnswers());
 				return map;
 			}).collect(Collectors.toList());
-			if (-1 == dto.getStepOrDown()) {
-				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());
-				}
+
+			TUserLotteryEventQuestionsAnswers one = userLotteryEventQuestionsAnswersService.getOne(new QueryWrapper<TUserLotteryEventQuestionsAnswers>().eq("lottery_event_question_id", lotteryEventQuestions.getId()).eq("user_id", userId).orderByDesc("create_time").last(" limit 0, 1"));
+			if (null != one) {
+				vo.setAnswer(lotteryEventQuestionsAnswersService.getById(one.getLotteryEventQuestionsAnswersId()).getAnswers());
 			}
+
+//			if (-1 == dto.getStepOrDown() || current == list.size() - 1) {
+//				TUserLotteryEventQuestionsAnswers one = userLotteryEventQuestionsAnswersService.getOne(new QueryWrapper<TUserLotteryEventQuestionsAnswers>().eq("lottery_event_question_id", lotteryEventQuestions.getId()).eq("user_id", userId).orderByDesc("create_time").last(" limit 0, 1"));
+//				if (null != one) {
+//					vo.setAnswer(lotteryEventQuestionsAnswersService.getById(one.getLotteryEventQuestionsAnswersId()).getAnswers());
+//				}
+//			}
 			vo.setOptions(options);
 		}
 		return R.ok(vo);
@@ -223,7 +230,7 @@
 	@PostMapping("/answerQuestion")
 	@ApiOperation(value = "答题操作【2.0】", tags = "抽奖活动")
 	public R answerQuestion(@RequestBody AnswerQuestionDto dto) {
-		List<TLotteryEventQuestions> list = lotteryEventServiceQuestionsService.list(new QueryWrapper<TLotteryEventQuestions>().eq("lottery_event_id", dto.getId()).orderByAsc("sort"));
+		List<TLotteryEventQuestions> list = lotteryEventQuestionsService.list(new QueryWrapper<TLotteryEventQuestions>().eq("lottery_event_id", dto.getId()).orderByAsc("sort"));
 		TLotteryEventQuestions lotteryEventQuestions = list.get(dto.getCurrent());
 		List<TLotteryEventQuestionsAnswers> list1 = lotteryEventQuestionsAnswersService.list(new QueryWrapper<TLotteryEventQuestionsAnswers>().eq("lottery_event_questions_id", lotteryEventQuestions.getId()));
 		TLotteryEventQuestionsAnswers lotteryEventQuestionsAnswers = list1.stream().filter(item -> item.getAnswers().equals(dto.getAnswer())).findAny().orElse(null);
@@ -249,6 +256,8 @@
 			one.setLotteryEventQuestionId(lotteryEventQuestions.getId());
 			one.setLotteryEventQuestionsAnswersId(lotteryEventQuestionsAnswers.getId());
 			one.setCreateTime(LocalDateTime.now());
+		}else{
+			one.setLotteryEventQuestionsAnswersId(lotteryEventQuestionsAnswers.getId());
 		}
 		one.setIsCorrect(0);
 		//答案正确
@@ -256,6 +265,8 @@
 			one.setIsCorrect(1);
 		}
 		userLotteryEventQuestionsAnswersService.saveOrUpdate(one);
+		//判断
+
 		return R.ok();
 	}
 	
@@ -268,19 +279,26 @@
 	public R<Boolean> endAnswerQuestion(@PathVariable("id") String id) {
 		Long userId = SecurityUtils.getUserId();
 		TLotteryEvent lotteryEvent = lotteryEventService.getById(id);
+		if(null == lotteryEvent){
+			return R.fail("无效的抽奖活动id");
+		}
 		TUserLotteryEventQuestions questionsServiceOne = userLotteryEventQuestionsService.getOne(new QueryWrapper<TUserLotteryEventQuestions>().eq("lottery_event_id", id).eq("user_id", userId));
 		if (null == questionsServiceOne) {
-			return R.fail("请先进行答题操作");
+			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());
 		//计算正确率
-		List<TUserLotteryEventQuestionsAnswers> list = userLotteryEventQuestionsAnswersService.list(new QueryWrapper<TUserLotteryEventQuestionsAnswers>().eq("lottery_event_id", id).eq("user_id", userId));
-		int count = list.size();
-		int right = list.stream().filter(item -> 1 == item.getIsCorrect()).collect(Collectors.toList()).size();
+		int count = lotteryEventQuestionsService.count(new QueryWrapper<TLotteryEventQuestions>().eq("lottery_event_id", id));
+		int right = userLotteryEventQuestionsAnswersService.count(new QueryWrapper<TUserLotteryEventQuestionsAnswers>().eq("lottery_event_id", id).eq("user_id", userId).eq("is_correct", 1));
 		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);
 		}

--
Gitblit v1.7.1