huwhois 2 år sedan
förälder
incheckning
e0bd24ee3c

+ 5 - 0
app/common/model/ArticleBrowerHistory.php

@@ -19,4 +19,9 @@ class ArticleBrowerHistory extends Model
     ];
 
     protected $autoWriteTimestamp = false;
+
+    public static function getByIpAid($ip, $aid)
+    {
+        return self::where('ip', $ip)->where('aid', $aid)->find();
+    }
 }

+ 23 - 2
app/index/controller/Article.php

@@ -16,6 +16,7 @@ use think\exception\HttpException;
 
 use app\common\model\Category as CategoryModel;
 use app\common\model\Article as ArticleModel;
+use app\common\model\ArticleBrowerHistory;
 use app\common\model\ArticleTags as ArticleTagsModel;
 use app\common\model\ArticleDolikeLog;
 use app\common\model\Tag;
@@ -73,9 +74,29 @@ class Article extends Base
             throw new HttpException(404, '页面不存在');
         }
 
-        $data->hits += 1;
+        $ip = $this->request->ip();
+        $time = time();
+        $abh = ArticleBrowerHistory::getByIpAid($ip, $id);
+
+        if (!$abh) {
+            $data->hits += 1;
+            
+            $data->isAutoWriteTimestamp(false)->save();
+
+            ArticleBrowerHistory::create([
+                'ip' => $ip,
+                'aid'=> $id,
+                'create_time' => $time
+            ]);
+        } else {
+            $createTime = $abh->create_time;
 
-        $data->isAutoWriteTimestamp(false)->save();
+            if ($createTime + 24*3600 < $time) {
+                $data->hits += 1;
+            
+                $data->isAutoWriteTimestamp(false)->save();
+            }
+        }
 
         $prev_next = ArticleModel::getNextPrev($id, $data->cid);
 

+ 1 - 1
public/static/index/css/index.css

@@ -3,7 +3,7 @@
 * { margin: 0; padding: 0 }
 body { font: 15px "Microsoft YaHei", Arial, Helvetica, sans-serif; color: #555; background: #efefef; line-height: 1.5; }
 img { border: 0; display: block }
-/* ul, li { list-style: none; } */
+ul li { list-style: none; }
 a { text-decoration: none; color: #555 }
 a:hover { text-decoration: none; color: #000; }
 .clear { clear: both; }