xielin преди 5 години
родител
ревизия
9f1ddb5094

+ 4 - 0
app/Http/Controllers/V1/CircleController.php

@@ -43,6 +43,10 @@ class CircleController extends Controller
         $this->circleMessageRepository = $circleMessageRepository;
         $this->circleMessageRepository = $circleMessageRepository;
     }
     }
 
 
+    public function valid(Request $request){
+
+    }
+
     /**
     /**
      * 圈子首页
      * 圈子首页
      * @param Request $request
      * @param Request $request

+ 1 - 1
app/Models/InterestCircle.php

@@ -19,6 +19,6 @@ class InterestCircle extends Model
 
 
     public function imgs()
     public function imgs()
     {
     {
-        return $this->hasMany('App\Models\InterestCircleMessageImg', 'post_id', 'id');
+        return $this->hasMany('App\Models\InterestCircleMessageImg', 'msg_id', 'id');
     }
     }
 }
 }

+ 173 - 0
app/Repositories/Circle/CircleMessageRepository.php

@@ -46,8 +46,181 @@ class CircleMessageRepository
 
 
         return $this->interestCircleMessage
         return $this->interestCircleMessage
             ->where($where)
             ->where($where)
+            ->with('imgs')
             ->orderBy('is_recommend', 'desc')
             ->orderBy('is_recommend', 'desc')
             ->orderBy('id', 'desc')
             ->orderBy('id', 'desc')
             ->paginate($perPage);
             ->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('发布内容失败,请重试');
+        }
+    }
 }
 }

+ 5 - 1
app/Transformers/Circle/MessageListTransformer.php

@@ -25,12 +25,16 @@ class MessageListTransformer extends TransformerAbstract
     public function transform(InterestCircleMessage $interestCircleMessage)
     public function transform(InterestCircleMessage $interestCircleMessage)
     {
     {
         $user = $this->userInfo($interestCircleMessage['uid']);
         $user = $this->userInfo($interestCircleMessage['uid']);
+        $imgs = [];
+        foreach($interestCircleMessage->imgs as $img){
+            $imgs[] = $img['img'];
+        }
         return [
         return [
             'id' => $interestCircleMessage['id'],
             'id' => $interestCircleMessage['id'],
             'created_at' => Carbon::parse($interestCircleMessage['created_at'])->diffForHumans(),
             'created_at' => Carbon::parse($interestCircleMessage['created_at'])->diffForHumans(),
             'user' => $user ? $user : new \stdClass(),
             'user' => $user ? $user : new \stdClass(),
             'content' => $interestCircleMessage['content'],
             'content' => $interestCircleMessage['content'],
-            'imgs' => $postInfo['imgs'],
+            'imgs' => $imgs,
             'good' => $interestCircleMessage['good'],
             'good' => $interestCircleMessage['good'],
             'bad' => $interestCircleMessage['bad'],
             'bad' => $interestCircleMessage['bad'],
             'comment_count' => $interestCircleMessage['comment_count'],
             'comment_count' => $interestCircleMessage['comment_count'],

+ 1 - 1
app/Transformers/Topic/TopicDetailTransformer.php

@@ -41,7 +41,7 @@ class TopicDetailTransformer extends TransformerAbstract
     {
     {
         $circleInfo = InterestCircle::find($circleId);
         $circleInfo = InterestCircle::find($circleId);
         if ($circleInfo) {
         if ($circleInfo) {
-            $circle['id'] = $circleInfo->id;
+            $circle['id'] = $circleInfo->room_id;
             $circle['name'] = $circleInfo->name;
             $circle['name'] = $circleInfo->name;
         } else {
         } else {
             $circle = new \stdClass();
             $circle = new \stdClass();