|
@@ -923,4 +923,183 @@ class PostRepositories
|
|
return $this->detectionService->checkImg($img);
|
|
return $this->detectionService->checkImg($img);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 发布内容--程序对接使用
|
|
|
|
+ */
|
|
|
|
+ public function createPost($request)
|
|
|
|
+ {
|
|
|
|
+ //验证小号
|
|
|
|
+ $isValid = 1;
|
|
|
|
+
|
|
|
|
+ $detectionText = strip_tags($request['title']) . ',' . 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') {
|
|
|
|
+ $imgs = json_decode($request['imgs'], true);
|
|
|
|
+ $imgCount = count($imgs);
|
|
|
|
+ if ($imgCount == 0 || $imgCount > 9) {
|
|
|
|
+ return jsonError('所传图集必须1-9个');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $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('图片违规,请修正哦');
|
|
|
|
+ }
|
|
|
|
+ //如果为html时候,则imgs只是去把富文本的图片拿去鉴黄,但不做其他处理
|
|
|
|
+ if ($request['type'] == 'html') {
|
|
|
|
+ $imgs = [];
|
|
|
|
+ }
|
|
|
|
+ $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 (empty($videoUrl)) {
|
|
|
|
+ return jsonError('发布失败,请重试');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $fresh = (Carbon::now()->timestamp) - (Carbon::parse("2019-05-01 00:00:00")->timestamp);
|
|
|
|
+ $score = $fresh / 43200;
|
|
|
|
+ $data = [
|
|
|
|
+ 'uid' => $request['uid'],
|
|
|
|
+ 'username' => $request['username'],
|
|
|
|
+ 'mobile' => $request['mobile'],
|
|
|
|
+ 'avatar' => $request['avatar'] ?? '',
|
|
|
|
+ 'type' => $request['type'],
|
|
|
|
+ 'img' => $request['img'],
|
|
|
|
+ 'video' => $videoUrl,
|
|
|
|
+ 'video_id' => $videoId,
|
|
|
|
+ 'topic_ids' => implode(',', $topicIds),
|
|
|
|
+ 'title' => isset($request['title']) ? strip_tags($request['title']) : '',
|
|
|
|
+ 'content' => $request['content'],
|
|
|
|
+ 'lat' => isset($request['lat']) ? number_format($request['lat'],8) : 0,
|
|
|
|
+ 'lng' => isset($request['lng']) ? number_format($request['lng'],8) : 0,
|
|
|
|
+ 'location' => isset($request['location']) ? strip_tags($request['location']) : '',
|
|
|
|
+ 'is_suggest' => 0,
|
|
|
|
+ 'is_hide' => 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
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+ if ($imgs) {
|
|
|
|
+ $imgData = [];
|
|
|
|
+ foreach ($imgs as $img) {
|
|
|
|
+ $imgData[] = [
|
|
|
|
+ 'post_id' => $post->id,
|
|
|
|
+ 'img' => $img,
|
|
|
|
+ 'created_at' => $date,
|
|
|
|
+ 'updated_at' => $date
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ $this->postImgs->insert($imgData);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DB::commit();
|
|
|
|
+ Redis::zadd('post_trigger_type', $isValid, $post->id);
|
|
|
|
+ foreach ($topicIds as $id) {
|
|
|
|
+ Redis::zincrby('topic.user_uid' . $request['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());
|
|
|
|
+ $behavior = Behavior::where('behavior_identification', 'publish')->first();
|
|
|
|
+ if ($behavior) {
|
|
|
|
+ $data = [
|
|
|
|
+ "behavior_id" => $behavior['virus_behavior_id'],
|
|
|
|
+ "behavior_flag" => "publish",
|
|
|
|
+ "post_id" => $post->id,
|
|
|
|
+ "post_type" => $post->type,
|
|
|
|
+ "post_desc" => $post->title?$post->title:subtext($post->conetnt,100),
|
|
|
|
+ "post_cover" => $post->img,
|
|
|
|
+ "target_id" => $post->uid,
|
|
|
|
+ "action_id" => $post->id, //传帖子ID
|
|
|
|
+ ];
|
|
|
|
+ Log::debug('h5邀请用户注册' . json_encode($data));
|
|
|
|
+ //扔进virus队列
|
|
|
|
+ $rabbit = new RabbitMqUtil();
|
|
|
|
+ $rabbit->push('virus_add', $data);
|
|
|
|
+ }
|
|
|
|
+ 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,
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+ } catch (QueryException $exception) {
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ Log::debug('发布内容失败:' . $exception->getMessage());
|
|
|
|
+ return jsonError('发布内容失败,请重试');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|