浏览代码

最新后台代码

5 年之前
父节点
当前提交
ce5c00fb7f
共有 1 个文件被更改,包括 92 次插入93 次删除
  1. 92 93
      minigame/src/com/hssx/controller/PrizeController.java

+ 92 - 93
minigame/src/com/hssx/controller/PrizeController.java

@@ -57,7 +57,7 @@ public class PrizeController {
 	public void luckDraw(@RequestParam(required = false) Integer userId, HttpServletResponse response)
 			throws Exception, KeyManagementException, NoSuchAlgorithmException, NoSuchProviderException, IOException {
 		HttpRespMsg msg = new HttpRespMsg();
-		userId = new Random().nextInt(6)+1;//测试用
+//		userId = new Random().nextInt(6) + 1;// 测试用
 		Integer count = -1;
 		PrizeRecord prizeRecord = new PrizeRecord();
 		User user = usermapper.selectByPrimaryKey(userId);
@@ -70,112 +70,111 @@ public class PrizeController {
 		HashMap<String, Object> map = new HashMap<String, Object>();
 		// 模拟无限次数抽奖
 		// 测试必定中奖账号
-		if ("o1L3L5vwFkGSUMpec3uwRgsI6A-M".equals(user.getVoucherId())) {
-			Prize prize = prizeMapper.selectByPrimaryKey(1);
-			// UserPrizeCount userPrizeCount = new UserPrizeCount();
-			// userPrizeCount.setUserId(userId);
-			// UserPrizeCountMapper.insert(userPrizeCount);
-			map.put("prizeLevel", 0);
-			map.put("prizeRecord", prizeRecord);
-			map.put("prize", prize);
-			msg.data = map;
-			response.setContentType("application/json");
-			response.setCharacterEncoding("UTF-8");
-			response.getWriter().println(msg.toJSONStr());
-			return;
-		}
-		// if (luckDrawCount <= 1) {
-		// 直接抽奖(每日默认2次抽奖机会)
-		synchronized (this) {
-			Random ran = new Random();
-			int num = ran.nextInt(9999);
-			Prize prize = prizeMapper.selectByPrimaryKey(num);
-			if (prize == null) {
-				count = -1;
-			} else {
-				if (prize.getPrizeLevel() == 5 || prize.getIsSelected() == 1) {
+//		if ("o1L3L5vwFkGSUMpec3uwRgsI6A-M".equals(user.getVoucherId())) {
+//			Prize prize = prizeMapper.selectByPrimaryKey(1);
+//			// UserPrizeCount userPrizeCount = new UserPrizeCount();
+//			// userPrizeCount.setUserId(userId);
+//			// UserPrizeCountMapper.insert(userPrizeCount);
+//			map.put("prizeLevel", 0);
+//			map.put("prizeRecord", prizeRecord);
+//			map.put("prize", prize);
+//			msg.data = map;
+//			response.setContentType("application/json");
+//			response.setCharacterEncoding("UTF-8");
+//			response.getWriter().println(msg.toJSONStr());
+//			return;
+//		}
+		if (luckDrawCount <= 1) {
+			// 直接抽奖(每日默认2次抽奖机会)
+			synchronized (this) {
+				Random ran = new Random();
+				int num = ran.nextInt(9999);
+				Prize prize = prizeMapper.selectByPrimaryKey(num);
+				if (prize == null) {
 					count = -1;
 				} else {
-					if (prize.getPrizeLevel() == 0 && prize.getIsSelected() == 0) {
-						count = 0;
-					} else if (prize.getPrizeLevel() == 1 && prize.getIsSelected() == 0) {
-						count = 1;
-					} else if (prize.getPrizeLevel() == 2 && prize.getIsSelected() == 0) {
-						count = 2;
-					} else if (prize.getPrizeLevel() == 3 && prize.getIsSelected() == 0) {
-						count = 3;
-					} else if (prize.getPrizeLevel() == 4 && prize.getIsSelected() == 0) {
-						count = 4;
+					if (prize.getPrizeLevel() == 5 || prize.getIsSelected() == 1) {
+						count = -1;
+					} else {
+						if (prize.getPrizeLevel() == 0 && prize.getIsSelected() == 0) {
+							count = 0;
+						} else if (prize.getPrizeLevel() == 1 && prize.getIsSelected() == 0) {
+							count = 1;
+						} else if (prize.getPrizeLevel() == 2 && prize.getIsSelected() == 0) {
+							count = 2;
+						} else if (prize.getPrizeLevel() == 3 && prize.getIsSelected() == 0) {
+							count = 3;
+						} else if (prize.getPrizeLevel() == 4 && prize.getIsSelected() == 0) {
+							count = 4;
+						}
+						 prize.setIsSelected(1);
+						 prizeMapper.updateByPrimaryKeySelective(prize);
+						prizeRecord.setPrizeId(prize.getPrizeLevel());
+						prizeRecord.setPrize(prize.getName());
+						prizeRecordMapper.insert(prizeRecord);
 					}
-					// prize.setIsSelected(1);
-					// prizeMapper.updateByPrimaryKeySelective(prize);
-					prizeRecord.setPrizeId(prize.getPrizeLevel());
-					prizeRecord.setPrize(prize.getName());
-					prizeRecordMapper.insert(prizeRecord);
 				}
 			}
-		}
-//		count = getLuckDraw(prizeRecord, count);
-		// 添加抽奖记录
-		UserPrizeCount userPrizeCount = new UserPrizeCount();
-		userPrizeCount.setUserId(userId);
-		UserPrizeCountMapper.insert(userPrizeCount);
-		map.put("prizeLevel", count);
-		map.put("prizeRecord", prizeRecord);
-		msg.data = map;
-		// } else if (luckDrawCount == 2) {
-		// int opportunityCount =
-		// prizeOpportunityMapper.selectCountByToday(userId);
-		// if (opportunityCount > 0) {
-		// // 已分享直接抽奖
-		synchronized (this) {
-			Random ran = new Random();
-			int num = ran.nextInt(9999);
-			Prize prize = prizeMapper.selectByPrimaryKey(num);
-			if (prize == null) {
-				count = -1;
-			} else {
-				if (prize.getPrizeLevel() == 5 || prize.getIsSelected() == 1) {
-					count = -1;
-				} else {
-					if (prize.getPrizeLevel() == 0 && prize.getIsSelected() == 0) {
-						count = 0;
-					} else if (prize.getPrizeLevel() == 1 && prize.getIsSelected() == 0) {
-						count = 1;
-					} else if (prize.getPrizeLevel() == 2 && prize.getIsSelected() == 0) {
-						count = 2;
-					} else if (prize.getPrizeLevel() == 3 && prize.getIsSelected() == 0) {
-						count = 3;
-					} else if (prize.getPrizeLevel() == 4 && prize.getIsSelected() == 0) {
-						count = 4;
+			// count = getLuckDraw(prizeRecord, count);
+			// 添加抽奖记录
+			UserPrizeCount userPrizeCount = new UserPrizeCount();
+			userPrizeCount.setUserId(userId);
+			UserPrizeCountMapper.insert(userPrizeCount);
+			map.put("prizeLevel", count);
+			map.put("prizeRecord", prizeRecord);
+			msg.data = map;
+		} else if (luckDrawCount == 2) {
+			int opportunityCount = prizeOpportunityMapper.selectCountByToday(userId);
+			if (opportunityCount > 0) {
+				// 已分享直接抽奖
+				synchronized (this) {
+					Random ran = new Random();
+					int num = ran.nextInt(108);// 50%中奖概率
+					Prize prize = prizeMapper.selectByPrimaryKey(num);
+					if (prize == null) {
+						count = -1;
+					} else {
+						if (prize.getPrizeLevel() == 5 || prize.getIsSelected() == 1) {
+							count = -1;
+						} else {
+							if (prize.getPrizeLevel() == 0 && prize.getIsSelected() == 0) {
+								count = 0;
+							} else if (prize.getPrizeLevel() == 1 && prize.getIsSelected() == 0) {
+								count = 1;
+							} else if (prize.getPrizeLevel() == 2 && prize.getIsSelected() == 0) {
+								count = 2;
+							} else if (prize.getPrizeLevel() == 3 && prize.getIsSelected() == 0) {
+								count = 3;
+							} else if (prize.getPrizeLevel() == 4 && prize.getIsSelected() == 0) {
+								count = 4;
+							}
+							prize.setIsSelected(1);
+							prizeMapper.updateByPrimaryKeySelective(prize);
+							prizeRecord.setPrizeId(prize.getPrizeLevel());
+							prizeRecord.setPrize(prize.getName());
+							prizeRecordMapper.insert(prizeRecord);
+						}
 					}
-					// prize.setIsSelected(1);
-					// prizeMapper.updateByPrimaryKeySelective(prize);
-					prizeRecord.setPrizeId(prize.getPrizeLevel());
-					prizeRecord.setPrize(prize.getName());
-					prizeRecordMapper.insert(prizeRecord);
 				}
+				// 添加抽奖记录
+				UserPrizeCount userPrizeCount = new UserPrizeCount();
+				userPrizeCount.setUserId(userId);
+				UserPrizeCountMapper.insert(userPrizeCount);
+				map.put("prizeLevel", count);
+				map.put("prizeRecord", prizeRecord);
+				msg.data = map;
+			} else {
+				msg.setError("抽奖次数已达上限,去分享即可获得抽奖机会");
 			}
+		} else {
+			msg.setError("抽奖次数已达上限");
 		}
-		// // 添加抽奖记录
-		// UserPrizeCount userPrizeCount = new UserPrizeCount();
-		// userPrizeCount.setUserId(userId);
-		// UserPrizeCountMapper.insert(userPrizeCount);
-		// map.put("prizeLevel", count);
-		// map.put("prizeRecord", prizeRecord);
-		// msg.data = map;
-		// }else{
-		// msg.setError("抽奖次数已达上限,去分享即可获得抽奖机会");
-		// }
-		//
-		// } else {
-		// msg.setError("抽奖次数已达上限");
-		// }
 		response.setContentType("application/json");
 		response.setCharacterEncoding("UTF-8");
 		response.getWriter().println(msg.toJSONStr());
 
 	}
+
 	/**
 	 * 小游戏抽奖列表
 	 *