From 538f675cca80f9218eb8d90beca8eb56a2cead00 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 13 Dec 2016 17:58:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=BD=AF=E5=88=A0=E9=99=A4de?= =?UTF-8?q?stroy=E5=92=8Crestore=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/traits/model/SoftDelete.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/library/traits/model/SoftDelete.php b/library/traits/model/SoftDelete.php index 9d855c76..281c26c9 100644 --- a/library/traits/model/SoftDelete.php +++ b/library/traits/model/SoftDelete.php @@ -77,8 +77,8 @@ trait SoftDelete */ public static function destroy($data, $force = false) { - $model = new static(); - $query = $model->db(); + // 包含软删除数据 + $query = self::withTrashed(); if (is_array($data) && key($data) !== 0) { $query->where($data); $data = null; @@ -109,9 +109,13 @@ trait SoftDelete public function restore($where = []) { $name = $this->getDeleteTimeField(); + if (empty($where)) { + $pk = $this->getPk(); + $where[$pk] = $this->getData($pk); + $where[$name] = ['not null', '']; + } // 恢复删除 - return $this->isUpdate()->save([$name => null], $where); - + return $this->removeWhereField($this->getDeleteTimeField(true))->where($where)->update([$name => null]); } /**