|
@@ -132,6 +132,66 @@ class PostRepository
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 评论&回复
|
|
|
+ */
|
|
|
+ public function comment($request)
|
|
|
+ {
|
|
|
+ //验证小号
|
|
|
+
|
|
|
+ $post = $this->post->find($request['post_id']);
|
|
|
+ if(!$post){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '获取内容失败',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ $data = [
|
|
|
+ 'uid' => $request['uid'],
|
|
|
+ 'post_id' => $request['post_id'],
|
|
|
+ 'parent_id' => 0,
|
|
|
+ 'username' => '暂无',
|
|
|
+ 'avatar' => '暂无',
|
|
|
+ 'content' => $request['content'],
|
|
|
+ 'is_delete' => 0,
|
|
|
+ ];
|
|
|
+ if(isset($request['parent_id']) && $request['parent_id'] != 0){
|
|
|
+ $comment = $this->postComment->find($request['parent_id']);
|
|
|
+ if(!$comment){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '获取评论信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ if($comment->parent_id){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '只能回复评论',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ $data['parent_id'] = $request['parent_id'];
|
|
|
+ }
|
|
|
+ DB::beginTransaction();
|
|
|
+ try{
|
|
|
+ $this->postComment->create($data);
|
|
|
+ $post->data->comment_count += 1;
|
|
|
+ $post->data->comment_real_count += 1;
|
|
|
+ $post->data->save();
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ return Response::create();
|
|
|
+
|
|
|
+ }catch (QueryException $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ Log::debug('评论内容:'.$request['post_id'].$exception->getMessage());
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '评论失败,请重试',
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 内容列表
|
|
|
*/
|
|
@@ -283,6 +343,45 @@ class PostRepository
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 删除评论
|
|
|
+ */
|
|
|
+ public function commentDelete($request)
|
|
|
+ {
|
|
|
+ $comment = $this->postComment->find($request['id']);
|
|
|
+ if(!$comment){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '获取评论信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if($comment->is_delete == 1){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '该评论已经删除',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try{
|
|
|
+ $comment->is_delete = 1;
|
|
|
+ $comment->save();
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ return Response::create();
|
|
|
+
|
|
|
+ }catch (QueryException $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ Log::debug('删除评论:'.$request['id'].$exception->getMessage());
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '操作失败,请重试',
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 隐藏内容
|
|
|
*/
|