소스 검색

下注添加锁

kk 1 개월 전
부모
커밋
1e7a91c219

+ 231 - 214
game-business/src/main/java/com/game/business/controller/AppGameBettingController.java

@@ -10,6 +10,7 @@ import com.game.business.vo.*;
 import com.game.business.service.*;
 import com.game.common.annotation.Anonymous;
 import com.game.common.annotation.Log;
+import com.game.common.constant.CacheConstants;
 import com.game.common.constant.finance.FinTranType1;
 import com.game.common.constant.finance.FinTranType2;
 import com.game.common.constant.finance.FinTranType3;
@@ -79,301 +80,317 @@ public class AppGameBettingController extends BaseController{
     @DSTransactional
     public HttpRet<Double> betting(@RequestBody AppGameBetting gameBetting) throws Exception {
 
-        if(gameBetting.getClassId() == null){
-            return HttpRet.fail("游戏平台ID为空。");
+        String redisKey = CacheConstants.GAME_USER_BETTING_CREATE.concat(gameBetting.getUserId() + ":" + gameBetting.getGameId() + ":" + gameBetting.getGameDate());
+        if(!redisCache.redisTemplate.opsForValue().setIfAbsent(redisKey, 1)){
+            return HttpRet.fail("下注速度过快,请等待1秒后再试。");
         }
 
-        if(gameBetting.getGameId() == null){
-            return HttpRet.fail("游戏ID为空。");
-        }
+        Double diamondCoin = 0.00;
 
-        if(gameBetting.getUserId()== null){
-            return HttpRet.fail("用户ID为空。");
-        }
+        try {
 
-        if(gameBetting.getBettingGameType() == null){
-            gameBetting.setBettingGameType(0);
-        }
+            if(gameBetting.getClassId() == null){
+                return HttpRet.fail("游戏平台ID为空。");
+            }
 
-        if(gameBetting.getMoneyId() == null){
-            return HttpRet.fail("金额ID为空。");
-        }
+            if(gameBetting.getGameId() == null){
+                return HttpRet.fail("游戏ID为空。");
+            }
 
-        if(gameBetting.getBettingGameType() == 0){
-            AppGameMoney appGameMoney = appGameMoneyService.selectAppGameMoneyById(gameBetting.getMoneyId());
+            if(gameBetting.getUserId()== null){
+                return HttpRet.fail("用户ID为空。");
+            }
 
-            if(appGameMoney == null){
-                return HttpRet.fail("金额对象不存在。");
+            if(gameBetting.getBettingGameType() == null){
+                gameBetting.setBettingGameType(0);
             }
 
-            if(appGameMoney.getBettingMoney().doubleValue() != gameBetting.getBettingAmount().doubleValue()){
-                return HttpRet.fail("投注金额不匹配,无法下单。");
+            if(gameBetting.getMoneyId() == null){
+                return HttpRet.fail("金额ID为空。");
             }
-        }
 
-        AppGameClassify appGameClassify = appGameClassifyService.selectAppGameClassifyById(gameBetting.getClassId());
-        if(appGameClassify == null){
-            return HttpRet.fail("游戏平台不存在。");
-        }
+            if(gameBetting.getBettingGameType() == 0){
+                AppGameMoney appGameMoney = appGameMoneyService.selectAppGameMoneyById(gameBetting.getMoneyId());
 
-        AppGame appGame = appGameService.selectAppGameById(gameBetting.getGameId());
-        if(appGame == null){
-            return HttpRet.fail("游戏不存在。");
-        }
+                if(appGameMoney == null){
+                    return HttpRet.fail("金额对象不存在。");
+                }
 
-        if(appGame.getStatus() == 0){
-            return HttpRet.fail("游戏已下线,无法下单。");
-        }
+                if(appGameMoney.getBettingMoney().doubleValue() != gameBetting.getBettingAmount().doubleValue()){
+                    return HttpRet.fail("投注金额不匹配,无法下单。");
+                }
+            }
 
-        if(appGame.getEnable() == 1){
-            return HttpRet.fail("游戏已禁用,无法下单。");
-        }
+            AppGameClassify appGameClassify = appGameClassifyService.selectAppGameClassifyById(gameBetting.getClassId());
+            if(appGameClassify == null){
+                return HttpRet.fail("游戏平台不存在。");
+            }
 
-        if(StringUtils.isBlank(appGame.getGameDate())){
-            return HttpRet.fail("游戏期号不存在,无法下单。");
-        }
+            AppGame appGame = appGameService.selectAppGameById(gameBetting.getGameId());
+            if(appGame == null){
+                return HttpRet.fail("游戏不存在。");
+            }
 
-        if(!appGame.getGameDate().equals(gameBetting.getGameDate())){
-            return HttpRet.fail("游戏期号不匹配,无法下单。");
-        }
+            if(appGame.getStatus() == 0){
+                return HttpRet.fail("游戏已下线,无法下单。");
+            }
 
-        if(StringUtils.isBlank(appGame.getGameTime())){
-            return HttpRet.fail("游戏已封盘,无法下单。");
-        }
+            if(appGame.getEnable() == 1){
+                return HttpRet.fail("游戏已禁用,无法下单。");
+            }
 
-        if(!appGame.getGameTime().contains(":")){
-            return HttpRet.fail("游戏已封盘,无法下单。");
-        }
+            if(StringUtils.isBlank(appGame.getGameDate())){
+                return HttpRet.fail("游戏期号不存在,无法下单。");
+            }
 
-        String[] timeArry = appGame.getGameTime().substring(0, 5).split(":");
-        int m = Integer.parseInt(timeArry[1]);
-        if(m <= 2){
-            return HttpRet.fail("游戏已封盘,无法下单。");
-        }
+            if(!appGame.getGameDate().equals(gameBetting.getGameDate())){
+                return HttpRet.fail("游戏期号不匹配,无法下单。");
+            }
 
-        if(appGame.getBettingCount() == null || appGame.getBettingCount() == 0){
-            return HttpRet.fail("投注次数已超过限额,无法下单。");
-        }
+            if(StringUtils.isBlank(appGame.getGameTime())){
+                return HttpRet.fail("游戏已封盘,无法下单。");
+            }
 
-        // 每期可投注多少个选项:比如设置为3 则只能投3个不同的选项,不能超过3个
-        Integer bettingCount = appGameBettingService.getBettingCount(gameBetting.getUserId(), gameBetting.getGameId(), appGame.getGameDate(), gameBetting.getBettingItem());
-        if(bettingCount != null && bettingCount > 0 ){
-            if(appGame.getBettingCount().intValue() >= 0 && bettingCount.intValue() >= appGame.getBettingCount().intValue()){
-                return HttpRet.fail("当前期投注选项已超过限额,无法下单。");
+            if(!appGame.getGameTime().contains(":")){
+                return HttpRet.fail("游戏已封盘,无法下单。");
+            }
+
+            String[] timeArry = appGame.getGameTime().substring(0, 5).split(":");
+            int m = Integer.parseInt(timeArry[1]);
+            if(m <= 2){
+                return HttpRet.fail("游戏已封盘,无法下单。");
             }
-        }
 
-        // 游戏特殊固定下注判断
-        if(appGame.getCode().equals(Common.GAME_FOUR_CODE) ||
-            appGame.getCode().equals(Common.GAME_SIX_CODE) ||
-            appGame.getCode().equals(Common.GAME_SEVEN_CODE)){
+            if(appGame.getBettingCount() == null || appGame.getBettingCount() == 0){
+                return HttpRet.fail("投注次数已超过限额,无法下单。");
+            }
 
-            List<String> itemList = Arrays.asList(Common.GAME_BETTING_ITEM_LIMIT);
+            // 每期可投注多少个选项:比如设置为3 则只能投3个不同的选项,不能超过3个
+            Integer bettingCount = appGameBettingService.getBettingCount(gameBetting.getUserId(), gameBetting.getGameId(), appGame.getGameDate(), gameBetting.getBettingItem());
+            if(bettingCount != null && bettingCount > 0 ){
+                if(appGame.getBettingCount().intValue() >= 0 && bettingCount.intValue() >= appGame.getBettingCount().intValue()){
+                    return HttpRet.fail("当前期投注选项已超过限额,无法下单。");
+                }
+            }
 
-            // 当前投注的是否属于特殊固定选项
-            if(itemList.contains(gameBetting.getBettingItem())) {
+            // 游戏特殊固定下注判断
+            if(appGame.getCode().equals(Common.GAME_FOUR_CODE) ||
+                appGame.getCode().equals(Common.GAME_SIX_CODE) ||
+                appGame.getCode().equals(Common.GAME_SEVEN_CODE)){
 
-                List<String> bettingItemList = appGameBettingService.getBettingItem(gameBetting.getUserId(), gameBetting.getGameId(), appGame.getGameDate());
-                if (bettingItemList != null && !bettingItemList.isEmpty()) {
+                List<String> itemList = Arrays.asList(Common.GAME_BETTING_ITEM_LIMIT);
 
-                    List<String> checkItemList = new ArrayList<>();
+                // 当前投注的是否属于特殊固定选项
+                if(itemList.contains(gameBetting.getBettingItem())) {
 
-                    for (int i = 0; i < itemList.size(); i++) {
-                        String itemStr = itemList.get(i);
-                        if (bettingItemList.contains(itemStr)) {
-                            checkItemList.add(itemStr);
-                        }
-                    }
+                    List<String> bettingItemList = appGameBettingService.getBettingItem(gameBetting.getUserId(), gameBetting.getGameId(), appGame.getGameDate());
+                    if (bettingItemList != null && !bettingItemList.isEmpty()) {
 
-                    if(checkItemList.size() == 4){
-                        return HttpRet.fail("当前期投注选项已超过限额,无法下单!");
-                    }
+                        List<String> checkItemList = new ArrayList<>();
 
-                    // 当前投注是否已经满足3个投注选项了
-                    if (checkItemList.size() == 3) {
-                        // 当前投注的是否属于特殊选项重复投注
-                        if (!checkItemList.contains(gameBetting.getBettingItem())) {
+                        for (int i = 0; i < itemList.size(); i++) {
+                            String itemStr = itemList.get(i);
+                            if (bettingItemList.contains(itemStr)) {
+                                checkItemList.add(itemStr);
+                            }
+                        }
+
+                        if(checkItemList.size() == 4){
                             return HttpRet.fail("当前期投注选项已超过限额,无法下单!");
                         }
+
+                        // 当前投注是否已经满足3个投注选项了
+                        if (checkItemList.size() == 3) {
+                            // 当前投注的是否属于特殊选项重复投注
+                            if (!checkItemList.contains(gameBetting.getBettingItem())) {
+                                return HttpRet.fail("当前期投注选项已超过限额,无法下单!");
+                            }
+                        }
                     }
                 }
             }
-        }
 
-        BigDecimal gameBettingAmountCheck = new BigDecimal(appGame.getBettingMaxMoney() + "");
-        BigDecimal gameBettingAmountSum = appGameBettingService.getBettingAmount(gameBetting.getUserId(), gameBetting.getGameId(), appGame.getGameDate(), null);
-        BigDecimal gameBettingAmountAdd = gameBettingAmountSum.add(new BigDecimal(gameBetting.getBettingAmount() + ""));
-        if(appGame.getBettingMaxMoney() >= 0 && gameBettingAmountAdd.compareTo(gameBettingAmountCheck) == 1){
-            return HttpRet.fail("当前期投注金额已超过限额,无法下单。");
-        }
+            BigDecimal gameBettingAmountCheck = new BigDecimal(appGame.getBettingMaxMoney() + "");
+            BigDecimal gameBettingAmountSum = appGameBettingService.getBettingAmount(gameBetting.getUserId(), gameBetting.getGameId(), appGame.getGameDate(), null);
+            BigDecimal gameBettingAmountAdd = gameBettingAmountSum.add(new BigDecimal(gameBetting.getBettingAmount() + ""));
+            if(appGame.getBettingMaxMoney() >= 0 && gameBettingAmountAdd.compareTo(gameBettingAmountCheck) == 1){
+                return HttpRet.fail("当前期投注金额已超过限额,无法下单。");
+            }
 
-        // 单选
-        if(gameBetting.getBettingGameType() == 0){
+            // 单选
+            if(gameBetting.getBettingGameType() == 0){
 
-            AppGameItem appGameItem = appGameItemService.selectAppGameItemByGameIdAndItemLocation(appGame.getId(), gameBetting.getBettingItem());
-            if(appGameItem == null){
-                return HttpRet.fail("游戏选项不存在,无法下单。");
-            }
+                AppGameItem appGameItem = appGameItemService.selectAppGameItemByGameIdAndItemLocation(appGame.getId(), gameBetting.getBettingItem());
+                if(appGameItem == null){
+                    return HttpRet.fail("游戏选项不存在,无法下单。");
+                }
 
-            if(appGame.getCode().equals(Common.GAME_ONE_CODE)){
-                if(gameBetting.getBettingMultiple() != null && gameBetting.getBettingMultiple() > 0){
-                    if(gameBetting.getBettingMultiple().doubleValue() != appGameItem.getItemMultiple().doubleValue()){
-                        return HttpRet.fail("游戏选项倍数不统一,无法下单。");
+                if(appGame.getCode().equals(Common.GAME_ONE_CODE)){
+                    if(gameBetting.getBettingMultiple() != null && gameBetting.getBettingMultiple() > 0){
+                        if(gameBetting.getBettingMultiple().doubleValue() != appGameItem.getItemMultiple().doubleValue()){
+                            return HttpRet.fail("游戏选项倍数不统一,无法下单。");
+                        }
                     }
                 }
-            }
 
-            Integer bettingItemCount = appGameBettingService.getBettingItemCount(gameBetting.getUserId(), gameBetting.getGameId(), appGame.getGameDate(), gameBetting.getBettingItem());
-            if(bettingItemCount != null && bettingItemCount > 0 ){
-                if(appGameItem.getBettingCount().intValue() >= 0 && bettingItemCount.intValue() >= appGameItem.getBettingCount().intValue()){
-                    return HttpRet.fail("当前期投注选项数量已超过限额,无法下单。");
+                Integer bettingItemCount = appGameBettingService.getBettingItemCount(gameBetting.getUserId(), gameBetting.getGameId(), appGame.getGameDate(), gameBetting.getBettingItem());
+                if(bettingItemCount != null && bettingItemCount > 0 ){
+                    if(appGameItem.getBettingCount().intValue() >= 0 && bettingItemCount.intValue() >= appGameItem.getBettingCount().intValue()){
+                        return HttpRet.fail("当前期投注选项数量已超过限额,无法下单。");
+                    }
                 }
-            }
 
-            BigDecimal bettingAmountCheck = new BigDecimal(appGameItem.getBettingMoney() + "");
-            BigDecimal bettingAmountSum = appGameBettingService.getBettingAmount(gameBetting.getUserId(), gameBetting.getGameId(), appGame.getGameDate(), gameBetting.getBettingItem());
-            BigDecimal bettingAmountAdd = bettingAmountSum.add(new BigDecimal(gameBetting.getBettingAmount() + ""));
-            if(appGameItem.getBettingMoney() >= 0 && bettingAmountAdd.compareTo(bettingAmountCheck) == 1){
-                return HttpRet.fail("当前期选项投注金额已超过限额,无法下单。");
-            }
+                BigDecimal bettingAmountCheck = new BigDecimal(appGameItem.getBettingMoney() + "");
+                BigDecimal bettingAmountSum = appGameBettingService.getBettingAmount(gameBetting.getUserId(), gameBetting.getGameId(), appGame.getGameDate(), gameBetting.getBettingItem());
+                BigDecimal bettingAmountAdd = bettingAmountSum.add(new BigDecimal(gameBetting.getBettingAmount() + ""));
+                if(appGameItem.getBettingMoney() >= 0 && bettingAmountAdd.compareTo(bettingAmountCheck) == 1){
+                    return HttpRet.fail("当前期选项投注金额已超过限额,无法下单。");
+                }
 
-            gameBetting.setBettingMultiple(appGameItem.getItemMultiple());
-        // 多选
-        }else if(gameBetting.getBettingGameType() == 1 || gameBetting.getBettingGameType() == 2){
-            List<AppGameItemBettingVO> itemList = JSON.parseArray(gameBetting.getBettingItem(), AppGameItemBettingVO.class);
-            if(itemList == null || itemList.isEmpty()){
-                return HttpRet.fail("游戏选项不存在,无法下单。");
-            }
-            for(AppGameItemBettingVO item : itemList){
-                AppGameItem appGameItem = appGameItemService.selectAppGameItemByGameIdAndItemLocation(appGame.getId(), item.getBettingItem());
-                if(appGameItem == null){
+                gameBetting.setBettingMultiple(appGameItem.getItemMultiple());
+            // 多选
+            }else if(gameBetting.getBettingGameType() == 1 || gameBetting.getBettingGameType() == 2){
+                List<AppGameItemBettingVO> itemList = JSON.parseArray(gameBetting.getBettingItem(), AppGameItemBettingVO.class);
+                if(itemList == null || itemList.isEmpty()){
                     return HttpRet.fail("游戏选项不存在,无法下单。");
                 }
+                for(AppGameItemBettingVO item : itemList){
+                    AppGameItem appGameItem = appGameItemService.selectAppGameItemByGameIdAndItemLocation(appGame.getId(), item.getBettingItem());
+                    if(appGameItem == null){
+                        return HttpRet.fail("游戏选项不存在,无法下单。");
+                    }
+                }
+                // 写死的倍数
+                if(gameBetting.getBettingGameType() == 1){
+                    gameBetting.setBettingMultiple(getMultiple(itemList.size()));
+                }
             }
-            // 写死的倍数
-            if(gameBetting.getBettingGameType() == 1){
-                gameBetting.setBettingMultiple(getMultiple(itemList.size()));
+
+            AppGameLottery appGameLottery = appGameLotteryService.selectLottery(appGame.getClassifyId(), appGame.getId(), appGame.getGameDate());
+
+            if(appGameLottery == null){
+                return HttpRet.fail("游戏未开盘,无法下单。");
             }
-        }
 
-        AppGameLottery appGameLottery = appGameLotteryService.selectLottery(appGame.getClassifyId(), appGame.getId(), appGame.getGameDate());
+            if(appGameLottery.getIsLottery() == 1){
+                return HttpRet.fail("游戏已开奖,无法下单。");
+            }
 
-        if(appGameLottery == null){
-            return HttpRet.fail("游戏未开盘,无法下单。");
-        }
+            AppUser appUser = appUserService.selectAppUserByUserid(gameBetting.getUserId());
 
-        if(appGameLottery.getIsLottery() == 1){
-            return HttpRet.fail("游戏已开奖,无法下单。");
-        }
+            if(appUser == null){
+                return HttpRet.fail("用户不存在。");
+            }
 
-        AppUser appUser = appUserService.selectAppUserByUserid(gameBetting.getUserId());
+            if(gameBetting.getBettingType() == 0){
 
-        if(appUser == null){
-            return HttpRet.fail("用户不存在。");
-        }
+                // 获取用户金额,判断投注金额是否大于余额
+                if(gameBetting.getBettingAmount() > appUser.getDiamondCoin()){
+                    return HttpRet.fail("余额不足,投注失败。");
+                }
 
-        if(gameBetting.getBettingType() == 0){
+                // 更新用户余额
+                //appUser.setDiamondCoin(appUser.getDiamondCoin() - gameBetting.getBettingAmount());
+                //appUser.setDiamondCoinTotal(appUser.getDiamondCoinTotal() - gameBetting.getBettingAmount());
+                //appUser.setDiamondCoinCash(appUser.getDiamondCoinCash() - gameBetting.getBettingAmount());
+            }else{
 
-            // 获取用户金额,判断投注金额是否大于余额
-            if(gameBetting.getBettingAmount() > appUser.getDiamondCoin()){
-                return HttpRet.fail("余额不足,投注失败。");
-            }
+                // 获取用户金额,判断投注金额是否大于余额
+                if(gameBetting.getBettingAmount() > appUser.getCoin()){
+                    return HttpRet.fail("金币不足,投注失败。");
+                }
 
-            // 更新用户余额
-            //appUser.setDiamondCoin(appUser.getDiamondCoin() - gameBetting.getBettingAmount());
-            //appUser.setDiamondCoinTotal(appUser.getDiamondCoinTotal() - gameBetting.getBettingAmount());
-            //appUser.setDiamondCoinCash(appUser.getDiamondCoinCash() - gameBetting.getBettingAmount());
-        }else{
+                //appUser.setCoin(appUser.getCoin() - gameBetting.getBettingAmount());
 
-            // 获取用户金额,判断投注金额是否大于余额
-            if(gameBetting.getBettingAmount() > appUser.getCoin()){
-                return HttpRet.fail("金币不足,投注失败。");
+                // 判断不可提现金币是否满足扣款
+                //if(gameBetting.getBettingAmount() > (appUser.getCoin() - appUser.getCoinCash())){
+                //    appUser.setCoinCash(gameBetting.getBettingAmount() - (appUser.getCoin() - appUser.getCoinCash()));
+                //}
             }
 
-            //appUser.setCoin(appUser.getCoin() - gameBetting.getBettingAmount());
+            //appUserService.updateAppUser(appUser);
 
-            // 判断不可提现金币是否满足扣款
-            //if(gameBetting.getBettingAmount() > (appUser.getCoin() - appUser.getCoinCash())){
-            //    appUser.setCoinCash(gameBetting.getBettingAmount() - (appUser.getCoin() - appUser.getCoinCash()));
-            //}
-        }
+            //redisCache.deleteObject("U:UserInfo:" + appUser.getUserid());
 
-        //appUserService.updateAppUser(appUser);
-
-        //redisCache.deleteObject("U:UserInfo:" + appUser.getUserid());
+            gameBetting.setGameDate(appGame.getGameDate());
+            gameBetting.setIsLive(0);
+            if(gameBetting.getLiveRoomId() != null && gameBetting.getLiveRoomId() > 0 && gameBetting.getLiveUserId() != null && gameBetting.getLiveUserId() > 0){
+                gameBetting.setIsLive(1);
+            }
 
-        gameBetting.setGameDate(appGame.getGameDate());
-        gameBetting.setIsLive(0);
-        if(gameBetting.getLiveRoomId() != null && gameBetting.getLiveRoomId() > 0 && gameBetting.getLiveUserId() != null && gameBetting.getLiveUserId() > 0){
-            gameBetting.setIsLive(1);
-        }
+            gameBetting.setCreateTime(new Date());
+            // 插入投注记录
+            appGameBettingService.save(gameBetting);
 
-        gameBetting.setCreateTime(new Date());
-        // 插入投注记录
-        appGameBettingService.save(gameBetting);
+            FinTranRecord finTranRecord = new FinTranRecord();
 
-        FinTranRecord finTranRecord = new FinTranRecord();
+            //finTranRecord.setAfterCoin(appUser.getCoin());
+            //finTranRecord.setAfterDiamondCoin(appUser.getDiamondCoin());
 
-        //finTranRecord.setAfterCoin(appUser.getCoin());
-        //finTranRecord.setAfterDiamondCoin(appUser.getDiamondCoin());
+            if(gameBetting.getBettingType() == 0){
+                finTranRecord.setCurrencyType(4);
+                finTranRecord.setDiamondCoinChange(gameBetting.getBettingAmount() * -1);
+                finTranRecord.setCoinChange(0.00);
+            }else{
+                finTranRecord.setCurrencyType(2);
+                finTranRecord.setCoinChange(gameBetting.getBettingAmount() * -1);
+                finTranRecord.setDiamondCoinChange(0.00);
+            }
 
-        if(gameBetting.getBettingType() == 0){
-            finTranRecord.setCurrencyType(4);
-            finTranRecord.setDiamondCoinChange(gameBetting.getBettingAmount() * -1);
-            finTranRecord.setCoinChange(0.00);
-        }else{
-            finTranRecord.setCurrencyType(2);
-            finTranRecord.setCoinChange(gameBetting.getBettingAmount() * -1);
-            finTranRecord.setDiamondCoinChange(0.00);
-        }
+            finTranRecord.setAfterMoney(0.00);
+            finTranRecord.setMoneyChange(0.00);
 
-        finTranRecord.setAfterMoney(0.00);
-        finTranRecord.setMoneyChange(0.00);
+            finTranRecord.setAfterTicket(0.00);
+            finTranRecord.setTicketChange(0.00);
 
-        finTranRecord.setAfterTicket(0.00);
-        finTranRecord.setTicketChange(0.00);
+            finTranRecord.setToUid(appUser.getUserid());
+            finTranRecord.setUid(appUser.getUserid());
 
-        finTranRecord.setToUid(appUser.getUserid());
-        finTranRecord.setUid(appUser.getUserid());
+            finTranRecord.setSceneId1(0L);
+            finTranRecord.setSceneId2(null);
+            finTranRecord.setSceneType(0L);
 
-        finTranRecord.setSceneId1(0L);
-        finTranRecord.setSceneId2(null);
-        finTranRecord.setSceneType(0L);
+            finTranRecord.setTranGroupId(gameBetting.getId());
+            finTranRecord.setTranType1(FinTranType1.U_Outcome_Balance.getType());
+            finTranRecord.setTranType2(FinTranType2.CONSUM_GAME.getType());
+            finTranRecord.setTranType3(FinTranType3.CONSUM_GAME_ANCHOR_ZHUANPAN.getType());
 
-        finTranRecord.setTranGroupId(gameBetting.getId());
-        finTranRecord.setTranType1(FinTranType1.U_Outcome_Balance.getType());
-        finTranRecord.setTranType2(FinTranType2.CONSUM_GAME.getType());
-        finTranRecord.setTranType3(FinTranType3.CONSUM_GAME_ANCHOR_ZHUANPAN.getType());
+            finTranRecord.setRemarks("游戏下注");
 
-        finTranRecord.setRemarks("游戏下注");
+            finTranRecord.setConsumptionCoin(gameBetting.getBettingAmount());
+            finTranRecord.setConsumptionMoney(0.00);
+            finTranRecord.setCommissionRelatedUid(0L);
+            finTranRecord.setAgentId(appUser.getAgentId());
 
-        finTranRecord.setConsumptionCoin(gameBetting.getBettingAmount());
-        finTranRecord.setConsumptionMoney(0.00);
-        finTranRecord.setCommissionRelatedUid(0L);
-        finTranRecord.setAgentId(appUser.getAgentId());
+            finTranRecord.setCreateTime(new Date());
 
-        finTranRecord.setCreateTime(new Date());
+            finTranRecord.setFromUid(appUser.getUserid());
+            finTranRecord.setGoodsId(0L);
+            finTranRecord.setGuildId(0L);
+            finTranRecord.setManagerCoId(0L);
+            finTranRecord.setManagerId(0L);
 
-        finTranRecord.setFromUid(appUser.getUserid());
-        finTranRecord.setGoodsId(0L);
-        finTranRecord.setGuildId(0L);
-        finTranRecord.setManagerCoId(0L);
-        finTranRecord.setManagerId(0L);
+            finTranRecord.setPerc(0.00);
+            finTranRecord.setProId(0L);
+            finTranRecord.setProCount(0L);
 
-        finTranRecord.setPerc(0.00);
-        finTranRecord.setProId(0L);
-        finTranRecord.setProCount(0L);
+            finTranRecord.setOrderId(gameBetting.getId());
+            //finTranRecordService.insertFinTranRecord(finTranRecord);
+            appUserService.updateUserAmount(finTranRecord);
 
-        finTranRecord.setOrderId(gameBetting.getId());
-        //finTranRecordService.insertFinTranRecord(finTranRecord);
-        appUserService.updateUserAmount(finTranRecord);
+            // 分佣
+            if(gameBetting.getBettingType() == 0){
+                appAgentGameBettingTask.agentGameBettingTask(gameBetting);
+            }
 
-        // 分佣
-        if(gameBetting.getBettingType() == 0){
-            appAgentGameBettingTask.agentGameBettingTask(gameBetting);
+            diamondCoin = appUser.getDiamondCoin();
+        }catch (Exception e){
+            throw new Exception("下注异常");
+        }finally {
+            redisCache.redisTemplate.delete(redisKey);
         }
 
-        return HttpRet.success("下注成功", appUser.getDiamondCoin());
+        return HttpRet.success("下注成功", diamondCoin);
     }
 
     /**

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

@@ -72,4 +72,9 @@ public class CacheConstants
      */
     public static final String GAME_LOTTERY_ITEM_MULTIPLE = "game_lottery_item_multiple:";
 
+    /**
+     * 用户下注锁
+     */
+    public static final String GAME_USER_BETTING_CREATE = "game_user_betting_create:";
+
 }