优化IP显示

This commit is contained in:
2023-06-28 11:23:31 +08:00
parent 95d80fe568
commit b106f99c91

View File

@@ -1,9 +1,10 @@
<?php <?php
declare (strict_types=1); declare(strict_types=1);
namespace app\model; namespace app\model;
use think\facade\Request;
use think\Model; use think\Model;
/** /**
@@ -17,7 +18,7 @@ class PostVisit extends Model
{ {
$value = $this->getAttr('avatar'); $value = $this->getAttr('avatar');
if(empty($value)) { if (empty($value)) {
$value = '/static/images/avatar.png'; $value = '/static/images/avatar.png';
} }
@@ -28,8 +29,16 @@ class PostVisit extends Model
{ {
$value = $this->getAttr('nickname'); $value = $this->getAttr('nickname');
if(empty($value)) { if (empty($value)) {
$value = 'IP用户:'.$this->getAttr('ip'); $current_ip = Request::ip();
$ip = $this->getAttr('ip');
if ($current_ip == $ip) {
$value = '您的IP:' . $ip;
} else {
$value = 'IP用户:' . $ip;
}
} }
return $value; return $value;