From b44c8838c48957c5e7bd2271face8a11bb10f951 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Sun, 27 Dec 2020 12:33:30 +0800 Subject: [PATCH] =?UTF-8?q?add:=E6=96=B0=E5=A2=9E=E9=9A=90=E8=97=8F?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/catcher/base/CatchModel.php | 5 +- extend/catcher/traits/db/RewriteTrait.php | 56 +++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 extend/catcher/traits/db/RewriteTrait.php diff --git a/extend/catcher/base/CatchModel.php b/extend/catcher/base/CatchModel.php index 52adb78..c47b7e4 100644 --- a/extend/catcher/base/CatchModel.php +++ b/extend/catcher/base/CatchModel.php @@ -5,6 +5,7 @@ namespace catcher\base; use catcher\CatchQuery; use catcher\traits\db\BaseOptionsTrait; +use catcher\traits\db\RewriteTrait; use catcher\traits\db\TransTrait; use think\model\concern\SoftDelete; use catcher\traits\db\ScopeTrait; @@ -17,7 +18,7 @@ use catcher\traits\db\ScopeTrait; */ abstract class CatchModel extends \think\Model { - use SoftDelete, TransTrait, BaseOptionsTrait, ScopeTrait; + use SoftDelete, TransTrait, BaseOptionsTrait, ScopeTrait, RewriteTrait; protected $createTime = 'created_at'; @@ -29,8 +30,8 @@ abstract class CatchModel extends \think\Model protected $autoWriteTimestamp = true; + // 分页 Limit public const LIMIT = 10; - // 开启 public const ENABLE = 1; // 禁用 diff --git a/extend/catcher/traits/db/RewriteTrait.php b/extend/catcher/traits/db/RewriteTrait.php new file mode 100644 index 0000000..8dfc628 --- /dev/null +++ b/extend/catcher/traits/db/RewriteTrait.php @@ -0,0 +1,56 @@ +hidden = array_merge($this->hidden, $this->defaultHiddenFields()); + } + + /** + * hidden model fields + * + * @return array + */ + protected function defaultHiddenFields(): array + { + return [$this->deleteTime]; + } + + /** + * 重写 hidden 方法,支持合并 hidden 属性 + * + * @param array $hidden + * @return $this + */ + public function hidden(array $hidden = []) + { + /** + * 合并属性 + */ + if (!count($this->hidden)) { + $this->hidden = array_merge($this->hidden, $hidden); + + return $this; + } + + $this->hidden = $hidden; + + return $this; + } +} \ No newline at end of file