From eab8cee8a8b6a616a4cdb7a58c4a560c97606b01 Mon Sep 17 00:00:00 2001 From: augushong Date: Fri, 1 May 2026 16:19:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(api):=20=E4=BF=AE=E5=A4=8DgetData(id)?= =?UTF-8?q?=E6=96=B0=E5=BB=BA=E5=AF=B9=E8=B1=A1=E6=97=B6=E6=8A=9B=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=EF=BC=8C=E6=94=B9=E7=94=A8isset=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/model/Post.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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);