From d086406a547bea2df55b39fa575c057a0d8e41ae Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 10 Mar 2017 11:27:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index d3c4d837..2160604d 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -779,22 +779,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess return false; } - protected function autoWriteUpdateTime(&$data) - { - // 自动写入更新时间 - if ($this->autoWriteTimestamp && $this->updateTime && (empty($this->change) || !in_array($this->updateTime, $this->change))) { - $data[$this->updateTime] = $this->autoWriteTimestamp($this->updateTime); - } - } - - protected function autoWriteCreateTime(&$data) - { - // 自动写入创建时间 - if ($this->autoWriteTimestamp && $this->createTime && (empty($this->change) || !in_array($this->createTime, $this->change))) { - $data[$this->createTime] = $this->autoWriteTimestamp($this->createTime); - } - } - /** * 保存当前数据对象 * @access public @@ -886,9 +870,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } } - if (!empty($data)) { + if (!empty($data) && $this->autoWriteTimestamp && $this->updateTime && !isset($data[$this->updateTime])) { // 自动写入更新时间 - $this->autoWriteUpdateTime($data); + $data[$this->updateTime] = $this->autoWriteTimestamp($this->updateTime); } else { return 0; } @@ -939,10 +923,15 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } else { // 自动写入 $this->autoCompleteData($this->insert); - // 自动写入创建时间 - $this->autoWriteCreateTime($this->data); - // 自动写入更新时间 - $this->autoWriteUpdateTime($this->data); + // 自动写入创建时间和更新时间 + if ($this->autoWriteTimestamp) { + if ($this->createTime && !isset($this->data[$this->createTime])) { + $this->data[$this->createTime] = $this->autoWriteTimestamp($this->createTime); + } + if ($this->updateTime && !isset($this->data[$this->updateTime])) { + $this->data[$this->updateTime] = $this->autoWriteTimestamp($this->updateTime); + } + } if (false === $this->trigger('before_insert', $this)) { return false;