浏览代码

最新后台代码

5 年之前
父节点
当前提交
cfe504404b

+ 3 - 5
minigame/src/com/hssx/controller/NewsController.java

@@ -50,8 +50,8 @@ public class NewsController {
     /**
      * 添加分享信息
      *
-     * 传递的参数:
-     * 		userId:用户id message:寄语
+     * 传递的参数:userId:用户id message:寄语
+     *
      * @return
      * @throws IOException 
      */
@@ -78,9 +78,7 @@ public class NewsController {
     
     /**
      * 添加分享信息
-     *
-     * 传递的参数:
-     * 		id:海报消息id 
+     * 传递的参数:id:海报消息id
      * @return
      * @throws IOException 
      */

+ 103 - 63
minigame/src/com/hssx/controller/PrizeController.java

@@ -88,82 +88,83 @@ public class PrizeController {
 //		}
 		if (luckDrawCount <= 1) {
 			// 直接抽奖(每日默认2次抽奖机会)
-			synchronized (this) {
-				Random ran = new Random();
-				int num = ran.nextInt(60);
-				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);
+//			synchronized (this) {
+//				Random ran = new Random();
+//				int num = ran.nextInt(60);
+//				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);
+//					}
+//				}
+//			}
+			map = luckDrawWay(count,prizeRecord,map);
 			// 添加抽奖记录
 			UserPrizeCount userPrizeCount = new UserPrizeCount();
 			userPrizeCount.setUserId(userId);
 			UserPrizeCountMapper.insert(userPrizeCount);
-			map.put("prizeLevel", count);
-			map.put("prizeRecord", prizeRecord);
+//			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(60);// 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);
-						}
-					}
-				}
+				map = luckDrawWay(count,prizeRecord,map);
+//				synchronized (this) {
+//					Random ran = new Random();
+//					int num = ran.nextInt(60);// 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);
+//						}
+//					}
+//				}
 				// 添加抽奖记录
 				UserPrizeCount userPrizeCount = new UserPrizeCount();
 				userPrizeCount.setUserId(userId);
 				UserPrizeCountMapper.insert(userPrizeCount);
-				map.put("prizeLevel", count);
-				map.put("prizeRecord", prizeRecord);
+//				map.put("prizeLevel", count);
+//				map.put("prizeRecord", prizeRecord);
 				msg.data = map;
 			} else {
 				msg.setError("抽奖次数已达上限,去分享即可获得抽奖机会");
@@ -176,6 +177,45 @@ public class PrizeController {
 		response.getWriter().println(msg.toJSONStr());
 
 	}
+	
+	//抽奖方法
+	public synchronized HashMap<String, Object> luckDrawWay (Integer count,PrizeRecord prizeRecord,HashMap<String, Object> map){
+		Random ran = new Random();
+		int num = ran.nextInt(60);// 50%中奖概率
+		Prize prize = prizeMapper.selectByPrimaryKey(num);
+		//以下是真实环境的抽奖原则
+//		PrizeExample exp = new PrizeExample();
+//		exp.setOrderByClause("RAND() LIMIT 1");
+//		Prize prize = prizeMapper.selectByExample(exp).get(0);
+		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);
+			}
+		}
+		map.put("prizeLevel", count);
+		map.put("prizeRecord", prizeRecord);
+		return map;
+	}
+	
 
 	/**
 	 * 小游戏抽奖列表

+ 1 - 1
minigame/src/com/hssx/controller/UserController.java

@@ -166,7 +166,7 @@ public class UserController {
 	
 	/**
 	 * 根据userId获取用户信息 id
-	 * @param iduser
+	 * 参数 :id:用户id
 	 * @param response
 	 * @throws IOException 
 	 */