Browse Source

视频是否点赞

lizhen_gitee 9 months ago
parent
commit
30c72f4306
1 changed files with 24 additions and 0 deletions
  1. 24 0
      application/api/controller/Video.php

+ 24 - 0
application/api/controller/Video.php

@@ -33,6 +33,22 @@ class Video extends Api
         $list = Db::name('video')->where($where)->order('weigh desc')->autopage()->select();
         $list = list_domain_image($list,['video_file','video_image']);
 
+        if(!empty($list)){
+            if($this->auth->isLogin()){
+                $vidoe_ids = Db::name('video_good')->where('user_id',$this->auth->id)->column('video_id');
+            }else{
+                $vidoe_ids = [];
+            }
+
+            foreach($list as $key => &$val){
+                $val['is_good'] = 0;
+
+                if(in_array($val['id'],$vidoe_ids)){
+                    $val['is_good'] = 1;
+                }
+            }
+        }
+
         $this->success('success',$list);
     }
 
@@ -43,6 +59,14 @@ class Video extends Api
 
         $info = Db::name('video')->where('id',$id)->find();
         $info = info_domain_image($info,['video_file','video_image']);
+        $info['is_good'] = 0;
+
+        if($this->auth->isLogin()){
+            $is_good = Db::name('video_good')->where('user_id',$this->auth->id)->where('video_id',$id)->find();
+            if($is_good){
+                $info['is_good'] = 1;
+            }
+        }
 
         $this->success('success',$info);
     }