dever 6 роки тому
батько
коміт
d68ab8edce
1 змінених файлів з 24 додано та 8 видалено
  1. 24 8
      act/lib/Subscribe.php

+ 24 - 8
act/lib/Subscribe.php

@@ -6,18 +6,30 @@ use Dever;
 
 class Subscribe
 {
+    private $key = 'use_sub_';
+
     # 获取小刊是否被人订阅
-    public function get($id, $uid, $type = 4)
+    public function get($id, $uid, $type = 4, $cache = false)
     {
-        $where['uid'] = $uid;
-        $where['type'] = $type;
-        $where['data_id'] = $id;
-        $where['state'] = 1;
-        $data = Dever::db('act/subscribe')->one($where);
-
-        if ($data) {
+        $key = $this->key . $uid . '_' . $id;
+        $data = Dever::cache($key);
+        if ($data == 1) {
             return 1;
         } else {
+            if (!$cache) {
+                $where['uid'] = $uid;
+                $where['type'] = $type;
+                $where['data_id'] = $id;
+                $where['state'] = 1;
+                $data = Dever::db('act/subscribe')->one($where);
+
+                if ($data) {
+                    Dever::cache($key, 1, 86400*300);
+                    return 1;
+                } else {
+                    return 2;
+                }
+            }
             return 2;
         }
     }
@@ -71,6 +83,10 @@ class Subscribe
         $where['type'] = $type;
         $table = 'act/subscribe';
         $info = Dever::db($table)->one($where);
+
+        $key = $this->key . $uid . '_' . $id;
+        Dever::cache($key, 1, 86400*300);
+
         if (!$info) {
             $where['source'] = $source;
             Dever::db($table)->insert($where);