mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-03-04 00:24:29 +08:00
增加访问记录功能
This commit is contained in:
@@ -15,7 +15,7 @@ class Admin extends Model
|
||||
{
|
||||
|
||||
if(empty($value)){
|
||||
return '/static/images/avatar.jpeg';
|
||||
return '/static/images/avatar.png';
|
||||
}
|
||||
|
||||
return \get_source_link($value);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
44
app/model/PostVisit.php
Normal file
44
app/model/PostVisit.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class PostVisit extends Model
|
||||
{
|
||||
//
|
||||
|
||||
public function getAvatarSrcAttr()
|
||||
{
|
||||
$value = $this->getAttr('avatar');
|
||||
|
||||
if(empty($value)) {
|
||||
$value = '/static/images/avatar.png';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getNicknameTitleAttr()
|
||||
{
|
||||
$value = $this->getAttr('nickname');
|
||||
|
||||
if(empty($value)) {
|
||||
$value = 'IP用户:'.$this->getAttr('ip');
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getCreateTimeTitleAttr()
|
||||
{
|
||||
$value = $this->getData('create_time');
|
||||
|
||||
return show_time_ago($value);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ class User extends Model
|
||||
public function getAvatarAttr($value)
|
||||
{
|
||||
if(empty($value)){
|
||||
return '/static/images/avatar.jpeg';
|
||||
return '/static/images/avatar.png';
|
||||
}
|
||||
|
||||
return \get_source_link($value);
|
||||
|
||||
Reference in New Issue
Block a user