|
@@ -13,8 +13,10 @@ use App\Models\InterestCircle;
|
|
|
use App\Models\InterestCircleArticle;
|
|
|
use App\Models\InterestCircleMessage;
|
|
|
use App\Models\InterestCircleMessageComment;
|
|
|
+use App\Models\InterestCircleMessageImg;
|
|
|
use App\Models\InterestCircleUser;
|
|
|
use App\Models\Post;
|
|
|
+use App\Service\DetectionService;
|
|
|
use Illuminate\Database\QueryException;
|
|
|
use Dingo\Api\Http\Response;
|
|
|
use Illuminate\Support\Carbon;
|
|
@@ -27,12 +29,18 @@ class CircleMessageRepository
|
|
|
|
|
|
public function __construct(InterestCircle $interestCircle,
|
|
|
InterestCircleMessage $interestCircleMessage,
|
|
|
+ InterestCircleMessageImg $interestCircleMessageImg,
|
|
|
+ InterestCircleUser $interestCircleUser,
|
|
|
+ DetectionService $detectionService,
|
|
|
InterestCircleMessageComment $interestCircleMessageComment
|
|
|
)
|
|
|
{
|
|
|
$this->interestCircle = $interestCircle;
|
|
|
$this->interestCircleMessage = $interestCircleMessage;
|
|
|
+ $this->interestCircleMessageImg = $interestCircleMessageImg;
|
|
|
+ $this->interestCircleUser = $interestCircleUser;
|
|
|
$this->interestCircleMessageComment = $interestCircleMessageComment;
|
|
|
+ $this->detectionService = $detectionService;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -65,162 +73,80 @@ class CircleMessageRepository
|
|
|
if (!$userInfo['sns_status']) {
|
|
|
return jsonError('您已被禁言');
|
|
|
}
|
|
|
- $isValid = 0;
|
|
|
- if ($userInfo['strength']) {
|
|
|
- $isValid = 1;
|
|
|
+ $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();
|
|
|
- $oneHourPostCount = $this->post->where('uid', $userInfo['uid'])->where('created_at', '>', $oneHourTime)->count();
|
|
|
+ $oneHourPostCount = $this->interestCircleMessage->where('uid', $userInfo['uid'])->where('created_at', '>', $oneHourTime)->count();
|
|
|
if ($oneHourPostCount > 5) {
|
|
|
- return jsonError('创作欲望太强啦,休息一下,看看其他用户的内容吧!');
|
|
|
+ return jsonError('创作欲望太强啦,休息一下,看看其他用户的提问吧!');
|
|
|
}
|
|
|
|
|
|
- $detectionText = strip_tags($request['title']) . ',' . strip_tags($request['content']);
|
|
|
+ $detectionText = strip_tags($request['content']);
|
|
|
$detectionTextResult = $this->detectionService->checkText($detectionText);
|
|
|
if ($detectionTextResult['code'] < 0) {
|
|
|
return jsonError('内容违规,请修正哦');
|
|
|
}
|
|
|
-
|
|
|
- $topicIds = json_decode($request['topic_ids'], true);
|
|
|
- $topicCount = count($topicIds);
|
|
|
- if ($topicCount == 0 || $topicCount > 2) {
|
|
|
- return jsonError('所选话题必须1-2个');
|
|
|
- }
|
|
|
- //验证话题
|
|
|
- $hasTopicCount = $this->topic->whereIn('id', $topicIds)->count();
|
|
|
- if ($topicCount != $hasTopicCount) {
|
|
|
- Log::error('所选话题非法' . $request['topic_ids']);
|
|
|
- return jsonError('所选话题非法');
|
|
|
- }
|
|
|
$imgs = [];
|
|
|
- if ($request['type'] == 'image') {
|
|
|
+ if (isset($request['imgs']) && $request['imgs']) {
|
|
|
$imgs = json_decode($request['imgs'], true);
|
|
|
$imgCount = count($imgs);
|
|
|
- if ($imgCount == 0 || $imgCount > 9) {
|
|
|
- return jsonError('所传图集必须1-9个');
|
|
|
+ if ($imgCount > 3) {
|
|
|
+ return jsonError('最多上传3张图片');
|
|
|
}
|
|
|
}
|
|
|
- $allImg = array_merge($imgs, [$request['img']]);
|
|
|
- foreach ($allImg as &$img) {
|
|
|
- $img = $img . '&x-oss-process=image/resize,p_50/quality,Q_50';
|
|
|
- }
|
|
|
- $detectionImageResult = $this->detectionService->checkImg($allImg);
|
|
|
- if ($detectionImageResult['code'] < 0) {
|
|
|
- Log::debug('图片违规,请修正哦' . json_encode($detectionImageResult));
|
|
|
- return jsonError('图片违规,请修正哦');
|
|
|
- }
|
|
|
- $videoUrl = "";
|
|
|
- $videoId = "";
|
|
|
- if (isset($request['video']) && $request['video']) {
|
|
|
- $videoId = $request['video'];
|
|
|
- for ($i = 0; $i < 3; $i++) {
|
|
|
- $videoUrl = $this->aliYunVodService->getPlayUrlByVideoId($request['video']);
|
|
|
- Log::debug('video-url:' . $videoUrl);
|
|
|
- if ($videoUrl) {
|
|
|
- break;
|
|
|
- }
|
|
|
+ if ($imgs) {
|
|
|
+ $allImg = $imgs;
|
|
|
+ foreach ($allImg as &$img) {
|
|
|
+ $img = $img . '&x-oss-process=image/resize,p_50/quality,Q_50';
|
|
|
}
|
|
|
- if (empty($videoUrl)) {
|
|
|
- return jsonError('发布失败,请重试');
|
|
|
+ $detectionImageResult = $this->detectionService->checkImg($allImg);
|
|
|
+ if ($detectionImageResult['code'] < 0) {
|
|
|
+ Log::debug('图片违规,请修正哦' . json_encode($detectionImageResult));
|
|
|
+ return jsonError('图片违规,请修正哦');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $fresh = (Carbon::now()->timestamp) - (Carbon::parse("2019-05-01 00:00:00")->timestamp);
|
|
|
- $score = $fresh / 43200;
|
|
|
+ $fresh = (Carbon::now()->timestamp) - (Carbon::parse("2019-10-08 00:00:00")->timestamp);
|
|
|
+ $score = ($fresh / 43200) * 14;
|
|
|
$data = [
|
|
|
+ 'circle_id' => $request['circle_id'],
|
|
|
'uid' => $userInfo['uid'],
|
|
|
- 'username' => $userInfo['username'],
|
|
|
- 'mobile' => $userInfo['mobile'],
|
|
|
- 'avatar' => $userInfo['avatar'] ?? '',
|
|
|
- 'type' => $request['type'],
|
|
|
- 'img' => $request['img'],
|
|
|
- 'video' => $videoUrl,
|
|
|
- 'video_id' => $videoId,
|
|
|
- 'topic_ids' => implode(',', $topicIds),
|
|
|
- 'title' => isset($request['title']) ? $request['title'] : '',
|
|
|
'content' => $request['content'],
|
|
|
- 'location' => isset($request['location']) ? $request['location'] : '',
|
|
|
- 'is_suggest' => 0,
|
|
|
- 'is_hide' => 0,
|
|
|
+ 'good' => 0,
|
|
|
+ 'bad' => 0,
|
|
|
+ 'comment_count' => 0,
|
|
|
'weight' => $score
|
|
|
];
|
|
|
-
|
|
|
$date = date('Y-m-d H:i:s');
|
|
|
-
|
|
|
DB::beginTransaction();
|
|
|
try {
|
|
|
- $post = $this->post->create($data);
|
|
|
-
|
|
|
- $postData = $this->postData->create([
|
|
|
- 'post_id' => $post->id,
|
|
|
- 'pv' => 0,
|
|
|
- 'pv_real' => 0,
|
|
|
- 'dislike_count' => 0,
|
|
|
- 'praise_count' => 0,
|
|
|
- 'praise_real_count' => 0,
|
|
|
- 'share_count' => 0,
|
|
|
- 'share_real_count' => 0,
|
|
|
- 'comment_count' => 0,
|
|
|
- 'collect_count' => 0,
|
|
|
- 'collect_real_count' => 0,
|
|
|
- 'available_bean' => $this->availableBean(),
|
|
|
- 'will_collect_bean' => rand(100, 200),
|
|
|
- 'collect_bean' => 0
|
|
|
- ]);
|
|
|
-
|
|
|
+ $message = $this->interestCircleMessage->create($data);
|
|
|
if ($imgs) {
|
|
|
$imgData = [];
|
|
|
foreach ($imgs as $img) {
|
|
|
$imgData[] = [
|
|
|
- 'post_id' => $post->id,
|
|
|
- 'img' => $img,
|
|
|
+ 'msg_id' => $message->id,
|
|
|
+ 'circle_id' => $message->circle_id,
|
|
|
+ 'image' => $img,
|
|
|
'created_at' => $date,
|
|
|
'updated_at' => $date
|
|
|
];
|
|
|
}
|
|
|
- $this->postImgs->insert($imgData);
|
|
|
+ $this->interestCircleMessageImg->insert($imgData);
|
|
|
}
|
|
|
-
|
|
|
+ $this->interestCircle->where('id',$request['circle_id'])->increment('message_count');
|
|
|
DB::commit();
|
|
|
- Redis::zadd('post_trigger_type', $isValid, $post->id);
|
|
|
- foreach ($topicIds as $id) {
|
|
|
- Redis::zincrby('topic.user_uid' . $userInfo['uid'], 1, $id);
|
|
|
- Redis::zincrby('topic.just_use_count', 1, $id);
|
|
|
- }
|
|
|
- Redis::HSET('post_info_' . $post->id,
|
|
|
- 'id', $post->id,
|
|
|
- 'uid', $post->uid,
|
|
|
- 'type', $post->type,
|
|
|
- 'img', $post->img,
|
|
|
- 'imgs', json_encode($imgs),
|
|
|
- 'video', $post->video,
|
|
|
- 'topic_ids', $post->topic_ids,
|
|
|
- 'is_fine', $post->is_fine,
|
|
|
- 'title', $post->title,
|
|
|
- 'content', $post->content,
|
|
|
- 'location', $post->location,
|
|
|
- 'pv', $postData->pv,
|
|
|
- 'dislike_count', $postData->dislike_count,
|
|
|
- 'praise_count', $postData->praise_count,
|
|
|
- 'share_count', $postData->share_count,
|
|
|
- 'comment_count', $postData->comment_count,
|
|
|
- 'collect_count', $postData->collect_count,
|
|
|
- 'available_bean', $postData->available_bean,
|
|
|
- 'will_collect_bean', $postData->will_collect_bean,
|
|
|
- 'create_bean', $postData->create_bean,
|
|
|
- 'collect_bean', $postData->collect_bean,
|
|
|
- 'created_at', $post->created_at);
|
|
|
- Log::info('post_create:' . $post->id . ',post_author:' . $post->uid . ',author_ip:' . getClientIp());
|
|
|
- return jsonSuccess([
|
|
|
- 'post_id' => $post->id,
|
|
|
- 'h5url' => config('customer.share_post_h5url') . "?post_id={$post->id}&invite_code={$userInfo['invite_code']}",
|
|
|
- 'bean' => $postData->available_bean,
|
|
|
- ]);
|
|
|
-
|
|
|
+ Log::info('message_create:' . $message->id . ',post_author:' . $message->uid . ',author_ip:' . getClientIp());
|
|
|
+ return jsonSuccess();
|
|
|
} catch (QueryException $exception) {
|
|
|
DB::rollBack();
|
|
|
- Log::debug('发布内容失败:' . $exception->getMessage());
|
|
|
- return jsonError('发布内容失败,请重试');
|
|
|
+ Log::debug('发布提问失败:' . $exception->getMessage());
|
|
|
+ return jsonError('发布提问失败,请重试');
|
|
|
}
|
|
|
}
|
|
|
}
|