From 655541210a604026f044afe89b42b13cc92f1b3e Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Mon, 29 Jun 2020 22:01:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=A6=81=E7=94=A8/=E5=90=AF?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/catcher/base/CatchRepository.php | 1 + extend/catcher/traits/db/BaseOptionsTrait.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/extend/catcher/base/CatchRepository.php b/extend/catcher/base/CatchRepository.php index 3b2b697..933ee1b 100644 --- a/extend/catcher/base/CatchRepository.php +++ b/extend/catcher/base/CatchRepository.php @@ -17,6 +17,7 @@ namespace catcher\base; * @method updateBy(int $id, array $data) * @method findBy(int $id, array $column = ['*']) * @method deleteBy(int $id) + * @method disOrEnable(int $id) * @method startTrans() * @method rollback() * @method commit() diff --git a/extend/catcher/traits/db/BaseOptionsTrait.php b/extend/catcher/traits/db/BaseOptionsTrait.php index 7f1f8bf..6fff23e 100644 --- a/extend/catcher/traits/db/BaseOptionsTrait.php +++ b/extend/catcher/traits/db/BaseOptionsTrait.php @@ -155,4 +155,23 @@ trait BaseOptionsTrait { return sprintf('%s.%s', $this->getTable(), $field); } + + /** + * 禁用/启用 + * + * @time 2020年06月29日 + * @param $id + * @param string $field + * @return mixed + */ + public function disOrEnable($id, $field='status') + { + $model = $this->findBy($id); + + $status = $model->{$field} == self::DISABLE ? self::ENABLE : self::DISABLE; + + $model->{$field} = $status; + + return $model->save(); + } }