瀏覽代碼

virus评论

wzq 5 年之前
父節點
當前提交
496af7710c
共有 2 個文件被更改,包括 61 次插入5 次删除
  1. 23 0
      app/Console/Commands/VirusAdd.php
  2. 38 5
      app/Repositories/Post/PostRepository.php

+ 23 - 0
app/Console/Commands/VirusAdd.php

@@ -141,8 +141,31 @@ class VirusAdd extends Command
                     'action_id' => (string) $data['action_id'],
                     'extra' => [],
                 ];
+            }elseif($data['behavior_flag'] == 'comment'){
+                $json = [
+                    'sign' => $sign,
+                    'app_id' => config('customer.VIRUS_APP_ID'),
+                    'behavior_id' => $data['behavior_id'],
+                    'behavior_flag' => $data['behavior_flag'],
+                    'post_id' => $data['post_id'],
+                    'post_author_uid' => $data['post_author_uid'],
+                    'post_desc' => $data['post_desc'],
+                    'post_cover' => $data['post_cover'],
+                    'comment_id' => $data['comment_id'],
+                    'comment_content' => $data['comment_content'],
+                    'parent_comment_id' => $data['parent_comment_id'],
+                    'parent_comment_content' => $data['parent_comment_content'],
+                    'parent_comment_uid' => $data['parent_comment_uid'],
+                    'parent_comment_time' => $data['parent_comment_time'],
+                    'reply_uid' => $data['reply_uid'],
+                    'reply_username' => $data['reply_username'],
+                    'target_id' => (string) $data['target_id'],
+                    'action_id' => (string) $data['action_id'],
+                    'extra' => [],
+                ];
             }else{
                 Log::debug('行为类型错误'.json_encode($data));
+                return false;
             }
 
             $response = $this->client->request('POST', 'v2/record/add', [

+ 38 - 5
app/Repositories/Post/PostRepository.php

@@ -169,7 +169,7 @@ class PostRepository
                     'post_cover' => $post->img,
                     'target_id' => $post->uid,
                     'action_id' => $post->id,
-            ]);
+                ]);
             }
 
             return Response::create();
@@ -270,7 +270,7 @@ class PostRepository
         //验证小号
         $userInfo = $this->getUserInfo($request['uid']);
         Log::debug('评论&回复小号' . json_encode($userInfo));
-        if (!$userInfo || $userInfo['type'] != 1) {
+        if (!$userInfo || !$userInfo['data'] || $userInfo['data']['type'] != 1) {
             return Response::create([
                 'message' => '所选小号信息有误',
                 'status_code' => 500
@@ -288,13 +288,16 @@ class PostRepository
             'uid' => $request['uid'],
             'post_id' => $request['post_id'],
             'parent_id' => 0,
-            'username' => $userInfo['username'],
+            'username' => $userInfo['data']['username'],
             'reply_uid' => 0,
             'reply_username' => '',
-            'avatar' => $userInfo['avatar'],
+            'avatar' => $userInfo['data']['avatar'],
             'content' => $request['content'],
             'is_delete' => 0,
         ];
+        $parentCommentContent = '';
+        $parentCommentUid = 0;
+        $parentCommentTime = '';
         if (isset($request['parent_id']) && $request['parent_id'] != 0) {
             $comment = $this->postComment->find($request['parent_id']);
             if (!$comment) {
@@ -312,14 +315,44 @@ class PostRepository
             $data['parent_id'] = $request['parent_id'];
             $data['reply_uid'] = $comment->uid;
             $data['reply_username'] = $comment->username;
+            $parentCommentContent = $comment->content;
+            $parentCommentUid = $comment->uid;
+            $parentCommentTime = Carbon::parse($comment->created_at)->toDateTimeString();
         }
         DB::beginTransaction();
         try {
-            $this->postComment->create($data);
+            $comment = $this->postComment->create($data);
             $post->data->comment_count += 1;
             $post->data->save();
 
             DB::commit();
+
+            $virus = $this->behavior->where('behavior_identification', 'comment')->first();
+            if($virus){
+                if($post->title){
+                    $desc = $post->title;
+                }else{
+                    $desc = subtext(strip_tags($post->content), 20);
+                }
+                $this->rabbitMqUtil->push('virus_add', [
+                    'behavior_id' => $virus->virus_behavior_id,
+                    'behavior_flag' => 'comment',
+                    'post_id' => $post->id,
+                    'post_author_uid' => $post->uid,
+                    'post_desc' => $desc,
+                    'post_cover' => $post->img,
+                    'comment_id' => $comment->id,
+                    'comment_content' => $comment->content,
+                    'parent_comment_id' => $comment->parent_id,
+                    'parent_comment_content' => $parentCommentContent,
+                    'parent_comment_uid' => $parentCommentUid,
+                    'parent_comment_time' => $parentCommentTime,
+                    'reply_uid' => $comment->reply_uid,
+                    'reply_username' => $comment->reply_username,
+                    'target_id' => $comment->uid,
+                    'action_id' => $post->id,
+                ]);
+            }
             return Response::create();
 
         } catch (QueryException $exception) {