Explorar el Código

特殊游戏投注判断

kk hace 1 mes
padre
commit
b3b485a834

+ 41 - 4
game-business/src/main/java/com/game/business/controller/AppGameBettingController.java

@@ -158,15 +158,52 @@ public class AppGameBettingController extends BaseController{
         // 每期可投注多少个选项:比如设置为3 则只能投3个不同的选项,不能超过3个
         Integer bettingCount = appGameBettingService.getBettingCount(gameBetting.getUserId(), gameBetting.getGameId(), appGame.getGameDate(), gameBetting.getBettingItem());
         if(bettingCount != null && bettingCount > 0 ){
-            if(bettingCount.intValue() >= appGame.getBettingCount().intValue()){
+            if(appGame.getBettingCount().intValue() >= 0 && bettingCount.intValue() >= appGame.getBettingCount().intValue()){
                 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)){
+
+            List<String> itemList = Arrays.asList(Common.GAME_BETTING_ITEM_LIMIT);
+
+            // 当前投注的是否属于特殊固定选项
+            if(itemList.contains(gameBetting.getBettingItem())) {
+
+                List<String> bettingItemList = appGameBettingService.getBettingItem(gameBetting.getUserId(), gameBetting.getGameId(), appGame.getGameDate());
+                if (bettingItemList != null && !bettingItemList.isEmpty()) {
+
+                    List<String> checkItemList = new ArrayList<>();
+
+                    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(gameBettingAmountAdd.compareTo(gameBettingAmountCheck) == 1){
+        if(appGame.getBettingMaxMoney() >= 0 && gameBettingAmountAdd.compareTo(gameBettingAmountCheck) == 1){
             return HttpRet.fail("当前期投注金额已超过限额,无法下单。");
         }
 
@@ -188,7 +225,7 @@ public class AppGameBettingController extends BaseController{
 
             Integer bettingItemCount = appGameBettingService.getBettingItemCount(gameBetting.getUserId(), gameBetting.getGameId(), appGame.getGameDate(), gameBetting.getBettingItem());
             if(bettingItemCount != null && bettingItemCount > 0 ){
-                if(bettingItemCount.intValue() >= appGameItem.getBettingCount().intValue()){
+                if(appGameItem.getBettingCount().intValue() >= 0 && bettingItemCount.intValue() >= appGameItem.getBettingCount().intValue()){
                     return HttpRet.fail("当前期投注选项数量已超过限额,无法下单。");
                 }
             }
@@ -196,7 +233,7 @@ public class AppGameBettingController extends BaseController{
             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(bettingAmountAdd.compareTo(bettingAmountCheck) == 1){
+            if(appGameItem.getBettingMoney() >= 0 && bettingAmountAdd.compareTo(bettingAmountCheck) == 1){
                 return HttpRet.fail("当前期选项投注金额已超过限额,无法下单。");
             }
 

+ 1 - 1
game-business/src/main/java/com/game/business/mapper/AppGameBettingMapper.java

@@ -24,7 +24,7 @@ public interface AppGameBettingMapper extends BaseMapper<AppGameBetting> {
     Integer getBettingCount(@Param(value = "userId") Long userId, @Param(value = "gameId") Long gameId, @Param(value = "gameDate") String gameDate, @Param(value = "bettingItem") String bettingItem);
     Integer getBettingItemCount(@Param(value = "userId") Long userId, @Param(value = "gameId") Long gameId, @Param(value = "gameDate") String gameDate, @Param(value = "bettingItem") String bettingItem);
     BigDecimal getBettingAmount(@Param(value = "userId") Long userId, @Param(value = "gameId") Long gameId, @Param(value = "gameDate") String gameDate, @Param(value = "bettingItem") String bettingItem);
-
+    List<String> getBettingItem(@Param(value = "userId") Long userId, @Param(value = "gameId") Long gameId, @Param(value = "gameDate") String gameDate);
     /**
      * 查询用户下注记录
      *

+ 2 - 0
game-business/src/main/java/com/game/business/service/IAppGameBettingService.java

@@ -51,6 +51,8 @@ public interface IAppGameBettingService extends IService<AppGameBetting> {
 
     BigDecimal getBettingAmount(Long userId, Long gameId, String gameDate, String bettingItem);
 
+    List<String> getBettingItem(Long userId, Long gameId, String gameDate);
+
     /**
      * 查询用户下注记录
      *

+ 5 - 0
game-business/src/main/java/com/game/business/service/impl/AppGameBettingServiceImpl.java

@@ -175,6 +175,11 @@ public class AppGameBettingServiceImpl extends ServiceImpl<AppGameBettingMapper,
         return appGameBettingMapper.getBettingAmount(userId, gameId, gameDate, bettingItem);
     }
 
+    @Override
+    public List<String> getBettingItem(Long userId, Long gameId, String gameDate) {
+        return appGameBettingMapper.getBettingItem(userId, gameId, gameDate);
+    }
+
     /**
      * 查询用户下注记录
      *

+ 2 - 0
game-business/src/main/java/com/game/business/util/Common.java

@@ -24,6 +24,8 @@ public class Common {
     public static final String GAME_SEVEN_CODE = "7";
 
 
+    public static final String [] GAME_BETTING_ITEM_LIMIT = {"1","2","7","8"};
+
 //    public static final String WS_GAME_ONE_URL = "ws://47.115.59.17:8000/ws";
 //    public static final String WS_GAME_ONE_REMARK_URL = "ws://47.115.59.17:8000/ws";
 //    public static final String WS_GAME_TWO_URL = "ws://47.115.54.173:8000/ws";

+ 7 - 0
game-business/src/main/resources/mapper/business/AppGameBettingMapper.xml

@@ -100,6 +100,13 @@
         ) tmp
     </select>
 
+    <select id="getBettingItem" resultType="java.lang.String">
+        select
+            betting_item
+        from app_game_betting where user_id = #{userId} and game_id = #{gameId} and game_date = #{gameDate}
+        group by betting_item
+    </select>
+
     <select id="getBettingItemCount" resultType="java.lang.Integer">
         select
             ifnull(count(1), 0) as bettingCount