From 8af18e3527086b0bdcacd24acc078a7a08dd1905 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 3 Jun 2016 14:27:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB=E7=9A=84parseE?= =?UTF-8?q?xpress=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index be13475c..0e1ce67d 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1836,23 +1836,20 @@ class Query if (!isset($options['where'])) { $options['where'] = []; } elseif (isset($options['view'])) { - if (isset($options['where']['AND'])) { - foreach ($options['where']['AND'] as $key => $val) { - if (array_key_exists($key, $options['map'])) { - $options['where']['AND'][$options['map'][$key]] = $val; - unset($options['where']['AND'][$key]); - } - } - } - if (isset($options['where']['OR'])) { - foreach ($options['where']['OR'] as $key => $val) { - if (array_key_exists($key, $options['map'])) { - $options['where']['OR'][$options['map'][$key]] = $val; - unset($options['where']['OR'][$key]); + // 视图查询条件处理 + foreach (['AND', 'OR'] as $logic) { + if (isset($options['where'][$logic])) { + foreach ($options['where'][$logic] as $key => $val) { + if (array_key_exists($key, $options['map'])) { + $options['where'][$logic][$options['map'][$key]] = $val; + unset($options['where'][$logic][$key]); + } } } } + if (isset($options['order'])) { + // 视图查询排序处理 if (is_string($options['order'])) { $options['order'] = explode(',', $options['order']); } @@ -1864,17 +1861,13 @@ class Query $options['order'][$options['map'][$field]] = $sort; unset($options['order'][$key]); } - } else { - if (array_key_exists($val, $options['map'])) { - $options['order'][$options['map'][$val]] = 'asc'; - unset($options['order'][$key]); - } - } - } else { - if (array_key_exists($key, $options['map'])) { - $options['order'][$options['map'][$key]] = $val; + } elseif (array_key_exists($val, $options['map'])) { + $options['order'][$options['map'][$val]] = 'asc'; unset($options['order'][$key]); } + } elseif (array_key_exists($key, $options['map'])) { + $options['order'][$options['map'][$key]] = $val; + unset($options['order'][$key]); } } }