From a489f99ef44d458c3beb3f29f4205384822505dc Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 31 Mar 2017 16:04:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=8C=83=E5=9B=B4=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E9=9D=99=E6=80=81=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 976823aa..bae4902f 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1812,16 +1812,27 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } } - public static function __callStatic($method, $params) + public static function __callStatic($method, $args) { + $model = new static(); + if (isset(static::$db)) { $query = static::$db; static::$db = null; } else { - $query = (new static())->db(); + $query = $model->db(); } - return call_user_func_array([$query, $method], $params); + if (method_exists($model, 'scope' . $method)) { + // 动态调用命名范围 + $method = 'scope' . $method; + array_unshift($args, $query); + + call_user_func_array([$model, $method], $args); + return $query; + } else { + return call_user_func_array([$query, $method], $args); + } } /**