From fedfd9c8573f43e3d376ea33026fca4aad8890ac Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 28 Nov 2016 23:24:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index d35be22c..39ab03a9 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -917,6 +917,9 @@ class Query if (is_array($field)) { // 数组批量查询 $where = $field; + foreach ($where as $k => $val) { + $this->options['multi'][$k][] = $val; + } } elseif ($field && is_string($field)) { // 字符串查询 $where[$field] = ['null', '']; @@ -938,13 +941,25 @@ class Query if (!isset($this->options['where'][$logic])) { $this->options['where'][$logic] = []; } - if (isset($this->options['multi'][$field]) && count($this->options['multi'][$field]) > 1) { + if (is_string($field) && $this->checkMultiField($field)) { $where[$field] = $this->options['multi'][$field]; + } elseif (is_array($field)) { + foreach ($field as $key => $val) { + if ($this->checkMultiField($key)) { + $where[$key] = $this->options['multi'][$key]; + } + } } $this->options['where'][$logic] = array_merge($this->options['where'][$logic], $where); } } + // 检查是否存在一个字段多次查询条件 + private function checkMultiField($field) + { + return isset($this->options['multi'][$field]) && count($this->options['multi'][$field]) > 1; + } + /** * 去除某个查询条件 * @access public