评论数量,
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\model\Post;
|
||||
use app\common\model\PostComment;
|
||||
use app\common\model\PostFavorite;
|
||||
use app\common\model\PostLike;
|
||||
@@ -88,7 +89,32 @@ class PostController extends BaseController
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评论,点赞,收藏数量
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @param int|string $id 资源 ID
|
||||
* @return mixed 返回资源详情数据
|
||||
*/
|
||||
public function interaction(Request $request)
|
||||
{
|
||||
try {
|
||||
$param = $request->all();
|
||||
$data = Post::where('id', $param['id'])->select(['like','favorite','comment'])->first();
|
||||
|
||||
$where = [
|
||||
'post_id' => $data['id'],
|
||||
'user_id' => $request->user->uid
|
||||
];
|
||||
$data['is_like'] = PostLike::where($where)->count();
|
||||
$data['is_favorite'] = PostFavorite::where($where)->count();
|
||||
$data['is_comment'] = PostComment::where($where)->count();
|
||||
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage().$e->getFile().$e->getLine());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情
|
||||
@@ -104,6 +130,16 @@ class PostController extends BaseController
|
||||
$data = $this->transformData($raw, method_exists($this, 'showFormat')
|
||||
? [$this, 'showFormat']
|
||||
: null);
|
||||
|
||||
|
||||
$where = [
|
||||
'post_id' => $data['id'],
|
||||
'user_id' => $request->user->uid
|
||||
];
|
||||
$data['is_like'] = PostLike::where($where)->count();
|
||||
$data['is_favorite'] = PostFavorite::where($where)->count();
|
||||
$data['is_comment'] = PostComment::where($where)->count();
|
||||
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage().$e->getFile().$e->getLine());
|
||||
|
||||
Reference in New Issue
Block a user