|
@@ -57,7 +57,6 @@ public class PrizeController {
|
|
|
public void luckDraw(@RequestParam(required = false) String userId, HttpServletResponse response)
|
|
|
throws Exception, KeyManagementException, NoSuchAlgorithmException, NoSuchProviderException, IOException {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
-// userId = new Random().nextInt(6) + 1;// 测试用
|
|
|
Integer count = -1;
|
|
|
PrizeRecord prizeRecord = new PrizeRecord();
|
|
|
User user = usermapper.selectByPrimaryKey(userId);
|
|
@@ -68,103 +67,23 @@ public class PrizeController {
|
|
|
UserPrizeCountExample uExp = new UserPrizeCountExample();
|
|
|
Integer luckDrawCount = UserPrizeCountMapper.selectCountByTodayByUid(userId);
|
|
|
HashMap<String, Object> map = new HashMap<String, Object>();
|
|
|
- // 模拟无限次数抽奖
|
|
|
- // 测试必定中奖账号
|
|
|
-// if ("o1L3L5jybPQ0zJWujikHpVJPBiM8".equals(user.getVoucherId())) {
|
|
|
-// System.out.println("中奖了!!!!!!!!!!!!!!");
|
|
|
-// prizeRecordMapper.insert(prizeRecord);
|
|
|
-// 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(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);
|
|
|
+ map = luckDrawWay(userId, count,prizeRecord,map);
|
|
|
// 添加抽奖记录
|
|
|
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) {
|
|
|
// 已分享直接抽奖
|
|
|
- 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);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
+ map = luckDrawWay(userId, count,prizeRecord,map);
|
|
|
// 添加抽奖记录
|
|
|
UserPrizeCount userPrizeCount = new UserPrizeCount();
|
|
|
userPrizeCount.setUserId(userId);
|
|
|
UserPrizeCountMapper.insert(userPrizeCount);
|
|
|
-// map.put("prizeLevel", count);
|
|
|
-// map.put("prizeRecord", prizeRecord);
|
|
|
msg.data = map;
|
|
|
} else {
|
|
|
msg.setError("抽奖次数已达上限,去分享即可获得抽奖机会");
|
|
@@ -179,36 +98,40 @@ public class PrizeController {
|
|
|
}
|
|
|
|
|
|
//抽奖方法
|
|
|
- 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) {
|
|
|
+ public synchronized HashMap<String, Object> luckDrawWay (String userId, Integer count,PrizeRecord prizeRecord,HashMap<String, Object> map){
|
|
|
+ //已经中过奖的用户,不再中奖!!!
|
|
|
+ PrizeRecordExample prExp = new PrizeRecordExample();
|
|
|
+ prExp.createCriteria().andUidEqualTo(userId);
|
|
|
+ if (prizeRecordMapper.countByExample(prExp) > 0) {
|
|
|
count = -1;
|
|
|
} else {
|
|
|
- if (prize.getPrizeLevel() == 5 || prize.getIsSelected() == 1) {
|
|
|
+ //以下是真实环境的抽奖原则
|
|
|
+ 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() == 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);
|
|
|
}
|
|
|
}
|
|
|
map.put("prizeLevel", count);
|