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(); }