|
@@ -9,6 +9,7 @@
|
|
|
|
|
|
namespace App\Repositories\Post;
|
|
|
|
|
|
+use App\Models\Behavior;
|
|
|
use App\Models\CategoryTopic;
|
|
|
use App\Models\Post;
|
|
|
use App\Models\PostComment;
|
|
@@ -42,6 +43,7 @@ class PostRepository
|
|
|
PostImgs $postImgs,
|
|
|
PostLog $postLog,
|
|
|
RabbitMqUtil $rabbitMqUtil,
|
|
|
+ Behavior $behavior,
|
|
|
CategoryTopic $categoryTopic,
|
|
|
PostStatistics $postStatistics,
|
|
|
Topic $topic)
|
|
@@ -52,6 +54,7 @@ class PostRepository
|
|
|
$this->postImgs = $postImgs;
|
|
|
$this->postLog = $postLog;
|
|
|
$this->rabbitMqUtil = $rabbitMqUtil;
|
|
|
+ $this->behavior = $behavior;
|
|
|
$this->categoryTopic = $categoryTopic;
|
|
|
$this->topic = $topic;
|
|
|
$this->postStatistics = $postStatistics;
|
|
@@ -62,15 +65,16 @@ class PostRepository
|
|
|
*/
|
|
|
public function create($request)
|
|
|
{
|
|
|
+
|
|
|
//验证小号
|
|
|
- //todo 小号
|
|
|
-// $userInfo = $this->getUserInfo($request['uid']);
|
|
|
-// if(!$userInfo || $userInfo['type'] != 1){
|
|
|
-// return Response::create([
|
|
|
-// 'message' => '所选小号信息有误',
|
|
|
-// 'status_code' => 500
|
|
|
-// ]);
|
|
|
-// }
|
|
|
+ $userInfo = $this->getUserInfo($request['uid']);
|
|
|
+ Log::debug('发布内容小号信息:'.json_encode($userInfo));
|
|
|
+ if(!$userInfo || $userInfo['type'] != 1){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '所选小号信息有误',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
//验证话题
|
|
|
$topicIdsArray = $this->topic->whereIn('id', explode(',', $request['topic_ids']))->pluck('id')->toArray();
|
|
|
$topicCount = count($topicIdsArray);
|
|
@@ -92,13 +96,14 @@ class PostRepository
|
|
|
}
|
|
|
|
|
|
$data = [
|
|
|
- 'uid' => $request['uid'],
|
|
|
- 'username' => '暂无',
|
|
|
- 'mobile' => '13720758488',
|
|
|
- 'avatar' => 'https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83ep3asJn8emiat1MnPdviaPNroWY3f65y5ezkTAk2qtibv7ea9Ht9R2ahxr9bicY1DIj5vN5FibpDOwXegg/132',
|
|
|
+ 'uid' => $userInfo['uid'],
|
|
|
+ 'username' => $userInfo['username'],
|
|
|
+ 'mobile' => $userInfo['mobile'],
|
|
|
+ 'avatar' => $userInfo['avatar']??'',
|
|
|
'type' => $request['type'],
|
|
|
'img' => $request['img'],
|
|
|
'video' => $request['video'] ?? '',
|
|
|
+ 'video_id' => $request['video_id'] ?? '',
|
|
|
'topic_ids' => $topicIds,
|
|
|
'title' => $request['title'] ?? '',
|
|
|
'content' => $request['content'],
|
|
@@ -150,6 +155,25 @@ class PostRepository
|
|
|
foreach ($topicIdsArray as $id) {
|
|
|
Redis::zincrby('topic.user_uid' . $request['uid'], 1, $id);
|
|
|
}
|
|
|
+
|
|
|
+ $virus = $this->behavior->where('behavior_identification', 'publish')->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' => 'publish',
|
|
|
+ 'post_id' => $post->id,
|
|
|
+ 'post_desc' => $desc,
|
|
|
+ 'post_cover' => $post->img,
|
|
|
+ 'target_id' => $post->uid,
|
|
|
+ 'action_id' => $post->id,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
return Response::create();
|
|
|
|
|
|
} catch (QueryException $exception) {
|
|
@@ -178,9 +202,23 @@ class PostRepository
|
|
|
$uid = $token['user']->id;
|
|
|
$username = $token['user']->username;
|
|
|
//验证小号数量
|
|
|
-
|
|
|
+ $number = max([
|
|
|
+ $request['add_pv'],
|
|
|
+ $request['add_praise_count'],
|
|
|
+ $request['add_collect_count'],
|
|
|
+ $request['add_share_count']
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $members = $this->getSystemMember($number);
|
|
|
+ if(!$members || $members['status_code'] != 200){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => $members['message'],
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ $post = $this->post->find($request['post_id']);
|
|
|
$postData = $this->postData->where('post_id', $request['post_id'])->first();
|
|
|
- if (!$postData) {
|
|
|
+ if (!$postData || !$post) {
|
|
|
return Response::create([
|
|
|
'message' => '获取内容失败',
|
|
|
'status_code' => 500
|
|
@@ -227,6 +265,62 @@ class PostRepository
|
|
|
]);
|
|
|
|
|
|
DB::commit();
|
|
|
+
|
|
|
+ $virus = $this->behavior
|
|
|
+ ->whereIn('behavior_identification', ['read', 'forward', 'like', 'collect'])
|
|
|
+ ->pluck('virus_behavior_id', 'behavior_identification');
|
|
|
+ if($post->title){
|
|
|
+ $desc = $post->title;
|
|
|
+ }else{
|
|
|
+ $desc = subtext(strip_tags($post->content), 20);
|
|
|
+ }
|
|
|
+ $data = [
|
|
|
+ 'behavior_value' => 1,
|
|
|
+ 'post_id' => $post->id,
|
|
|
+ 'post_author_uid' => $post->uid,
|
|
|
+ 'post_desc' => $desc,
|
|
|
+ 'post_cover' => $post->img,
|
|
|
+ 'action_id' => $post->id,
|
|
|
+ ];
|
|
|
+
|
|
|
+ foreach($members['data'] as $key => $member){
|
|
|
+ if(isset($virus['read']) && $request['add_pv'] > $key){
|
|
|
+ $newData = array_merge($data, [
|
|
|
+ 'behavior_id' => $virus['read'],
|
|
|
+ 'behavior_flag' => 'read',
|
|
|
+ 'target_id' => $member['uid'],
|
|
|
+ ]);
|
|
|
+ $this->rabbitMqUtil->push('virus_add', $newData);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(isset($virus['like']) && $request['add_praise_count'] > $key){
|
|
|
+ $newData = array_merge($data, [
|
|
|
+ 'behavior_id' => $virus['like'],
|
|
|
+ 'behavior_flag' => 'like',
|
|
|
+ 'target_id' => $member['uid'],
|
|
|
+ ]);
|
|
|
+ $this->rabbitMqUtil->push('virus_add', $newData);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(isset($virus['collect']) && $request['add_collect_count'] > $key){
|
|
|
+ $newData = array_merge($data, [
|
|
|
+ 'behavior_id' => $virus['collect'],
|
|
|
+ 'behavior_flag' => 'collect',
|
|
|
+ 'target_id' => $member['uid'],
|
|
|
+ ]);
|
|
|
+ $this->rabbitMqUtil->push('virus_add', $newData);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(isset($virus['forward']) && $request['add_share_count'] > $key){
|
|
|
+ $newData = array_merge($data, [
|
|
|
+ 'behavior_id' => $virus['forward'],
|
|
|
+ 'behavior_flag' => 'forward',
|
|
|
+ 'target_id' => $member['uid'],
|
|
|
+ ]);
|
|
|
+ $this->rabbitMqUtil->push('virus_add', $newData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return Response::create();
|
|
|
|
|
|
} catch (QueryException $exception) {
|
|
@@ -269,10 +363,13 @@ class PostRepository
|
|
|
'username' => $userInfo['username'],
|
|
|
'reply_uid' => 0,
|
|
|
'reply_username' => '',
|
|
|
- 'avatar' => $userInfo['avatar'],
|
|
|
+ 'avatar' => $userInfo['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) {
|
|
@@ -290,37 +387,44 @@ class PostRepository
|
|
|
$data['parent_id'] = $request['parent_id'];
|
|
|
$data['reply_uid'] = $comment->uid;
|
|
|
$data['reply_username'] = $comment->username;
|
|
|
- $this->rabbitMqUtil->push('add_message', [
|
|
|
- 'uid' => $comment->uid,
|
|
|
- 'message_show_type' => 'post_reply_main',
|
|
|
- 'param' => [
|
|
|
- 'uid' => $userInfo['uid'],
|
|
|
- 'username' => $userInfo['username'],
|
|
|
- 'post_id' => $post->id,
|
|
|
- 'cover' => $post->img,
|
|
|
- 'content' => subtext($request['content'], 20),
|
|
|
- ]
|
|
|
- ]);
|
|
|
- } else {
|
|
|
- $this->rabbitMqUtil->push('add_message', [
|
|
|
- 'uid' => $post->uid,
|
|
|
- 'message_show_type' => 'post_comment',
|
|
|
- 'param' => [
|
|
|
- 'uid' => $userInfo['uid'],
|
|
|
- 'username' => $userInfo['username'],
|
|
|
- 'post_id' => $post->id,
|
|
|
- 'cover' => $post->img,
|
|
|
- 'content' => subtext($request['content'], 20),
|
|
|
- ]
|
|
|
- ]);
|
|
|
+ $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' => $comment->id,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
return Response::create();
|
|
|
|
|
|
} catch (QueryException $exception) {
|