From e1abef23193e92db4c6baaaa2f24e7c88a2083f7 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Thu, 30 Apr 2020 17:58:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eorder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/catcher/CatchQuery.php | 34 +++++++++++++++++++ extend/catcher/traits/db/BaseOptionsTrait.php | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/extend/catcher/CatchQuery.php b/extend/catcher/CatchQuery.php index e22d040..f52e975 100644 --- a/extend/catcher/CatchQuery.php +++ b/extend/catcher/CatchQuery.php @@ -178,4 +178,38 @@ class CatchQuery extends Query return parent::paginate($listRows, $simple); // TODO: Change the autogenerated stub } + + /** + * order 排序 + * + * @time 2020年04月30日 + * @param string $field + * @param string $order + * @param string $position + * @return $this|CatchQuery + */ + public function order($field = '', string $order = 'desc', $position = 'backend') + { + if ($position = 'front') { + parent::order($field, $order); + } + + if (property_exists($this, 'field')) { + if (in_array('sort', $this->field)) { + parent::order('sort', 'desc'); + } + } + + if ($position == 'middle') { + parent::order($field, $order); + } + + parent::order($this->getPk(), 'desc'); + + if ($position == 'backend') { + parent::order($field, $order); + } + + return $this; + } } diff --git a/extend/catcher/traits/db/BaseOptionsTrait.php b/extend/catcher/traits/db/BaseOptionsTrait.php index 2a15911..f2be993 100644 --- a/extend/catcher/traits/db/BaseOptionsTrait.php +++ b/extend/catcher/traits/db/BaseOptionsTrait.php @@ -13,7 +13,7 @@ trait BaseOptionsTrait public function getList() { return $this->catchSearch() - ->order($this->getPk(), 'desc') + ->order() ->paginate(); }