xielin 5 anos atrás
pai
commit
9a20623e04

+ 1 - 0
app/Helper/helper.php

@@ -131,6 +131,7 @@ function jsonError($msg)
 
 function subtext($text, $length)
 {
+    $text = strip_tags($text);
     if (mb_strlen($text, 'utf8') > $length) {
         return mb_substr($text, 0, $length - 1, 'utf8') . '...';
     } else {

+ 35 - 13
app/Repositories/BeanRepository.php

@@ -3,6 +3,7 @@
 namespace App\Repositories;
 
 use App\Models\Post;
+use App\Repositories\Circle\CircleRepository;
 use App\Traits\PostTrait;
 use App\Traits\UserTrait;
 use Illuminate\Support\Carbon;
@@ -16,6 +17,11 @@ class BeanRepository
     use PostTrait;
     use UserTrait;
 
+    public function __construct(CircleRepository $circleRepository)
+    {
+        $this->circleRepository = $circleRepository;
+    }
+
     public function beanDetail($request)
     {
         try {
@@ -222,23 +228,32 @@ class BeanRepository
 //        $star_home['battle']['end'] = $activityInfo['end'];
 //        $star_home['battle']['news'] = Redis::get('battle_latest_info_'.$activityInfo['id'])??'战场四平八稳,劳驾老板亲自去战场督战';
 
+        $circleList = $this->circleRepository->circleLists(['is_recommend' => 1]);
+        $circles = [];
+        foreach ($circleList as $circle) {
+            $temp = [];
+            $temp['circle_id'] = $circle['id'];
+            $temp['circle_name'] = mb_substr($circle['name'], 0, 6);
+            $circles[] = $temp;
+        }
+        $star_detail['circles'] = $circles;
         //聊天室
         $tmpChatroom = Redis::get('user_service_chatroom');
-        $chatrooms = $tmpChatroom?json_decode($tmpChatroom,true):[];
+        $chatrooms = $tmpChatroom ? json_decode($tmpChatroom, true) : [];
         $current = Carbon::now()->format('H:i:s');
         $chatRoomsData1 = [];
         $chatRoomsData0 = [];
         foreach ($chatrooms as &$chatroom) {
-            if ($chatroom['start']<$chatroom['end']) {
-                if ($current<$chatroom['start'] || $current>$chatroom['end']) {
+            if ($chatroom['start'] < $chatroom['end']) {
+                if ($current < $chatroom['start'] || $current > $chatroom['end']) {
                     $chatroom['is_open'] = 0;
                     $chatRoomsData0[] = $chatroom;
                 } else {
                     $chatroom['is_open'] = 1;
                     $chatRoomsData1[] = $chatroom;
                 }
-            } elseif ($chatroom['start']>$chatroom['end']) {
-                if ($current>$chatroom['end'] && $current<$chatroom['start']) {
+            } elseif ($chatroom['start'] > $chatroom['end']) {
+                if ($current > $chatroom['end'] && $current < $chatroom['start']) {
                     $chatroom['is_open'] = 0;
                     $chatRoomsData0[] = $chatroom;
                 } else {
@@ -372,7 +387,7 @@ class BeanRepository
             $star_detail['invite']['bean'] = config("customer.share_post_bean") ?? 0;
         } else {
             Log::debug($request['invite_code']);
-            return jsonError('邀请码有误');
+            //return jsonError('邀请码有误');
         }
 
         $star_detail['mybean']['user_count'] = intval($user_bean['user_count']) ?? 0;//已入驻老板
@@ -381,8 +396,15 @@ class BeanRepository
 
         $star_detail['daily_news'] = $this->getNews($request);
         $star_detail['exchange'] = $exchange;
-
-
+        $circleList = $this->circleRepository->circleLists(['is_recommend' => 1]);
+        $circles = [];
+        foreach ($circleList as $circle) {
+            $temp = [];
+            $temp['circle_id'] = $circle['id'];
+            $temp['circle_name'] = mb_substr($circle['name'], 0, 6);
+            $circles[] = $temp;
+        }
+        $star_detail['circles'] = $circles;
 
         return $star_detail;
 
@@ -422,21 +444,21 @@ class BeanRepository
 
         //聊天室
         $tmpChatroom = Redis::get('user_service_chatroom');
-        $chatrooms = $tmpChatroom?json_decode($tmpChatroom,true):[];
+        $chatrooms = $tmpChatroom ? json_decode($tmpChatroom, true) : [];
         $current = Carbon::now()->format('H:i:s');
         $chatRoomsData1 = [];
         $chatRoomsData0 = [];
         foreach ($chatrooms as &$chatroom) {
-            if ($chatroom['start']<$chatroom['end']) {
-                if ($current<$chatroom['start'] || $current>$chatroom['end']) {
+            if ($chatroom['start'] < $chatroom['end']) {
+                if ($current < $chatroom['start'] || $current > $chatroom['end']) {
                     $chatroom['is_open'] = 0;
                     $chatRoomsData0[] = $chatroom;
                 } else {
                     $chatroom['is_open'] = 1;
                     $chatRoomsData1[] = $chatroom;
                 }
-            } elseif ($chatroom['start']>$chatroom['end']) {
-                if ($current>$chatroom['end'] && $current<$chatroom['start']) {
+            } elseif ($chatroom['start'] > $chatroom['end']) {
+                if ($current > $chatroom['end'] && $current < $chatroom['start']) {
                     $chatroom['is_open'] = 0;
                     $chatRoomsData0[] = $chatroom;
                 } else {

+ 106 - 0
app/Repositories/Circle/CircleRepository.php

@@ -0,0 +1,106 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/5
+ * Time: 16:03
+ */
+
+namespace App\Repositories\Circle;
+
+use App\Models\InterestCircle;
+use Illuminate\Database\QueryException;
+use Dingo\Api\Http\Response;
+use Illuminate\Support\Carbon;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
+
+class CircleRepository
+{
+
+    public function __construct(InterestCircle $interestCircle)
+    {
+        $this->interestCircle = $interestCircle;
+    }
+
+    /**
+     * 圈子列表
+     */
+    public function circleLists($request, $limit = 3)
+    {
+        $where[] = ['is_open', 1];
+        if (isset($request['is_recommend'])) {
+            $where[] = ['is_recommend', 1];
+        }
+
+        return $this->interestCircle
+            ->where($where)
+            ->orderBy('id', 'desc')
+            ->take($limit)
+            ->get();
+    }
+
+    /**
+     * 圈子详情
+     */
+    public function detail($request, $isTrashed = false)
+    {
+        $model = $this->interestCircle;
+        if ($isTrashed) {
+            $model->withTrashed();
+        }
+        return $model->find($request['id']);
+    }
+
+
+    /**
+     * 相册列表
+     */
+    public function pictureLists($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+        $where = [];
+        if (isset($request['circle_id'])) {
+            $where[] = ['circle_id', $request['circle_id']];
+        }
+        if (isset($request['uid'])) {
+            $where[] = ['uid', $request['uid']];
+        }
+
+        return $this->interestCirclePicture
+            ->where($where)
+            ->orderBy('created_at', 'desc')
+            ->paginate($perPage);
+    }
+
+    /**
+     * 删除相册图片
+     */
+    public function deletePicture($request)
+    {
+        $circle = $this->interestCirclePicture->where('id', $request['id'])->first();
+        if (!$circle) {
+            return Response::create([
+                'message' => '获取图片信息失败',
+                'status_code' => 500
+            ]);
+        }
+        DB::beginTransaction();
+        try {
+            $circle->delete();
+            DB::commit();
+            return Response::create();
+
+        } catch (QueryException $exception) {
+            DB::rollBack();
+            Log::debug('删除相册图片:' . $request['id'] . $exception->getMessage());
+            return Response::create([
+                'message' => '操作失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code' => 500
+            ]);
+        }
+    }
+}

+ 6 - 1
app/Repositories/FeedRepositories.php

@@ -206,6 +206,11 @@ class FeedRepositories
             $isFollow = $followStatus;
         }
         $user = $this->userInfo($postInfo['uid']);
+        if($postInfo['type']=='html'){
+            $content = subtext($postInfo['content'],100);
+        }else{
+            $content = $postInfo['content'];
+        }
         return [
             'id' => (int)$postInfo['id'],
             'type' => $postInfo['type'],
@@ -216,7 +221,7 @@ class FeedRepositories
             'topic' => $this->getTopic($postInfo['topic_ids']),
             'is_fine' => $postInfo['is_fine'],
             'title' => $postInfo['title'],
-            'content' => $postInfo['content'],
+            'content' => $content,
             'location' => $postInfo['location'],
             'img' => $postInfo['img'],
             'imgs' => $postInfo['imgs'],

+ 1 - 1
app/Repositories/PostRepositories.php

@@ -92,7 +92,7 @@ class PostRepositories
             return jsonError('创作欲望太强啦,休息一下,看看其他用户的内容吧!');
         }
 
-        $detectionText = $request['title'] . ',' . $request['content'];
+        $detectionText = strip_tags($request['title']) . ',' . strip_tags($request['content']);
         $detectionTextResult = $this->detectionService->checkText($detectionText);
         if ($detectionTextResult['code'] < 0) {
             return jsonError('内容违规,请修正哦');

+ 1 - 0
app/Transformers/Post/ListTransformer.php

@@ -37,6 +37,7 @@ class ListTransformer extends TransformerAbstract
             'uid' => $post['uid'],
             'username' => $user['username'],
             'avatar' => $user['avatar'],
+            'is_fine' => $post['is_fine']??0,
             'title' => $post['title'],
             'content' => subtext($post['content'], 100),
             'img' => $post['img'],

+ 6 - 1
app/Transformers/Post/SuggestTransformer.php

@@ -38,6 +38,11 @@ class SuggestTransformer extends TransformerAbstract
         }
         $user = $this->userInfo($post['uid']);
         $postInfo = $this->getPostInfo($post['id']);
+        if($post['type']=='html'){
+            $content = subtext($post['content'],100);
+        }else{
+            $content = $post['content'];
+        }
         return [
             'show_type' => 'post',
             'id' => $post['id'],
@@ -49,7 +54,7 @@ class SuggestTransformer extends TransformerAbstract
             'topic' => $this->getTopic($post['topic_ids']),
             'is_fine' => $post['is_fine'],
             'title' => $post['title'],
-            'content' => $post['content'],
+            'content' => $content,
             'location' => $post['location'],
             'img' => $post['img'],
             'imgs' => $postInfo['imgs'],