rabin 7 years ago
parent
commit
42901ca042
4 changed files with 22 additions and 8 deletions
  1. 3 4
      comment/src/Review.php
  2. 1 3
      comment/src/Vote.php
  3. 4 1
      comment/src/Watch.php
  4. 14 0
      content/lib/Base.php

+ 3 - 4
comment/src/Review.php

@@ -49,7 +49,7 @@ class Review extends Base
         $uid = Dever::input('uid');
 
         $user = Dever::load('passport/user-one', $uid);
-        if ($user && $user['pic']) {
+        if ($user) {
             $data = Dever::load('comment/review-one', array('option_info_id' => $this->data['info']['id'], 'option_source_table' => $source_table, 'option_source_id' => $source_id, 'option_uid' => $uid, 'option_content' => $content));
 
             if ($data) {
@@ -67,9 +67,8 @@ class Review extends Base
 
                 $id = Dever::load('comment/review-insert', $insert);
 
-                # 增加原表数据 以后要添加crontab来定时矫正数据
-                $table = $this->type($source_table);
-                Dever::db('content/' . $table)->addReview($source_id);
+                $this->count($source_table, $source_id, 'comment/review', 'num_review');
+                
             }
             return $id;
         }

+ 1 - 3
comment/src/Vote.php

@@ -37,9 +37,7 @@ class Vote extends Base
 
             $id = Dever::load('comment/vote-insert', $insert);
 
-            # 增加原表数据 以后要添加crontab来定时矫正数据
-            $table = $this->type($source_table);
-            Dever::db($table)->addUp($source_id);
+            $this->count($source_table, $source_id, 'comment/vote', 'num_up');
         }
         return $id;
     }

+ 4 - 1
comment/src/Watch.php

@@ -33,8 +33,11 @@ class Watch extends Base
 
                 $id = Dever::load('comment/watch-insert', $insert);
 
+                $count = Dever::db('comment/watch')->total(array('option_info_id' => $this->data['info']['id'], 'option_course_id' => $course_id));
+                Dever::db('content/course')->update(array('set_num_watch' => $count, 'where_id' => $course_id));
+
                 # 增加原表数据 以后要添加crontab来定时矫正数据
-                Dever::db('content/course')->addWatch($course_id);
+                //Dever::db('content/course')->addWatch($course_id);
             }
         }
         

+ 14 - 0
content/lib/Base.php

@@ -164,4 +164,18 @@ class Base
         );
         return $config[$type];
     }
+
+    /**
+     * 统计数据
+     *
+     * @return mixed
+     */
+    public function count($source_table, $source_id, $type, $set)
+    {
+        $table = $this->type($source_table);
+        $count = Dever::db($type)->total(array('option_info_id' => $this->data['info']['id'], 'option_source_table' => $source_table, 'option_source_id' => $source_id));
+        $id = Dever::db($table)->update(array('set_' . $set => $count, 'where_id' => $source_id));
+
+        //Dever::db($table)->addReview($source_id);
+    }
 }