rabin 7 years ago
parent
commit
021b6a9b41
6 changed files with 41 additions and 7 deletions
  1. 1 0
      comment/src/Review.php
  2. 8 1
      comment/src/Vote.php
  3. 20 0
      content/lib/Base.php
  4. 2 0
      content/v1/Course.php
  5. 5 3
      content/v1/Meeting.php
  6. 5 3
      content/v1/News.php

+ 1 - 0
comment/src/Review.php

@@ -24,6 +24,7 @@ class Review extends Base
             foreach ($data as $k => $v) {
                 $v['cdate'] = date('Y-m-d H:i', $v['cdate']);
                 $v['user'] = Dever::load('passport/user-one', $v['uid']);
+                $v['vote'] = $this->vote(4, $v['id']);
                 $this->data['review'][$k] = $this->handlePic($v);
             }
         }

+ 8 - 1
comment/src/Vote.php

@@ -23,11 +23,18 @@ class Vote extends Base
         $data = Dever::load('comment/vote-one', array('option_info_id' => $this->data['info']['id'], 'option_source_table' => $source_table, 'option_source_id' => $source_id, 'option_uid' => $uid));
 
         if ($data) {
-            Dever::alert('已赞过');
+            if ($source_table == 4) {
+                Dever::alert('已赞过');
+            } else {
+                $id = $data['id'];
+                Dever::load('comment/vote-delete', $id);
+            }
+            /*
             $id = $data['id'];
             $update['set_cdate'] = time();
             $update['where_id'] = $id;
             Dever::load('comment/vote-update', $update);
+            */
         } else {
             $insert['add_source_table'] = $source_table;
             $insert['add_source_id'] = $source_id;

+ 20 - 0
content/lib/Base.php

@@ -178,4 +178,24 @@ class Base
 
         //Dever::db($table)->addReview($source_id);
     }
+
+    /**
+     * vote
+     *
+     * @return mixed
+     */
+    public function vote($type, $id)
+    {
+        $state = 2;
+        $uid = Dever::input('uid');
+        if ($uid > 0) {
+            $data = Dever::load('comment/vote-one', array('option_info_id' => $this->data['info']['id'], 'option_source_table' => $type, 'option_source_id' => $id, 'option_uid' => $uid));
+
+            if ($data) {
+                $state = 1;
+            }
+        }
+        
+        return $state;
+    }
 }

+ 2 - 0
content/v1/Course.php

@@ -141,6 +141,8 @@ class Course extends Base
             Dever::alert('错误的课程id');
         }
 
+        $this->data['vote'] = $this->vote(2, $id);
+
         return $this->data;
     }
 }

+ 5 - 3
content/v1/Meeting.php

@@ -207,10 +207,10 @@ class Meeting extends Base
         $id = Dever::input('id');
 
         if ($id > 0) {
-            $meeting = Dever::load('content/meeting-one', $id);
+            $this->data['meeting'] = Dever::load('content/meeting-one', $id);
 
-            if ($meeting) {
-                $this->data['meeting'] = $this->one($meeting);
+            if ($this->data['meeting']) {
+                $this->data['meeting'] = $this->one($this->data['meeting']);
                 # 增加阅读量
                 Dever::load('content/meeting-addView', $id);
             } else {
@@ -220,6 +220,8 @@ class Meeting extends Base
             Dever::alert('错误的会议id');
         }
 
+        $this->data['vote'] = $this->vote(3, $id);
+
         return $this->data;
     }
 }

+ 5 - 3
content/v1/News.php

@@ -204,10 +204,10 @@ class News extends Base
         $id = Dever::input('id');
 
         if ($id > 0) {
-            $news = Dever::load('content/news-one', $id);
+            $this->data['news'] = Dever::load('content/news-one', $id);
 
-            if ($news) {
-                $this->data['news'] = $this->one($news, 2);
+            if ($this->data['news']) {
+                $this->data['news'] = $this->one($this->data['news'], 2);
                 # 增加阅读量
                 Dever::load('content/news-addView', $id);
             } else {
@@ -217,6 +217,8 @@ class News extends Base
             Dever::alert('错误的资讯id');
         }
 
+        $this->data['vote'] = $this->vote(1, $id);
+
         return $this->data;
     }
 }