2 커밋 2996c11561 ... 537436a45a

작성자 SHA1 메시지 날짜
  kk 537436a45a Merge remote-tracking branch 'origin/master' 4 주 전
  kk 2b7259321d 修改开奖 4 주 전

+ 6 - 2
game-business/src/main/java/com/game/business/controller/AppGameBettingController.java

@@ -152,9 +152,13 @@ public class AppGameBettingController extends BaseController{
 //            return HttpRet.fail("游戏已封盘,无法下单。");
 //        }
 
-        long count = appGameLotteryService.selectCount(appGame.getClassifyId(), appGame.getId(), appGame.getGameDate());
+        AppGameLottery appGameLottery = appGameLotteryService.selectLottery(appGame.getClassifyId(), appGame.getId(), appGame.getGameDate());
 
-        if(count > 0){
+        if(appGameLottery == null){
+            return HttpRet.fail("游戏未开盘,无法下单。");
+        }
+
+        if(appGameLottery.getIsLottery() == 1){
             return HttpRet.fail("游戏已开奖,无法下单。");
         }
 

+ 15 - 4
game-business/src/main/java/com/game/business/controller/AppGameLotteryController.java

@@ -8,6 +8,7 @@ import com.game.business.dto.AppUserDTO;
 import com.game.business.service.IAppGameItemService;
 import com.game.business.service.IAppGameLotteryService;
 import com.game.business.service.IAppGameService;
+import com.game.business.task.AppGameBettingTask;
 import com.game.business.task.AppGameLotteryTask;
 import com.game.business.vo.AppGameLotteryVO;
 import com.game.business.vo.AppUserAgentVO;
@@ -148,17 +149,27 @@ public class AppGameLotteryController extends BaseController{
             return HttpRet.fail("权限不足,请联系管理员");
         }
 
-        long count = appGameLotteryService.selectCount(appGameLottery.getClassId(), appGameLottery.getGameId(), appGameLottery.getGameDate());
-        if(count > 0){
+        AppGameLottery dbAppGameLottery = appGameLotteryService.selectLottery(appGameLottery.getClassId(), appGameLottery.getGameId(), appGameLottery.getGameDate());
+        if(dbAppGameLottery != null && dbAppGameLottery.getIsLottery() == 1){
             return HttpRet.fail("该游戏,当前期已自动开奖过了,不能手动开奖");
         }
 
         appGameLottery.setIsLottery(1);
         appGameLottery.setGameRecordDate(new Date());
-        if(appGameLotteryService.save(appGameLottery)){
+        boolean flg = false;
+        if(dbAppGameLottery == null){
+            flg = appGameLotteryService.save(appGameLottery);
+        }else{
+            AppGameLottery updateAppGameLottery = new AppGameLottery();
+            updateAppGameLottery.setId(dbAppGameLottery.getId());
+            updateAppGameLottery.setIsLottery(1);
+            updateAppGameLottery.setGameRecordDate(new Date());
+            updateAppGameLottery.setGameLotterySucc(appGameLottery.getGameLotterySucc());
+            flg =appGameLotteryService.updateById(updateAppGameLottery);
+        }
+        if(flg){
             appGameLotteryTask.updateLottery(appGameLottery);
         }
-
         return HttpRet.success("手动开奖成功",true);
     }
 

+ 1 - 0
game-business/src/main/java/com/game/business/service/impl/AppGameLotteryServiceImpl.java

@@ -23,6 +23,7 @@ public class AppGameLotteryServiceImpl extends ServiceImpl<AppGameLotteryMapper,
         queryLotteryWrapper.eq(AppGameLottery::getClassId, classId);
         queryLotteryWrapper.eq(AppGameLottery::getGameId, gameId);
         queryLotteryWrapper.eq(AppGameLottery::getGameDate, gameDate);
+        queryLotteryWrapper.eq(AppGameLottery::getIsLottery, 1);
         return appGameLotteryMapper.selectCount(queryLotteryWrapper);
     }
 

+ 80 - 50
game-business/src/main/java/com/game/business/task/AppGameBettingTask.java

@@ -223,51 +223,72 @@ public class AppGameBettingTask {
             }
 
             if(type == 3){
-                appGame.setGameDate(gameDate);
-                appGameService.updateAppGame(appGame);
 
-                // 修改倍数
-                if(gameCode.equals(Common.GAME_ONE_CODE)){
+                String redisKey = CacheConstants.GAME_LOTTERY_TASK_CREATE.concat(appGame.getId() + ":" + gameCode);
+                if(!redisCache.redisTemplate.opsForValue().setIfAbsent(redisKey, 1)){
+                    continue;
+                }
 
-                    String gameLotteryBet = gameLotteryObject.getString("gameLotteryBet");
-                    if(StringUtils.isBlank(gameLotteryBet)){
-                        continue;
-                    }
+                try {
 
-                    gameLotteryBet = gameLotteryBet.replace(" ", "").trim();
-                    JSONArray items = JSONArray.parseArray(gameLotteryBet);
-                    if(items == null || items.isEmpty()){
-                       continue;
-                    }
+                    appGame.setGameDate(gameDate);
+                    appGameService.updateAppGame(appGame);
 
-                    AppGameItem appGameItem = new AppGameItem();
-                    appGameItem.setGameId(appGame.getId());
-                    List<AppGameItem> itemList = appGameItemService.selectAppGameItemList(appGameItem);
+                    // 修改倍数
+                    if(gameCode.equals(Common.GAME_ONE_CODE)){
 
-                    if(itemList == null || itemList.isEmpty()){
-                        continue;
-                    }
+                        String gameLotteryBet = gameLotteryObject.getString("gameLotteryBet");
+                        if(StringUtils.isBlank(gameLotteryBet)){
+                            continue;
+                        }
 
-                    if(itemList.size() != items.size()){
-                        continue;
-                    }
+                        gameLotteryBet = gameLotteryBet.replace(" ", "").trim();
+                        JSONArray items = JSONArray.parseArray(gameLotteryBet);
+                        if(items == null || items.isEmpty()){
+                            continue;
+                        }
 
-                    AppGameItemMultiple appGameItemMultiple = new AppGameItemMultiple();
-                    appGameItemMultiple.setGameId(appGame.getId());
-                    appGameItemMultiple.setGameDate(gameDate);
-                    appGameItemMultiple.setItemMultiple(gameLotteryBet.substring(1, gameLotteryBet.length() - 1));
-                    appGameItemMultipleService.save(appGameItemMultiple);
+                        AppGameItem appGameItem = new AppGameItem();
+                        appGameItem.setGameId(appGame.getId());
+                        List<AppGameItem> itemList = appGameItemService.selectAppGameItemList(appGameItem);
 
-                    // 升序排序
-                    itemList.stream().sorted(Comparator.comparing(AppGameItem::getItemLocation));
+                        if(itemList == null || itemList.isEmpty()){
+                            continue;
+                        }
 
-                    for (int j = 0; j < itemList.size(); j++) {
-                        AppGameItem gameItem = itemList.get(j);
-                        gameItem.setItemMultiple(items.getDouble(j));
-                        appGameItemService.updateAppGameItem(gameItem);
+                        if(itemList.size() != items.size()){
+                            continue;
+                        }
+
+                        AppGameItemMultiple appGameItemMultiple = new AppGameItemMultiple();
+                        appGameItemMultiple.setGameId(appGame.getId());
+                        appGameItemMultiple.setGameDate(gameDate);
+                        appGameItemMultiple.setItemMultiple(gameLotteryBet.substring(1, gameLotteryBet.length() - 1));
+                        appGameItemMultipleService.save(appGameItemMultiple);
+
+                        // 升序排序
+                        itemList.stream().sorted(Comparator.comparing(AppGameItem::getItemLocation));
+
+                        for (int j = 0; j < itemList.size(); j++) {
+                            AppGameItem gameItem = itemList.get(j);
+                            gameItem.setItemMultiple(items.getDouble(j));
+                            appGameItemService.updateAppGameItem(gameItem);
+                        }
                     }
-                }
 
+                    AppGameLottery appGameLottery = new AppGameLottery();
+                    appGameLottery.setGameId(appGame.getId());
+                    appGameLottery.setClassId(appGame.getClassifyId());
+                    appGameLottery.setGameDate(gameDate);
+                    appGameLottery.setIsLottery(0);
+                    appGameLottery.setGameRecordDate(new Date());
+                    appGameLotteryService.save(appGameLottery);
+
+                }catch (Exception e){
+                    e.printStackTrace();
+                }finally {
+                    redisCache.redisTemplate.delete(redisKey);
+                }
                 continue;
             }
 
@@ -290,24 +311,33 @@ public class AppGameBettingTask {
 
             try {
 
-                long count = appGameLotteryService.selectCount(appGame.getClassifyId(), appGame.getId(), gameDate);
+                AppGameLottery appGameLottery = appGameLotteryService.selectLottery(appGame.getClassifyId(), appGame.getId(), gameDate);
+
+                if(appGameLottery == null){
+                    // 保存开奖记录
+                    appGameLottery = new AppGameLottery();
+                    appGameLottery.setGameId(appGame.getId());
+                    appGameLottery.setClassId(appGame.getClassifyId());
+                    appGameLottery.setGameDate(gameDate);
+                    appGameLottery.setIsLottery(isLottery);
+                    appGameLottery.setGameRecordDate(new Date());
+                    appGameLottery.setGameLotterySucc(gameLotterySucc);
+                    appGameLotteryService.save(appGameLottery);
+                }else{
+                    if(appGameLottery.getIsLottery() == 1){
+//                      redisCache.redisTemplate.delete(redisKey);
+//                      System.out.println("游戏socket推送开奖,当前期已开过将,游戏编码:" + gameCode + ",期号:" + gameDate);
+                        continue;
+                    }
 
-                if(count > 0){
-                    redisCache.redisTemplate.delete(redisKey);
-//                System.out.println("游戏socket推送开奖,当前期已开过将,游戏编码:" + gameCode + ",期号:" + gameDate);
-                    continue;
+                    AppGameLottery updateAppGameLottery = new AppGameLottery();
+                    updateAppGameLottery.setId(appGameLottery.getId());
+                    updateAppGameLottery.setIsLottery(isLottery);
+                    updateAppGameLottery.setGameRecordDate(new Date());
+                    updateAppGameLottery.setGameLotterySucc(gameLotterySucc);
+                    appGameLotteryService.updateById(updateAppGameLottery);
                 }
 
-                // 保存开奖记录
-                AppGameLottery appGameLottery = new AppGameLottery();
-                appGameLottery.setGameId(appGame.getId());
-                appGameLottery.setClassId(appGame.getClassifyId());
-                appGameLottery.setGameDate(gameDate);
-                appGameLottery.setIsLottery(isLottery);
-                appGameLottery.setGameRecordDate(new Date());
-                appGameLottery.setGameLotterySucc(gameLotterySucc);
-                appGameLotteryService.save(appGameLottery);
-
                 lotteryTask(appGame, appGameClassify, gameLotterySucc, gameDate);
 
             }catch (Exception e){
@@ -324,7 +354,7 @@ public class AppGameBettingTask {
 
         List<String> userIds = this.gameBettingTask(appGameClassify.getId(), appGame.getId(), gameDate, gameLotterySucc);
 
-        appUserCountService.staticsUserCount(appGame.getId(),null,appGame.getGameDate());
+        appUserCountService.staticsUserCount(appGame.getId(),null, appGame.getGameDate());
 
         // 给中奖人发送刷新余额通知
         sendMsg(userIds);

+ 8 - 0
game-business/src/main/java/com/game/business/task/AppGameLotteryTask.java

@@ -42,6 +42,9 @@ public class AppGameLotteryTask {
     @Autowired
     private RedisCache redisCache;
 
+    @Autowired
+    private AppUserCountTask appUserCountTask;
+
     public void updateLottery(AppGameLottery appGameLottery) throws Exception {
 
         updateItme(appGameLottery.getGameId(), appGameLottery.getGameLotterySucc());
@@ -52,6 +55,11 @@ public class AppGameLotteryTask {
 
         // 给中奖人发送刷新余额通知
         sendMsg(userIds);
+
+        //更新可提现余额
+        for(String userId : userIds) {
+            appUserCountTask.updateWithdrawAble(Long.parseLong(userId));
+        }
     }
 
     private void updateItme(Long gameId, String gameLotterySucc){

+ 0 - 1
game-business/src/main/java/com/game/business/websocket/client/GameFiveClient.java

@@ -1,7 +1,6 @@
 package com.game.business.websocket.client;
 
 import com.game.business.config.GameFiveConfig;
-import com.game.business.config.GameFourConfig;
 import com.game.business.task.AppGameBettingTask;
 import com.game.business.util.Common;
 import org.apache.commons.lang3.StringUtils;

+ 0 - 1
game-business/src/main/java/com/game/business/websocket/client/GameFourClient.java

@@ -1,7 +1,6 @@
 package com.game.business.websocket.client;
 
 import com.game.business.config.GameFourConfig;
-import com.game.business.config.GameThreesConfig;
 import com.game.business.task.AppGameBettingTask;
 import com.game.business.util.Common;
 import org.apache.commons.lang3.StringUtils;

+ 0 - 11
game-business/src/main/java/com/game/business/websocket/client/GameOneClient.java

@@ -1,17 +1,6 @@
 package com.game.business.websocket.client;
 
-import com.alibaba.fastjson2.JSONArray;
-import com.alibaba.fastjson2.JSONObject;
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.game.business.config.GameOneConfig;
-import com.game.business.domain.AppGame;
-import com.game.business.domain.AppGameClassify;
-import com.game.business.domain.AppGameLottery;
-import com.game.business.service.IAppGameClassifyService;
-import com.game.business.service.IAppGameLotteryService;
-import com.game.business.service.IAppGameService;
 import com.game.business.task.AppGameBettingTask;
 import com.game.business.util.Common;
 import org.apache.commons.lang3.StringUtils;

+ 0 - 1
game-business/src/main/java/com/game/business/websocket/client/GameThreesClient.java

@@ -1,7 +1,6 @@
 package com.game.business.websocket.client;
 
 import com.game.business.config.GameThreesConfig;
-import com.game.business.config.GameTwoConfig;
 import com.game.business.task.AppGameBettingTask;
 import com.game.business.util.Common;
 import org.apache.commons.lang3.StringUtils;

+ 0 - 1
game-business/src/main/java/com/game/business/websocket/client/GameTwoClient.java

@@ -1,6 +1,5 @@
 package com.game.business.websocket.client;
 
-import com.game.business.config.GameOneConfig;
 import com.game.business.config.GameTwoConfig;
 import com.game.business.task.AppGameBettingTask;
 import com.game.business.util.Common;

+ 5 - 0
game-common/src/main/java/com/game/common/constant/CacheConstants.java

@@ -62,4 +62,9 @@ public class CacheConstants
      */
     public static final String GAME_LOTTERY_TASK = "game_lottery_task:";
 
+    /**
+     * 创建开奖任务锁
+     */
+    public static final String GAME_LOTTERY_TASK_CREATE = "game_lottery_task_create:";
+
 }