mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-03-04 00:24:29 +08:00
增加访问记录功能
This commit is contained in:
@@ -23,6 +23,9 @@ class Post extends Base
|
||||
use SoftDelete;
|
||||
//
|
||||
|
||||
|
||||
public const CACHE_KEY_HITS = 'cache_hits_';
|
||||
|
||||
public static $autoClearCache = [
|
||||
[
|
||||
'name' => 'top_post'
|
||||
@@ -184,7 +187,7 @@ class Post extends Base
|
||||
public function getPosterAttr($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
$value = '/static/images/avatar.jpeg';
|
||||
$value = '/static/images/avatar.png';
|
||||
}
|
||||
|
||||
return get_source_link($value);
|
||||
@@ -233,4 +236,31 @@ class Post extends Base
|
||||
}
|
||||
return $end_content;
|
||||
}
|
||||
|
||||
public function getHitsTitleAttr()
|
||||
{
|
||||
$cache_key = static::CACHE_KEY_HITS.$this->getAttr('id');
|
||||
|
||||
$value = Cache::get($cache_key);
|
||||
|
||||
if(!is_null($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$value = $this->getData('hits');
|
||||
|
||||
Cache::set($cache_key, $value, 600);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function setHitsAttr($value)
|
||||
{
|
||||
$cache_key = static::CACHE_KEY_HITS.$this->getAttr('id');
|
||||
|
||||
$this->getAttr('hits_title');
|
||||
Cache::inc($cache_key);
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user