diff --git a/app/model/Post.php b/app/model/Post.php index 9ef5e6c..0380a23 100644 --- a/app/model/Post.php +++ b/app/model/Post.php @@ -270,11 +270,12 @@ class Post extends Base public function getHitsTitleAttr() { // 新建对象时直接返回 0 - $id = $this->getData('id'); - if (empty($id)) { + if (!isset($this->data['id']) || empty($this->data['id'])) { return 0; } + $id = $this->data['id']; + $cache_key = static::CACHE_KEY_HITS . $id; $value = Cache::get($cache_key); @@ -294,11 +295,12 @@ class Post extends Base public function setHitsAttr($value) { // 新建对象(无 id)时,直接返回值,跳过缓存操作 - $id = $this->getData('id'); - if (empty($id)) { + if (!isset($this->data['id']) || empty($this->data['id'])) { return $value; } + $id = $this->data['id']; + $cache_key = static::CACHE_KEY_HITS . $id; Cache::inc($cache_key);