|
@@ -28,6 +28,7 @@ use Illuminate\Support\Facades\Redis;
|
|
|
class CircleMessageRepository
|
|
|
{
|
|
|
use UserTrait;
|
|
|
+
|
|
|
public function __construct(InterestCircle $interestCircle,
|
|
|
InterestCircleMessage $interestCircleMessage,
|
|
|
InterestCircleMessageImg $interestCircleMessageImg,
|
|
@@ -44,6 +45,16 @@ class CircleMessageRepository
|
|
|
$this->detectionService = $detectionService;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询单个提问
|
|
|
+ * @param $id
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function detail($id)
|
|
|
+ {
|
|
|
+ return $this->interestCircleMessage->find($id);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 提问列表
|
|
|
*/
|
|
@@ -142,7 +153,7 @@ class CircleMessageRepository
|
|
|
}
|
|
|
$this->interestCircleMessageImg->insert($imgData);
|
|
|
}
|
|
|
- $this->interestCircle->where('id',$request['circle_id'])->increment('message_count');
|
|
|
+ $this->interestCircle->where('id', $request['circle_id'])->increment('message_count');
|
|
|
DB::commit();
|
|
|
Log::info('message_create:' . $message->id . ',post_author:' . $message->uid . ',author_ip:' . getClientIp());
|
|
|
return jsonSuccess();
|
|
@@ -152,4 +163,127 @@ class CircleMessageRepository
|
|
|
return jsonError('发布提问失败,请重试');
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 评论&回复
|
|
|
+ * @param $request
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function createComment($request)
|
|
|
+ {
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
+// $userInfo['sns_status']=1;
|
|
|
+// $userInfo['uid']=268;
|
|
|
+// $userInfo['username']='测试用户';
|
|
|
+// $userInfo['avatar']='';
|
|
|
+ if (empty($userInfo)) {
|
|
|
+ return jsonError('获取用户信息失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$userInfo['sns_status']) {
|
|
|
+ return jsonError('您已被禁言');
|
|
|
+ }
|
|
|
+ $isBlack = $this->interestCircleUser->where('circle_id', $request['circle_id'])
|
|
|
+ ->where('uid', $userInfo['uid'])
|
|
|
+ ->where('is_black', 1)->exists();
|
|
|
+ if ($isBlack) {
|
|
|
+ return jsonError('当前状态无法提问,请联系管理员');
|
|
|
+ }
|
|
|
+ $oneHourTime = Carbon::now()->addHours(-1)->toDateTimeString();
|
|
|
+ $oneHourCommentCount = $this->interestCircleMessageComment->where('uid', $userInfo['uid'])->where('created_at', '>', $oneHourTime)->count();
|
|
|
+ if ($oneHourCommentCount > 59) {
|
|
|
+ return jsonError('回复了这么多,休息休息,喝口水吧!');
|
|
|
+ }
|
|
|
+
|
|
|
+ $detectionTextResult = $this->detectionService->checkText($request['content']);
|
|
|
+ if ($detectionTextResult['code'] < 0) {
|
|
|
+ return jsonError('内容违规,请修正哦');
|
|
|
+ }
|
|
|
+
|
|
|
+ $post = $this->interestCircleMessage->find($request['msg_id']);
|
|
|
+ if (!$post) {
|
|
|
+ return jsonError('获取提问信息失败');
|
|
|
+ }
|
|
|
+ $data = [
|
|
|
+ 'uid' => $userInfo['uid'],
|
|
|
+ 'msg_id' => $request['msg_id'],
|
|
|
+ 'parent_id' => 0,
|
|
|
+ 'username' => $userInfo['username'],
|
|
|
+ 'reply_uid' => 0,
|
|
|
+ 'reply_username' => '',
|
|
|
+ 'avatar' => $userInfo['avatar'] ?? '',
|
|
|
+ 'content' => $request['content'],
|
|
|
+ 'is_delete' => 0,
|
|
|
+ ];
|
|
|
+ if (isset($request['parent_id']) && $request['parent_id'] != 0) {
|
|
|
+ $comment = $this->interestCircleMessageComment->find($request['parent_id']);
|
|
|
+ if (!$comment || $comment->msg_id != $post->id) {
|
|
|
+ return jsonError('获取评论信息失败');
|
|
|
+ }
|
|
|
+ if ($comment->parent_id) {
|
|
|
+ return jsonError('只能回复评论');
|
|
|
+ }
|
|
|
+ if ($comment->is_delete) {
|
|
|
+ return jsonError('不能回复已删除评论');
|
|
|
+ }
|
|
|
+ $data['parent_id'] = $request['parent_id'];
|
|
|
+
|
|
|
+ if (isset($request['reply_uid']) && isset($request['reply_username'])) {
|
|
|
+ $data['reply_uid'] = $request['reply_uid'];
|
|
|
+ $data['reply_username'] = $request['reply_username'];
|
|
|
+ } else {
|
|
|
+ $data['reply_uid'] = 0;
|
|
|
+ $data['reply_username'] = '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ $newComment = $this->interestCircleMessageComment->create($data);
|
|
|
+
|
|
|
+ if ($newComment->parent_id) {
|
|
|
+ $this->interestCircleMessageComment->where('id', $newComment->parent_id)->increment('reply_count');
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ if ($newComment->parent_id) {
|
|
|
+ Redis::DEL('circle_message_new_reply_' . $newComment->parent_id);
|
|
|
+ } else {
|
|
|
+ Redis::DEL('circle_message_new_comment_' . $newComment->post_id);
|
|
|
+ }
|
|
|
+ return jsonSuccess(['id' => $newComment->id], '评论成功');
|
|
|
+
|
|
|
+ } catch (QueryException $exception) {
|
|
|
+ DB::rollBack();
|
|
|
+ Log::debug('评论内容失败:' . $exception->getMessage());
|
|
|
+ return jsonError('评论内容失败,请重试');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 评论列表
|
|
|
+ */
|
|
|
+ public function commentList($request)
|
|
|
+ {
|
|
|
+ $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
+
|
|
|
+ return $this->interestCircleMessageComment
|
|
|
+ ->where('msg_id', $request['msg_id'])
|
|
|
+ ->where('parent_id', 0)
|
|
|
+ ->orderBy('id', 'desc')
|
|
|
+ ->paginate($perPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提问评论数
|
|
|
+ */
|
|
|
+ public function getCommentCount($id)
|
|
|
+ {
|
|
|
+ $commentCount = 0;
|
|
|
+ $post = $this->interestCircleMessage->find($id);
|
|
|
+ if ($post) {
|
|
|
+ $commentCount = $this->interestCircleMessageComment->where('msg_id', $id)->count();
|
|
|
+ }
|
|
|
+ return $commentCount;
|
|
|
+ }
|
|
|
}
|