interestCircle = $interestCircle; $this->interestCircleMessage = $interestCircleMessage; $this->interestCircleMessageComment = $interestCircleMessageComment; } /** * 提问列表 */ public function lists($request) { $perPage = isset($request['per_page']) ? $request['per_page'] : 20; $where[] = ['circle_id', $request['id']]; return $this->interestCircleMessage ->where($where) ->with('imgs') ->orderBy('is_recommend', 'desc') ->orderBy('id', 'desc') ->paginate($perPage); } /** * 发布提问 */ public function create($request) { //验证小号 $userInfo = $this->getUserInfo(); if (empty($userInfo)) { return jsonError('获取用户信息失败'); } if (!$userInfo['sns_status']) { return jsonError('您已被禁言'); } $isValid = 0; if ($userInfo['strength']) { $isValid = 1; } $oneHourTime = Carbon::now()->addHours(-1)->toDateTimeString(); $oneHourPostCount = $this->post->where('uid', $userInfo['uid'])->where('created_at', '>', $oneHourTime)->count(); if ($oneHourPostCount > 5) { return jsonError('创作欲望太强啦,休息一下,看看其他用户的内容吧!'); } $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('图片违规,请修正哦'); } $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' => $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, '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' . $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, ]); } catch (QueryException $exception) { DB::rollBack(); Log::debug('发布内容失败:' . $exception->getMessage()); return jsonError('发布内容失败,请重试'); } } }