mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-07-07 12:42:49 +08:00
fix(api): 修复创建文章500错误和更新文章数据覆盖问题
This commit is contained in:
@@ -269,7 +269,13 @@ class Post extends Base
|
||||
|
||||
public function getHitsTitleAttr()
|
||||
{
|
||||
$cache_key = static::CACHE_KEY_HITS . $this->getAttr('id');
|
||||
// 新建对象时直接返回 0
|
||||
$id = $this->getData('id');
|
||||
if (empty($id)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$cache_key = static::CACHE_KEY_HITS . $id;
|
||||
|
||||
$value = Cache::get($cache_key);
|
||||
|
||||
@@ -277,7 +283,8 @@ class Post extends Base
|
||||
return $value;
|
||||
}
|
||||
|
||||
$value = $this->getData('hits');
|
||||
// 安全获取:hits 可能尚未存在于 data 中
|
||||
$value = array_key_exists('hits', $this->data) ? $this->data['hits'] : 0;
|
||||
|
||||
Cache::set($cache_key, $value, 600);
|
||||
|
||||
@@ -286,9 +293,14 @@ class Post extends Base
|
||||
|
||||
public function setHitsAttr($value)
|
||||
{
|
||||
$cache_key = static::CACHE_KEY_HITS . $this->getAttr('id');
|
||||
// 新建对象(无 id)时,直接返回值,跳过缓存操作
|
||||
$id = $this->getData('id');
|
||||
if (empty($id)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$cache_key = static::CACHE_KEY_HITS . $id;
|
||||
|
||||
$this->getAttr('hits_title');
|
||||
Cache::inc($cache_key);
|
||||
|
||||
return $value;
|
||||
|
||||
Reference in New Issue
Block a user