Browse Source

修改投注逻辑

kk 2 months ago
parent
commit
7f6d6dc312

+ 12 - 0
game-business/src/main/java/com/game/business/controller/AppGameBettingController.java

@@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -117,8 +118,12 @@ public class AppGameBettingController extends BaseController{
             return HttpRet.fail("游戏已封盘,无法下单。");
         }
 
+
+        Integer bettingCount = appGameBettingService.getBettingCount(gameBetting.getUserId(), gameBetting.getGameId(), gameBetting.getGameDate());
+
         // 单选
         if(gameBetting.getBettingGameType() == 0){
+
             AppGameItem appGameItem = appGameItemService.selectAppGameItemByGameIdAndItemLocation(appGame.getId(), gameBetting.getBettingItem());
             if(appGameItem == null){
                 return HttpRet.fail("游戏选项不存在,无法下单。");
@@ -132,6 +137,13 @@ public class AppGameBettingController extends BaseController{
                 }
             }
 
+            BigDecimal bettingAmountCheck = new BigDecimal("0");
+            BigDecimal bettingAmountSum = appGameBettingService.getBettingAmount(gameBetting.getUserId(), gameBetting.getGameId(), gameBetting.getGameDate(), gameBetting.getBettingItem());
+            BigDecimal bettingAmountAdd = bettingAmountSum.add(new BigDecimal(gameBetting.getBettingAmount() + ""));
+            if(bettingAmountAdd.compareTo(bettingAmountCheck) == 1){
+                return HttpRet.fail("游戏选项当前期投注金额已超过限额,无法下单。");
+            }
+
             gameBetting.setBettingMultiple(appGameItem.getItemMultiple());
         // 多选
         }else if(gameBetting.getBettingGameType() == 1 || gameBetting.getBettingGameType() == 2){

+ 5 - 0
game-business/src/main/java/com/game/business/domain/AppGameBetting.java

@@ -46,6 +46,11 @@ public class AppGameBetting {
     @ApiModelProperty(value = "直播房间号")
     private Long liveRoomId;
 
+    @Excel(name = "金额ID")
+    @TableField(value = "money_id")
+    @ApiModelProperty(value = "金额ID")
+    private Long moneyId;
+
     @Excel(name = "是否直播间投注 0:否 1:是")
     @TableField(value = "is_live")
     @ApiModelProperty(value = "是否直播间投注 0:否 1:是")

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

@@ -20,4 +20,7 @@ public interface AppGameBettingMapper extends BaseMapper<AppGameBetting> {
     List<AppUserGameBettingDetailsCountVO> getUserBettingItemCount(@Param(value = "gameId") Long gameId, @Param(value = "gameDate") String gameDate, @Param(value = "userId") Long userId, @Param(value = "bettingType") Integer bettingType);
     Map<String, BigDecimal> getBettingAmountSum(Long userId);
     Map<String, BigDecimal> getBettingAmountByDateSum(FinTranRecordDTO finTranRecordDTO);
+
+    Integer getBettingCount(@Param(value = "userId") Long userId, @Param(value = "gameId") Long gameId, @Param(value = "gameDate") String gameDate);
+    BigDecimal getBettingAmount(@Param(value = "userId") Long userId, @Param(value = "gameId") Long gameId, @Param(value = "gameDate") String gameDate, @Param(value = "bettingItem") String bettingItem);
 }

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

@@ -39,4 +39,8 @@ public interface IAppGameBettingService extends IService<AppGameBetting> {
     Map<String, BigDecimal> getBettingAmountSum(Long userId);
 
     Map<String, BigDecimal> getBettingAmountByDateSum(FinTranRecordDTO finTranRecordDTO);
+
+    Integer getBettingCount(Long userId, Long gameId, String gameDate);
+
+    BigDecimal getBettingAmount(Long userId, Long gameId, String gameDate, String bettingItem);
 }

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

@@ -130,4 +130,16 @@ public class AppGameBettingServiceImpl extends ServiceImpl<AppGameBettingMapper,
     public Map<String, BigDecimal> getBettingAmountByDateSum(FinTranRecordDTO finTranRecordDTO) {
         return appGameBettingMapper.getBettingAmountByDateSum(finTranRecordDTO);
     }
+
+    @Override
+    public Integer getBettingCount(Long userId, Long gameId, String gameDate) {
+        return appGameBettingMapper.getBettingCount(userId, gameId, gameDate);
+    }
+
+    @Override
+    public BigDecimal getBettingAmount(Long userId, Long gameId, String gameDate, String bettingItem) {
+        return appGameBettingMapper.getBettingAmount(userId, gameId, gameDate, bettingItem);
+    }
+
+
 }

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

@@ -69,4 +69,16 @@
             </if>
         </where>
     </select>
+
+    <select id="getBettingCount" resultType="java.util.Map">
+        select
+        ifnull(count(1), 0) as bettingCount
+        from app_game_betting where user_id = #{userId} and game_id = #{gameId} and game_date = #{gameDate}
+    </select>
+
+    <select id="getBettingAmount" resultType="java.util.Map">
+        select
+            ifnull(sum(betting_amount), 0.00) as bettingAmount
+        from app_game_betting where user_id = #{userId} and game_id = #{gameId} and game_date = #{gameDate} and betting_item = #{bettingItem}
+    </select>
 </mapper>