From 69773f2e8d5a89adcbfc6804e12c04009075b614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=98=8A=E5=A4=A9?= <442384644@qq.com> Date: Sat, 18 Mar 2023 17:41:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=99=A8=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crmeb/app/dao/BaseDao.php | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/crmeb/app/dao/BaseDao.php b/crmeb/app/dao/BaseDao.php index 338253d2c..7061af2b0 100644 --- a/crmeb/app/dao/BaseDao.php +++ b/crmeb/app/dao/BaseDao.php @@ -291,38 +291,43 @@ abstract class BaseDao } /** - * 获取搜索器和搜索条件key - * @param array $withSearch + * 获取搜索器和搜索条件key,以及不在搜索器的条件数组 + * @param array $where * @return array[] * @throws \ReflectionException + * @author 吴汐 + * @email 442384644@qq.com + * @date 2023/03/18 */ - private function getSearchData(array $withSearch) + private function getSearchData(array $where) { $with = []; - $whereKey = []; + $otherWhere = []; $responses = new \ReflectionClass($this->setModel()); - foreach ($withSearch as $fieldName) { - $method = 'search' . Str::studly($fieldName) . 'Attr'; + foreach ($where as $key => $value) { + $method = 'search' . Str::studly($key) . 'Attr'; if ($responses->hasMethod($method)) { - $with[] = $fieldName; + $with[] = $key; } else { - $whereKey[] = $fieldName; + $otherWhere[] = $value; } } - return [$with, $whereKey]; + return [$with, $otherWhere]; } /** * 根据搜索器获取搜索内容 - * @param array $withSearch - * @param array|null $data + * @param $where * @return BaseModel * @throws \ReflectionException + * @author 吴汐 + * @email 442384644@qq.com + * @date 2023/03/18 */ - protected function withSearchSelect(array $withSearch, ?array $data = []) + protected function withSearchSelect($where) { - [$with] = $this->getSearchData($withSearch); - return $this->getModel()->withSearch($with, $data); + [$with, $otherWhere] = $this->getSearchData($where); + return $this->getModel()->withSearch($with, $where)->where($otherWhere); } /** @@ -330,11 +335,14 @@ abstract class BaseDao * @param array $where * @return BaseModel * @throws \ReflectionException + * @author 吴汐 + * @email 442384644@qq.com + * @date 2023/03/18 */ protected function search(array $where = []) { if ($where) { - return $this->withSearchSelect(array_keys($where), $where); + return $this->withSearchSelect($where); } else { return $this->getModel(); }