From 501ff21e55d5aeb9c6b266b94a0b24a71094e61c Mon Sep 17 00:00:00 2001 From: kuaifan Date: Sun, 4 Jan 2026 00:29:29 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=95=B0=E5=80=BC?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E8=BD=AC=E6=8D=A2=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E7=A1=AE=E4=BF=9D=E6=9F=A5=E8=AF=A2=E7=BB=93=E6=9E=9C=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E5=80=BC=E7=B1=BB=E5=9E=8B=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Module/Manticore/ManticoreBase.php | 32 ++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/app/Module/Manticore/ManticoreBase.php b/app/Module/Manticore/ManticoreBase.php index 84644add1..d18441e31 100644 --- a/app/Module/Manticore/ManticoreBase.php +++ b/app/Module/Manticore/ManticoreBase.php @@ -256,7 +256,7 @@ class ManticoreBase $stmt = $pdo->prepare($sql); $this->bindParams($stmt, $params); $stmt->execute(); - return $stmt->fetchAll(); + return $this->convertNumericTypes($stmt->fetchAll()); } catch (PDOException $e) { Log::error('Manticore query error: ' . $e->getMessage(), [ 'sql' => $sql, @@ -285,7 +285,7 @@ class ManticoreBase $this->bindParams($stmt, $params); $stmt->execute(); $result = $stmt->fetch(); - return $result ?: null; + return $result ? $this->convertNumericTypesRow($result) : null; } catch (PDOException $e) { Log::error('Manticore queryOne error: ' . $e->getMessage(), [ 'sql' => $sql, @@ -295,6 +295,34 @@ class ManticoreBase } } + /** + * 转换结果集中的数值类型 + * PDO 默认将 BIGINT 等数值类型返回为字符串,这里统一转换 + * + * @param array $rows 结果集 + * @return array 转换后的结果集 + */ + private function convertNumericTypes(array $rows): array + { + return array_map([$this, 'convertNumericTypesRow'], $rows); + } + + /** + * 转换单行数据中的数值类型 + * + * @param array $row 单行数据 + * @return array 转换后的数据 + */ + private function convertNumericTypesRow(array $row): array + { + foreach ($row as $key => $value) { + if (is_string($value) && is_numeric($value) && !str_contains($value, '.')) { + $row[$key] = (int) $value; + } + } + return $row; + } + /** * 绑定参数到预处理语句 * Manticore 对参数类型敏感,需要明确指定 INT 类型