浏览代码

获取用户

5 年之前
父节点
当前提交
4cb4e4c5d6

+ 60 - 35
minigame/src/com/hssx/controller/PrizeController.java

@@ -86,7 +86,36 @@ public class PrizeController {
 		}
 		// if (luckDrawCount <= 1) {
 		// 直接抽奖(每日默认2次抽奖机会)
-		count = getLuckDraw(prizeRecord, count);
+		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;
+					}
+					// 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);
@@ -98,8 +127,36 @@ public class PrizeController {
 		// int opportunityCount =
 		// prizeOpportunityMapper.selectCountByToday(userId);
 		// if (opportunityCount > 0) {
-		// // 直接抽奖
-		// count = getLuckDraw(prizeRecord, count);
+		// // 已分享直接抽奖
+		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;
+					}
+					// prize.setIsSelected(1);
+					// prizeMapper.updateByPrimaryKeySelective(prize);
+					prizeRecord.setPrizeId(prize.getPrizeLevel());
+					prizeRecord.setPrize(prize.getName());
+					prizeRecordMapper.insert(prizeRecord);
+				}
+			}
+		}
 		// // 添加抽奖记录
 		// UserPrizeCount userPrizeCount = new UserPrizeCount();
 		// userPrizeCount.setUserId(userId);
@@ -119,38 +176,6 @@ public class PrizeController {
 		response.getWriter().println(msg.toJSONStr());
 
 	}
-
-	public synchronized Integer getLuckDraw(PrizeRecord prizeRecord, Integer count) {
-		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;
-				}
-				// prize.setIsSelected(1);
-				// prizeMapper.updateByPrimaryKeySelective(prize);
-				prizeRecord.setPrizeId(prize.getPrizeLevel());
-				prizeRecord.setPrize(prize.getName());
-				prizeRecordMapper.insert(prizeRecord);
-			}
-		}
-		return count;
-	}
-
 	/**
 	 * 小游戏抽奖列表
 	 *

+ 17 - 0
minigame/src/com/hssx/controller/UserController.java

@@ -152,4 +152,21 @@ public class UserController {
 		response.setCharacterEncoding("UTF-8");
 		response.getWriter().println(msg.toJSONStr());
 	}
+	
+	/**
+	 * 根据userId获取用户信息 id
+	 * @param iduser
+	 * @param response
+	 * @throws IOException 
+	 */
+	@RequestMapping(value = "getUser")
+	public void getUser(User user,HttpServletResponse response) throws IOException{
+		HttpRespMsg msg = new HttpRespMsg();
+		user = usermapper.selectByPrimaryKey(user.getId());
+		msg.data = user;
+		response.setContentType("application/json");
+		response.setCharacterEncoding("UTF-8");
+		response.getWriter().println(msg.toJSONStr());
+	}
+	
 }