seven 2 天之前
父节点
当前提交
e95bfdf109
共有 2 个文件被更改,包括 26 次插入0 次删除
  1. 24 0
      app/Constants/GameplayRuleEnum
  2. 2 0
      app/Services/GameplayRuleService.php

+ 24 - 0
app/Constants/GameplayRuleEnum

@@ -121,4 +121,28 @@ class GameplayRuleEnum
         ]
         ]
 
 
     ];
     ];
+
+    /**
+     * 验证并解析用户输入
+     * @param string $input 例如 "大单100" / "5操20"
+     * @return array|null   返回 ['rule' => 玩法, 'amount' => 金额],失败返回 null
+     */
+    public static function validateInput(string $input): ?array
+    {
+        // 获取所有玩法
+        $allRules = array_merge(...self::$RULES);
+
+        // 玩法正则(防止玩法里有特殊符号出错)
+        $rulesPattern = implode('|', array_map('preg_quote', $allRules));
+
+        // 匹配玩法 + 金额
+        if (preg_match('/^(' . $rulesPattern . ')(\d+)$/u', $input, $matches)) {
+            return [
+                'rule'   => $matches[1],
+                'amount' => (int)$matches[2]
+            ];
+        }
+
+        return null;
+    }
 }
 }

+ 2 - 0
app/Services/GameplayRuleService.php

@@ -163,4 +163,6 @@ class GameplayRuleService extends BaseService
         $cacheKey = self::CACHE_KEY . $keywords;
         $cacheKey = self::CACHE_KEY . $keywords;
         Cache::forget($cacheKey);
         Cache::forget($cacheKey);
     }
     }
+
+    
 }
 }