wesmiler 5 dni temu
rodzic
commit
0051396f4a

+ 1 - 0
app/Http/Controllers/Api/v1/SocialController.php

@@ -21,6 +21,7 @@ class SocialController extends webApp
     {
         $params =request()->post();
         $pageSize = request()->post('pageSize', 15);
+        $params['user_id'] = $this->userId;
         $datas = SocialService::make()->getDataList($params, $pageSize);
         return message(1010, true, $datas);
     }

+ 10 - 0
app/Models/PostModel.php

@@ -96,4 +96,14 @@ class PostModel extends BaseModel
         return $this->hasMany(PostRecordModel::class, 'source_id', 'id')
             ->where(['type'=>2,'status'=>1,'mark'=>1]);
     }
+
+    /**
+     * 是否点赞
+     * @return \Illuminate\Database\Eloquent\Relations\hasMany
+     */
+    public function isLike()
+    {
+        return $this->hasOne(PostRecordModel::class, 'source_id', 'id')
+            ->where(['type'=>2,'status'=>1,'mark'=>1]);
+    }
 }

+ 4 - 3
app/Services/Api/SocialService.php

@@ -108,6 +108,7 @@ class SocialService extends BaseService
         $where = ['a.mark' => 1];
         $status = isset($params['status'])? $params['status'] : 0;
         $type = isset($params['type'])? $params['type'] : 0;
+        $userId = isset($params['user_id'])? $params['user_id'] : 0;
 
         if($status>0){
             $where['a.status'] = $status;
@@ -118,8 +119,9 @@ class SocialService extends BaseService
         }
 
 
-
-        return $this->model->with(['user'])->from('posts as a')
+        return $this->model->with(['user','isLike'=>function($query) use($userId){
+               $query->where('user_id', $userId);
+            }])->from('posts as a')
             ->where($where)
             ->where(function ($query) use($params){
                 $keyword = isset($params['keyword'])? $params['keyword'] : '';
@@ -132,7 +134,6 @@ class SocialService extends BaseService
                 if($tag){
                     $query->where('a.tags','like',"%{$tag},%");
                 }
-
             });
     }