From 9d6c326dfdfd0be2f65ebc0359a25b2ad8417412 Mon Sep 17 00:00:00 2001 From: xieyongfa <215005377@qq.com> Date: Thu, 14 Nov 2024 11:14:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E7=BC=93=E5=AD=98key?= =?UTF-8?q?=E7=94=9F=E6=88=90=E9=80=BB=E8=BE=91,=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E9=97=AD=E5=8C=85=E6=9D=A1=E4=BB=B6=E4=B9=9F=E5=8F=82=E4=B8=8E?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/Query.php | 16 ++++++++++++++-- src/db/concern/WhereQuery.php | 17 +++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/db/Query.php b/src/db/Query.php index c8a05721..b4e83696 100644 --- a/src/db/Query.php +++ b/src/db/Query.php @@ -517,12 +517,24 @@ protected function getLazyFieldCacheKey(string $field, $id = null): string */ public function getQueryGuid($data = null): string { + $logic_closure_string = ''; if (null === $data) { $data = $this->options; unset($data['scope'], $data['default_model']); + $logic_list = ['AND', 'OR', 'XOR']; + foreach ($logic_list as $logic) { + if (isset($data['where']) && isset($data['where'][$logic])) { + foreach ($this->options['where'][$logic] as $key => $val) { + if ($val instanceof \Closure) { + $reflection = new \ReflectionFunction($val); + $static_properties = $reflection->getStaticVariables(); + $logic_closure_string .= $logic . print_r($static_properties, true); + } + } + } + } } - - return md5($this->getConfig('database') . serialize(var_export($data, true)) . serialize($this->getBind(false))); + return md5($this->getConfig('database') . serialize(var_export($data, true)) . serialize($this->getBind(false)) . serialize($logic_closure_string)); } /** diff --git a/src/db/concern/WhereQuery.php b/src/db/concern/WhereQuery.php index 5a3a18a3..04de2b17 100644 --- a/src/db/concern/WhereQuery.php +++ b/src/db/concern/WhereQuery.php @@ -30,12 +30,13 @@ trait WhereQuery */ public function where($field, $op = null, $condition = null) { + $logic = 'AND'; if ($field instanceof $this) { $this->parseQueryWhere($field); return $this; } elseif (true === $field || 1 === $field) { - $this->options['where']['AND'][] = true; + $this->options['where'][$logic][] = true; return $this; } @@ -49,11 +50,11 @@ public function where($field, $op = null, $condition = null) array_shift($param); if (is_array($field)) { - return $this->where(function ($query) use ($param, $condition, $op, $field) { - return $query->parseWhereExp('AND', $field, $op, $condition, $param); + return $this->where(function ($query) use ($param, $condition, $op, $field, $logic) { + return $query->parseWhereExp($logic, $field, $op, $condition, $param); }); } - return $this->parseWhereExp('AND', $field, $op, $condition, $param); + return $this->parseWhereExp($logic, $field, $op, $condition, $param); } /** @@ -95,14 +96,14 @@ public function whereOr($field, $op = null, $condition = null) { $param = func_get_args(); array_shift($param); - + $logic = 'OR'; if (is_array($field)) { - return $this->where(function ($query) use ($param, $condition, $op, $field) { - return $query->parseWhereExp('OR', $field, $op, $condition, $param); + return $this->where(function ($query) use ($param, $condition, $op, $field, $logic) { + return $query->parseWhereExp($logic, $field, $op, $condition, $param); }); } - return $this->parseWhereExp('OR', $field, $op, $condition, $param); + return $this->parseWhereExp($logic, $field, $op, $condition, $param); } /**