浏览代码

Merge branch 'develop'

xielin 5 年之前
父节点
当前提交
21a8aa7a38
共有 42 个文件被更改,包括 2543 次插入98 次删除
  1. 497 0
      app/Http/Controllers/Circle/CircleController.php
  2. 2 0
      app/Http/Controllers/ConfigController.php
  3. 20 0
      app/Models/InterestCircle.php
  4. 19 0
      app/Models/InterestCircleArticle.php
  5. 25 0
      app/Models/InterestCircleMessage.php
  6. 17 0
      app/Models/InterestCircleMessageComment.php
  7. 20 0
      app/Models/InterestCircleMessageImg.php
  8. 17 0
      app/Models/InterestCircleMessageRecord.php
  9. 20 0
      app/Models/InterestCirclePicture.php
  10. 19 0
      app/Models/InterestCircleUser.php
  11. 266 0
      app/Repositories/Circle/CircleArticleRepository.php
  12. 98 0
      app/Repositories/Circle/CircleMemberRepository.php
  13. 215 0
      app/Repositories/Circle/CircleMessageRepository.php
  14. 262 0
      app/Repositories/Circle/CircleRepository.php
  15. 2 2
      app/Repositories/Post/PostRepository.php
  16. 93 75
      app/Repositories/TopicRepository.php
  17. 12 0
      app/Traits/UserTrait.php
  18. 38 0
      app/Transformers/Circle/ArticleListTransformer.php
  19. 31 0
      app/Transformers/Circle/CircleMemberTransformer.php
  20. 37 0
      app/Transformers/Circle/CommentTransformer.php
  21. 39 0
      app/Transformers/Circle/DetailTransformer.php
  22. 32 0
      app/Transformers/Circle/InterestCirclePictureTransformer.php
  23. 32 0
      app/Transformers/Circle/InterestCircleTransformer.php
  24. 44 0
      app/Transformers/Circle/MessageDetailTransformer.php
  25. 46 0
      app/Transformers/Circle/MessageListTransformer.php
  26. 43 0
      app/Transformers/Circle/PostListTransformer.php
  27. 1 0
      app/Transformers/DetailTopicTransformer.php
  28. 49 0
      database/migrations/2019_10_09_055019_create_table_interest_circles.php
  29. 36 0
      database/migrations/2019_10_09_060956_create_table_interest_circle_articles.php
  30. 36 0
      database/migrations/2019_10_09_061333_create_interest_circle_users_table.php
  31. 39 0
      database/migrations/2019_10_09_061550_create_interest_circle_pictures_table.php
  32. 40 0
      database/migrations/2019_10_09_061822_create_interest_circle_messages_table.php
  33. 35 0
      database/migrations/2019_10_09_062233_create_interest_circle_message_records_table.php
  34. 34 0
      database/migrations/2019_10_09_062401_create_interest_circle_message_imgs_table.php
  35. 41 0
      database/migrations/2019_10_09_062552_create_interest_circle_message_comments_table.php
  36. 35 0
      database/migrations/2019_10_11_055646_add_column_circle_id_to_topic.php
  37. 36 0
      database/migrations/2019_10_12_012729_add_column_is_fine_to_post.php
  38. 37 0
      database/migrations/2019_10_15_103836_add_column_weight_to_interest_circle_messages.php
  39. 36 0
      database/migrations/2019_10_15_113727_add_column_reply_username_to_interest_circle_message_comments.php
  40. 36 0
      database/migrations/2019_10_16_004919_add_column_msg_id_to_interest_circle_message_records.php
  41. 36 0
      database/migrations/2019_10_16_075004_add_column_is_main_to_interest_circle_pictures.php
  42. 70 21
      routes/api.php

+ 497 - 0
app/Http/Controllers/Circle/CircleController.php

@@ -0,0 +1,497 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/5
+ * Time: 15:58
+ */
+
+namespace App\Http\Controllers\Circle;
+
+use App\Repositories\Circle\CircleArticleRepository;
+use App\Repositories\Circle\CircleMemberRepository;
+use App\Repositories\Circle\CircleMessageRepository;
+use App\Repositories\Circle\CircleRepository;
+use App\Transformers\Circle\ArticleListTransformer;
+use App\Transformers\Circle\CircleMemberTransformer;
+use App\Transformers\Circle\CommentTransformer;
+use App\Transformers\Circle\DetailTransformer;
+use App\Transformers\Circle\InterestCirclePictureTransformer;
+use App\Transformers\Circle\InterestCircleTransformer;
+use App\Transformers\Circle\MessageDetailTransformer;
+use App\Transformers\Circle\MessageListTransformer;
+use App\Transformers\Circle\PostListTransformer;
+use Carbon\Carbon;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Validator;
+use App\Http\Controllers\Controller;
+use Illuminate\Validation\Rule;
+use League\Fractal\Manager;
+use League\Fractal\Pagination\IlluminatePaginatorAdapter;
+use League\Fractal\Resource\Collection;
+use League\Fractal\Resource\Item;
+
+class CircleController extends Controller
+{
+    public function __construct(CircleRepository $circleRepository,
+                                CircleArticleRepository $circleArticleRepository,
+                                CircleMemberRepository $circleMemberRepository,
+                                CircleMessageRepository $circleMessageRepository
+    )
+    {
+        $this->circleRepository = $circleRepository;
+        $this->circleArticleRepository = $circleArticleRepository;
+        $this->circleMemberRepository = $circleMemberRepository;
+        $this->circleMessageRepository = $circleMessageRepository;
+    }
+
+    /**
+     * 创建圈子
+     */
+    public function create(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'name' => 'required|max:12',
+            'image' => 'required|url',
+            'notice' => 'nullable|string|max:44',
+            'join_limit' => ['required', Rule::in(0, 1)],
+            'limit_condition' => 'required_if:join_limit,1|integer',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->circleRepository->create($request->all());
+    }
+
+    /**
+     * 修改圈子
+     */
+    public function update(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|exists:interest_circles',
+            'name' => 'required|max:12',
+            'image' => 'required|url',
+            'notice' => 'nullable|string|max:44',
+            'join_limit' => ['required', Rule::in(0, 1)],
+            'limit_condition' => 'required_if:join_limit,1|integer',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->circleRepository->update($request->all());
+    }
+
+    /**
+     * 圈子列表
+     */
+    public function index(Request $request)
+    {
+        $circleList = $this->circleRepository->circleLists($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($circleList, new InterestCircleTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($circleList));
+        $data = $fractal->createData($resource)->toArray();
+        $data['extra'] = [
+            'filters' => [
+                'keyword',
+                'is_open'
+            ],
+            'columns' => [
+                'id',
+                'name',
+                'image',
+                'created_at',
+                'article_count',
+                'message_count',
+                'view_count',
+                'join_count',
+                'is_recommend',
+                'is_open',
+            ]
+        ];
+        return $data;
+    }
+
+
+    /**
+     * 圈子详情
+     */
+    public function detail(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|exists:interest_circles'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+
+        $circle = $this->circleRepository->detail($request->all());
+        return $this->response->item($circle, new DetailTransformer());
+    }
+
+    /**
+     * 圈子 推荐
+     */
+    public function recommend(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|exists:interest_circles'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->circleRepository->circleRecommend($request->all());
+    }
+
+    /**
+     * 圈子 开启/关闭
+     */
+    public function circleStatus(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|exists:interest_circles'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->circleRepository->circleStatus($request->all());
+    }
+
+    /**
+     * 相册列表
+     */
+    public function pictureList(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'circle_id' => 'required|integer'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        $pictureList = $this->circleRepository->pictureLists($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($pictureList, new InterestCirclePictureTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($pictureList));
+        $data = $fractal->createData($resource)->toArray();
+        return $data;
+    }
+
+    /**
+     * 删除相册图片
+     */
+    public function deletePicture(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|exists:interest_circle_pictures'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->circleRepository->deletePicture($request->all());
+    }
+
+    /**
+     * 圈子精品文章列表
+     */
+    public function articleList(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'circle_id' => 'required|integer'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        $articleList = $this->circleArticleRepository->lists($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($articleList, new ArticleListTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($articleList));
+        $data = $fractal->createData($resource)->toArray();
+        $data['extra'] = [
+            'filters' => [
+
+            ],
+            'columns' => [
+                'id',
+                'created_at',
+                'uid',
+                'topic',
+                'content',
+                'pv',
+                'praise_count',
+                'share_count',
+                'comment_count',
+                'collect_count',
+                'is_recommend',
+            ]
+        ];
+        return $data;
+    }
+
+    /**
+     * 可选帖子列表
+     */
+    public function postList(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'circle_id' => 'required|integer'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        $productList = $this->circleArticleRepository->postList($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($productList, new PostListTransformer($request['circle_id']));
+        $resource->setPaginator(new IlluminatePaginatorAdapter($productList));
+        $data = $fractal->createData($resource)->toArray();
+        $data['extra'] = [
+            'filters' => [
+                'keyword',
+                'content',
+                'topic_ids',
+                'category_ids',
+                'is_suggest',
+                'created_at',
+                'type',
+                'sort'
+            ],
+            'columns' => [
+                'id',
+                'created_at',
+                'uid',
+                'topic',
+                'content',
+                'image',
+                'is_exists_circle',
+            ]
+        ];
+        return $data;
+    }
+
+    /**
+     * 精品文章 推荐
+     */
+    public function articleRecommend(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'post_id' => 'required|integer',
+            'circle_id' => 'required|integer'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->circleArticleRepository->articleRecommend($request->all());
+    }
+
+    /**
+     * 精品文章 加入
+     */
+    public function articleInsert(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'post_id' => 'required|integer',
+            'circle_id' => 'required|integer'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->circleArticleRepository->articleInsert($request->all());
+    }
+
+    /**
+     * 移出精品文章
+     */
+    public function articleRemove(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'post_id' => 'required|integer',
+            'circle_id' => 'required|integer'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->circleArticleRepository->articleRemove($request->all());
+    }
+
+
+    /**
+     * 圈子用户列表
+     */
+    public function memberList(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'circle_id' => 'required|integer'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        $memberList = $this->circleMemberRepository->lists($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($memberList, new CircleMemberTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($memberList));
+        $data = $fractal->createData($resource)->toArray();
+        $data['extra'] = [
+            'filters' => [
+                'uid',
+                'user_type'
+            ],
+            'columns' => [
+                'id',
+                'created_at',
+                'uid',
+                'is_black',
+            ]
+        ];
+        return $data;
+    }
+    /**
+     * 设置圈子黑名单
+     */
+    public function setCircleBlack(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'uid' => 'required|integer',
+            'circle_id' => 'required|integer'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->circleMemberRepository->setUserBlack($request->all());
+    }
+
+    /**
+     * 圈子留言列表
+     */
+    public function messageList(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'circle_id' => 'required|integer'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        $commentList = $this->circleMessageRepository->lists($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($commentList, new MessageListTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($commentList));
+        $data = $fractal->createData($resource)->toArray();
+
+        $data['extra'] = [
+            'filters' => [
+                'uid',
+                'content',
+                'created_at',
+            ],
+            'columns' => [
+                'id',
+                'created_at',
+                'uid',
+                'username',
+                'avatar',
+                'circle_id',
+                'circle_name',
+                'content',
+                'good',
+                'bad',
+                'comment_count',
+                'is_recommend',
+            ]
+        ];
+        return $data;
+    }
+
+    /**
+     * 圈子留言详情
+     */
+    public function messageDetail(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|exists:interest_circle_messages'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+
+        $message = $this->circleMessageRepository->detail($request->all());
+        return $this->response->item($message, new MessageDetailTransformer());
+    }
+
+    /**
+     * 留言 推荐
+     */
+    public function messageRecommend(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|integer',
+            'circle_id' => 'required|integer'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->circleMessageRepository->messageRecommend($request->all());
+    }
+
+    /**
+     * 删除圈子留言
+     */
+    public function deleteMessage(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|exists:interest_circle_messages',
+            'circle_id' => 'required|integer'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->circleMessageRepository->delete($request->all());
+    }
+    /**
+     * 圈子留言评论列表
+     */
+    public function commentList(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'msg_id' => 'required|integer'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        $commentList = $this->circleMessageRepository->commentList($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($commentList, new CommentTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($commentList));
+        $data = $fractal->createData($resource)->toArray();
+
+        $data['extra'] = [
+            'filters' => [
+
+            ],
+            'columns' => [
+                'id',
+                'parent_id',
+                'uid',
+                'content',
+                'created_at',
+                'is_delete',
+            ]
+        ];
+        return $data;
+    }
+
+
+    /**
+     * 删除评论
+     */
+    public function commentDelete(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|integer',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->circleMessageRepository->commentDelete($request->all());
+    }
+
+}

+ 2 - 0
app/Http/Controllers/ConfigController.php

@@ -101,6 +101,8 @@ class ConfigController extends Controller
                 '2' =>'用户',
                 '3' =>'活动',
                 '4' =>'话题',
+                '5' =>'社团活动',
+                '6' =>'圈子',
             ],
             'floor_type'=>[
                 0=>'banner',

+ 20 - 0
app/Models/InterestCircle.php

@@ -0,0 +1,20 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/5
+ * Time: 16:24
+ */
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class InterestCircle extends Model
+{
+    //
+    use SoftDeletes;
+    protected $table = 'interest_circles';
+    protected $guarded = [];
+
+}

+ 19 - 0
app/Models/InterestCircleArticle.php

@@ -0,0 +1,19 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/5
+ * Time: 16:24
+ */
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class InterestCircleArticle extends Model
+{
+    //
+    protected $table = 'interest_circle_articles';
+    protected $guarded = [];
+
+}

+ 25 - 0
app/Models/InterestCircleMessage.php

@@ -0,0 +1,25 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/5
+ * Time: 16:24
+ */
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class InterestCircleMessage extends Model
+{
+    //
+    use SoftDeletes;
+    protected $table = 'interest_circle_messages';
+    protected $guarded = [];
+
+    public function imgs()
+    {
+        return $this->hasMany('App\Models\InterestCircleMessageImg', 'msg_id', 'id');
+    }
+
+}

+ 17 - 0
app/Models/InterestCircleMessageComment.php

@@ -0,0 +1,17 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/6
+ * Time: 11:21
+ */
+
+namespace App\Models;
+use Illuminate\Database\Eloquent\Model;
+
+class InterestCircleMessageComment extends Model
+{
+//
+    protected $table = 'interest_circle_message_comments';
+    protected $guarded = [];
+}

+ 20 - 0
app/Models/InterestCircleMessageImg.php

@@ -0,0 +1,20 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/5
+ * Time: 16:24
+ */
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class InterestCircleMessageImg extends Model
+{
+    //
+    protected $table = 'interest_circle_message_imgs';
+    protected $guarded = [];
+
+
+}

+ 17 - 0
app/Models/InterestCircleMessageRecord.php

@@ -0,0 +1,17 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/6
+ * Time: 11:21
+ */
+
+namespace App\Models;
+use Illuminate\Database\Eloquent\Model;
+
+class InterestCircleMessageRecord extends Model
+{
+//
+    protected $table = 'interest_circle_message_records';
+    protected $guarded = [];
+}

+ 20 - 0
app/Models/InterestCirclePicture.php

@@ -0,0 +1,20 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/5
+ * Time: 16:24
+ */
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class InterestCirclePicture extends Model
+{
+    //
+    use SoftDeletes;
+    protected $table = 'interest_circle_pictures';
+    protected $guarded = [];
+
+}

+ 19 - 0
app/Models/InterestCircleUser.php

@@ -0,0 +1,19 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/5
+ * Time: 16:24
+ */
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class InterestCircleUser extends Model
+{
+    //
+    protected $table = 'interest_circle_users';
+    protected $guarded = [];
+
+}

+ 266 - 0
app/Repositories/Circle/CircleArticleRepository.php

@@ -0,0 +1,266 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/5
+ * Time: 16:03
+ */
+
+namespace App\Repositories\Circle;
+
+use App\Models\InterestCircle;
+use App\Models\InterestCircleArticle;
+use App\Models\Post;
+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 CircleArticleRepository
+{
+
+    public function __construct(InterestCircleArticle $interestCircleArticle, Post $post, InterestCircle $interestCircle)
+    {
+        $this->interestCircleArticle = $interestCircleArticle;
+        $this->post = $post;
+        $this->interestCircle = $interestCircle;
+    }
+
+    /**
+     * 内容列表
+     */
+    public function lists($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+        $where = [];
+
+        if (isset($request['uid'])) {
+            $where[] = ['uid', $request['uid']];
+        }
+
+        if (isset($request['circle_id'])) {
+            $where[] = ['interest_circle_articles.circle_id', $request['circle_id']];
+        }
+
+        $articleModel = $this->post;
+
+        return $articleModel
+            ->join('post_data', 'post_data.post_id', '=', 'post.id')
+            ->join('interest_circle_articles', 'interest_circle_articles.post_id', '=', 'post.id')
+            ->select('post.*', 'interest_circle_articles.is_recommend', 'interest_circle_articles.circle_id')
+            ->with('data')
+            ->where($where)
+            ->where(function ($query) use ($request) {
+                if (isset($request['content'])) {
+                    $query->where('title', 'like', "%{$request['content']}%")
+                        ->orWhere('content', 'like', "%{$request['content']}%");
+                }
+            })
+            ->where(function ($query) use ($request) {
+                if (isset($request['created_at'])) {
+                    $time = explode('_', $request['created_at']);
+                    $query->whereBetween('post.created_at', $time);
+                }
+            })
+            ->orderBy('is_recommend', 'desc')
+            ->paginate($perPage);
+    }
+
+    /**
+     * 推荐精品文章
+     */
+    public function articleRecommend($request)
+    {
+        $article = $this->interestCircleArticle
+            ->where('post_id', $request['post_id'])
+            ->where('circle_id', $request['circle_id'])
+            ->first();
+        if (!$article) {
+            return Response::create([
+                'message' => '获取精品文章信息失败',
+                'status_code' => 500
+            ]);
+        }
+
+        if ($article->is_recommend == 1) {
+            $article->is_recommend = 0;
+        } else {
+            $article->is_recommend = 1;
+        }
+
+        DB::beginTransaction();
+        try {
+            $article->save();
+            DB::commit();
+            return Response::create();
+
+        } catch (QueryException $exception) {
+            DB::rollBack();
+            Log::debug('推荐精品文章:' . $request['post_id'] . '-' . $request['circle_id'] . $exception->getMessage());
+            return Response::create([
+                'message' => '操作失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code' => 500
+            ]);
+        }
+    }
+
+    /**
+     * 精品文章从当前圈子移出
+     */
+    public function articleRemove($request)
+    {
+        $article = $this->interestCircleArticle
+            ->where('post_id', $request['post_id'])
+            ->where('circle_id', $request['circle_id'])
+            ->first();
+        if (!$article) {
+            return Response::create([
+                'message' => '获取精品文章信息失败',
+                'status_code' => 500
+            ]);
+        }
+
+        DB::beginTransaction();
+        try {
+            $article->delete();
+            $this->interestCircle->where('id',$request['circle_id'])->decrement('article_count');
+            $isRef = $this->interestCircleArticle->where('post_id', $request['post_id'])->exists();
+            if (!$isRef) {
+                //移出后需要检测该帖子在其他圈子有没有设为精品,如没有,则删除该帖子的精品标识
+                $this->post->where('id', $request['post_id'])->update(['is_fine' => 0]);
+                Redis::HSET('post_info_' . $request['post_id'],'is_fine',0);
+            }
+            $key = 'circle_articles_' . $request['circle_id'];
+            Redis::zrem($key, $request['post_id']);
+            DB::commit();
+            return Response::create();
+
+        } catch (QueryException $exception) {
+            DB::rollBack();
+            Log::debug('移出精品文章:' . $request['post_id'] . '-' . $request['circle_id'] . $exception->getMessage());
+            return Response::create([
+                'message' => '操作失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code' => 500
+            ]);
+        }
+    }
+
+    /**
+     * 新增精品文章
+     */
+    public function articleInsert($request)
+    {
+        $article = $this->interestCircleArticle
+            ->where('post_id', $request['post_id'])
+            ->where('circle_id', $request['circle_id'])
+            ->first();
+        if ($article) {
+            return Response::create([
+                'message' => '该文章已存在当前圈子',
+                'status_code' => 500
+            ]);
+        }
+
+        DB::beginTransaction();
+        try {
+            $this->interestCircleArticle->insert(['post_id' => $request['post_id'], 'circle_id' => $request['circle_id']]);
+            $this->interestCircle->where('id',$request['circle_id'])->increment('article_count');
+            //修改帖子为精品贴
+            $this->post->where('id', $request['post_id'])->update(['is_fine' => 1]);
+            Redis::HSET('post_info_' . $request['post_id'],'is_fine',1);
+            //将精品文章存入该圈子的有序集合中
+            $key = 'circle_articles_' . $request['circle_id'];
+            Redis::zadd($key, time(), $request['post_id']);
+            DB::commit();
+            return Response::create();
+
+        } catch (QueryException $exception) {
+            DB::rollBack();
+            Log::debug('设置精品文章:' . $request['post_id'] . '-' . $request['circle_id'] . $exception->getMessage());
+            return Response::create([
+                'message' => '操作失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code' => 500
+            ]);
+        }
+    }
+
+    /**
+     * 当前圈子精品文章帖子来源列表
+     * @param $request
+     * @return mixed
+     */
+    public function postList($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+        $where = [];
+        if (isset($request['type'])) {
+            $where[] = ['type', $request['type']];
+        }
+
+        if (isset($request['uid'])) {
+            $where[] = ['uid', $request['uid']];
+        }
+
+        if (isset($request['circle_id'])) {
+            $circleInfo = $this->interestCircle->where('id', $request['circle_id'])->first();
+            if ($circleInfo && $circleInfo->limit_article_ids) {
+                $request['topic_ids'] = "{$circleInfo->limit_article_ids}";
+            }
+        }
+
+        $sort = 'post.id';
+        if (isset($request['sort']) && in_array($request['sort'], ['praise_count', 'share_count', 'pv', 'comment_count', 'create_bean'])) {
+            $sort = $request['sort'];
+        }
+        $post = $this->post;
+
+        return $post
+            ->where($where)
+            ->where(function ($query) use ($request) {
+                if (isset($request['keyword'])) {
+                    $query->where('uid', '=', $request['keyword'])
+                        ->orWhere('username', 'like', "%{$request['keyword']}%")
+                        ->orWhere('mobile', 'like', "%{$request['keyword']}%");
+                }
+            })
+            ->where(function ($query) use ($request) {
+                if (isset($request['content'])) {
+                    $query->where('title', 'like', "%{$request['content']}%")
+                        ->orWhere('content', 'like', "%{$request['content']}%");
+                }
+            })
+            ->where(function ($query) use ($request) {
+                if (isset($request['created_at'])) {
+                    $time = explode('_', $request['created_at']);
+                    $query->whereBetween('post.created_at', $time);
+                }
+            })
+            ->where(function ($query) use ($request) {
+                if (isset($request['category_ids']) || isset($request['topic_ids'])) {
+                    $ids = [];
+                    if (isset($request['category_ids'])) {
+                        $categoryIds = explode(',', $request['category_ids']);
+                        $ids = $this->categoryTopic->whereIn('category_id', $categoryIds)->pluck('topic_id')->toArray();
+                    }
+                    if (isset($request['topic_ids'])) {
+                        $ids = array_merge($ids, explode(',', $request['topic_ids']));
+                    }
+                    foreach ($ids as $key => $id) {
+                        if ($key == 0) {
+                            $query = $query->whereRaw('FIND_IN_SET(' . $id . ',topic_ids)');
+                        } else {
+                            $query = $query->orWhereRaw('FIND_IN_SET(' . $id . ',topic_ids)');
+                        }
+                    }
+                }
+            })
+            ->orderBy($sort, 'desc')
+            ->paginate($perPage);
+    }
+}

+ 98 - 0
app/Repositories/Circle/CircleMemberRepository.php

@@ -0,0 +1,98 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/5
+ * Time: 16:03
+ */
+
+namespace App\Repositories\Circle;
+
+use App\Models\InterestCircle;
+use App\Models\InterestCircleArticle;
+use App\Models\InterestCircleUser;
+use App\Models\Post;
+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 CircleMemberRepository
+{
+
+    public function __construct(InterestCircle $interestCircle,InterestCircleUser $interestCircleUser)
+    {
+        $this->interestCircleUser = $interestCircleUser;
+        $this->interestCircle = $interestCircle;
+    }
+
+    /**
+     * 用户列表
+     */
+    public function lists($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+        $where = [];
+
+        if (isset($request['uid'])) {
+            $where[] = ['uid', $request['uid']];
+        }
+        if (isset($request['user_type'])) {
+            $where[] = ['is_black', $request['user_type']];
+        }
+
+        if (isset($request['circle_id'])) {
+            $where[] = ['circle_id', $request['circle_id']];
+        }
+
+        $userModel = $this->interestCircleUser;
+
+        return $userModel
+            ->where($where)
+            ->orderBy('created_at', 'desc')
+            ->paginate($perPage);
+    }
+
+    /**
+     * 设置该用户为当前圈子黑名单
+     */
+    public function setUserBlack($request)
+    {
+        $article = $this->interestCircleUser
+            ->where('uid', $request['uid'])
+            ->where('circle_id', $request['circle_id'])
+            ->first();
+        if (!$article) {
+            return Response::create([
+                'message' => '当前用户不在该圈子',
+                'status_code' => 500
+            ]);
+        }
+
+        if ($article->is_black == 1) {
+            $article->is_black = 0;
+        } else {
+            $article->is_black = 1;
+        }
+
+        DB::beginTransaction();
+        try {
+            $article->save();
+
+            DB::commit();
+            return Response::create();
+
+        } catch (QueryException $exception) {
+            DB::rollBack();
+            Log::debug('设置圈子黑名单:' . $request['uid'] . '-' . $request['circle_id'] . $exception->getMessage());
+            return Response::create([
+                'message' => '操作失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code' => 500
+            ]);
+        }
+    }
+}

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

@@ -0,0 +1,215 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/5
+ * Time: 16:03
+ */
+
+namespace App\Repositories\Circle;
+
+use App\Models\InterestCircle;
+use App\Models\InterestCircleMessage;
+use App\Models\InterestCircleMessageComment;
+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 CircleMessageRepository
+{
+
+    public function __construct(InterestCircle $interestCircle,
+                                InterestCircleMessage $interestCircleMessage,
+                                InterestCircleMessageComment $interestCircleMessageComment)
+    {
+        $this->interestCircle = $interestCircle;
+        $this->interestCircleMessage = $interestCircleMessage;
+        $this->interestCircleMessageComment = $interestCircleMessageComment;
+    }
+
+    /**
+     * 圈子留言列表
+     */
+    public function lists($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->interestCircleMessage
+            ->where($where)
+            ->where(function ($query) use ($request) {
+                if (isset($request['content'])) {
+                    $query->Where('content', 'like', "%{$request['content']}%");
+                }
+            })
+            ->where(function ($query) use ($request) {
+                if (isset($request['created_at'])) {
+                    $time = explode('_', $request['created_at']);
+                    $query->whereBetween('post.created_at', $time);
+                }
+            })
+            ->orderBy('is_recommend', 'desc')
+            ->orderBy('created_at', 'desc')
+            ->paginate($perPage);
+    }
+
+    /**
+     * 留言详情
+     */
+    public function detail($request, $isTrashed = false)
+    {
+        $model = $this->interestCircleMessage;
+        if ($isTrashed) {
+            $model->withTrashed();
+        }
+        return $model->find($request['id']);
+    }
+
+    /**
+     * 推荐留言
+     */
+    public function messageRecommend($request)
+    {
+        $circle = $this->interestCircleMessage
+            ->where('id', $request['id'])
+            ->where('circle_id', $request['circle_id'])->first();
+        if (!$circle) {
+            return Response::create([
+                'message' => '获取留言信息失败',
+                'status_code' => 500
+            ]);
+        }
+
+        if ($circle->is_recommend == 1) {
+            $circle->is_recommend = 0;
+        } else {
+            $circle->is_recommend = 1;
+        }
+
+        DB::beginTransaction();
+        try {
+            $circle->save();
+
+            DB::commit();
+            return Response::create();
+
+        } catch (QueryException $exception) {
+            DB::rollBack();
+            Log::debug('推荐留言:' . $request['id'] . '-' . $request['circle_id'] . $exception->getMessage());
+            return Response::create([
+                'message' => '操作失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code' => 500
+            ]);
+        }
+    }
+
+    /**
+     * 删除留言
+     */
+    public function delete($request)
+    {
+        $circle = $this->interestCircleMessage
+            ->where('id', $request['id'])
+            ->where('circle_id', $request['circle_id'])
+            ->first();
+        if (!$circle) {
+            return Response::create([
+                'message' => '获取留言信息失败',
+                'status_code' => 500
+            ]);
+        }
+        DB::beginTransaction();
+        try {
+            $circle->delete();
+            $this->interestCircle->where('id',$request['circle_id'])->decrement('message_count');
+            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
+            ]);
+        }
+    }
+
+    /**
+     * 圈子留言评论列表
+     */
+    public function commentList($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['msg_id'])) {
+            $where[] = ['msg_id', $request['msg_id']];
+        }
+
+        return $this->interestCircleMessageComment
+            ->where($where)
+            ->orderBy('created_at', 'desc')
+            ->paginate($perPage);
+    }
+
+    /**
+     * 删除评论
+     */
+    public function commentDelete($request)
+    {
+        $comment = $this->interestCircleMessageComment->find($request['id']);
+        if (!$comment) {
+            return Response::create([
+                'message' => '获取评论信息失败',
+                'status_code' => 500
+            ]);
+        }
+
+        if ($comment->is_delete == 1) {
+            return Response::create([
+                'message' => '该评论已经删除',
+                'status_code' => 500
+            ]);
+        }
+
+        DB::beginTransaction();
+        try {
+            $comment->is_delete = 1;
+            $comment->save();
+
+            DB::commit();
+//            Redis::SADD('delete_post_comment_ids', $comment->id);
+//
+//            if (!$comment->parent_id) {
+//                Redis::DEL('post_new_comment_' . $comment->post_id);
+//            } else {
+//                Redis::DEL('post_new_reply_' . $comment->id);
+//            }
+            return Response::create();
+
+        } catch (QueryException $exception) {
+            DB::rollBack();
+            Log::debug('删除评论:' . $request['id'] . $exception->getMessage());
+            return Response::create([
+                'message' => '操作失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code' => 500
+            ]);
+        }
+    }
+}

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

@@ -0,0 +1,262 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/5
+ * Time: 16:03
+ */
+
+namespace App\Repositories\Circle;
+
+use App\Models\InterestCircle;
+use App\Models\InterestCirclePicture;
+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, InterestCirclePicture $interestCirclePicture)
+    {
+        $this->interestCircle = $interestCircle;
+        $this->interestCirclePicture = $interestCirclePicture;
+    }
+
+    /**
+     * 创建圈子
+     */
+    public function create($request)
+    {
+        $data = [
+            'name' => $request['name'],
+            'notice' => $request['notice'],
+            'image' => $request['image'] ?? '',
+            'join_limit' => $request['join_limit'],
+            'limit_condition' => $request['limit_condition'],
+            'join_question' => json_encode($request['join_question']) ?? '',
+            'limit_article_ids' => $request['limit_article_ids'] ?? '',
+            'contains_function' => json_encode($request['contains_function']) ?? '',
+        ];
+
+        DB::beginTransaction();
+        try {
+            $circle = $this->interestCircle->create($data);
+            DB::commit();
+            return Response::create();
+        } catch (QueryException $exception) {
+            DB::rollBack();
+            Log::debug('创建圈子exception:' . $exception->getMessage());
+            return Response::create([
+                'message' => '创建失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code' => 500
+            ]);
+        }
+    }
+
+    /**
+     * 修改圈子
+     */
+    public function update($request)
+    {
+        $data = [
+            'name' => $request['name'],
+            'notice' => $request['notice'],
+            'image' => $request['image'] ?? '',
+            'join_limit' => $request['join_limit'],
+            'limit_condition' => $request['limit_condition'],
+            'join_question' => json_encode($request['join_question']),
+            'limit_article_ids' => $request['limit_article_ids'] ?? '',
+            'contains_function' => json_encode($request['contains_function']),
+        ];
+
+        DB::beginTransaction();
+        try {
+            $circle = $this->interestCircle->where('id', $request['id'])->update($data);
+            DB::commit();
+            return Response::create();
+        } catch (QueryException $exception) {
+            DB::rollBack();
+            Log::debug('修改圈子exception:' . $exception->getMessage());
+            return Response::create([
+                'message' => '修改失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code' => 500
+            ]);
+        }
+    }
+
+    /**
+     * 圈子列表
+     */
+    public function circleLists($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+        $where = [];
+        if (isset($request['is_open'])) {
+            $where[] = ['is_open', $request['is_open']];
+        }
+
+        return $this->interestCircle
+            ->where($where)
+            ->where(function ($query) use ($request) {
+                if (isset($request['keyword'])) {
+                    $query->Where('name', 'like', "%{$request['keyword']}%");
+                }
+            })
+            ->orderBy('is_recommend', 'desc')
+            ->orderBy('created_at', 'desc')
+            ->paginate($perPage);
+    }
+
+    /**
+     * 圈子详情
+     */
+    public function detail($request, $isTrashed = false)
+    {
+        $model = $this->interestCircle;
+        if ($isTrashed) {
+            $model->withTrashed();
+        }
+        return $model->find($request['id']);
+    }
+
+    /**
+     * 推荐圈子
+     */
+    public function circleRecommend($request)
+    {
+        $circle = $this->interestCircle->where('id', $request['id'])->first();
+        if (!$circle) {
+            return Response::create([
+                'message' => '获取圈子信息失败',
+                'status_code' => 500
+            ]);
+        }
+
+        if ($circle->is_recommend == 1) {
+            $circle->is_recommend = 0;
+        } else {
+            $circle->is_recommend = 1;
+        }
+
+        DB::beginTransaction();
+        try {
+            $circle->save();
+
+            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
+            ]);
+        }
+    }
+
+    /**
+     * 开启/关闭圈子
+     */
+    public function circleStatus($request)
+    {
+        $circle = $this->interestCircle->where('id', $request['id'])->first();
+        if (!$circle) {
+            return Response::create([
+                'message' => '获取圈子信息失败',
+                'status_code' => 500
+            ]);
+        }
+
+        if ($circle->is_open == 1) {
+            $circle->is_open = 0;
+        } else {
+            $circle->is_open = 1;
+        }
+
+        DB::beginTransaction();
+        try {
+            $circle->save();
+
+            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
+            ]);
+        }
+    }
+
+    /**
+     * 相册列表
+     */
+    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();
+            //删除图片后,判断该条是否为主信息,如果为主信息,则更新同批次下一条为主信息
+            if($circle->is_main==1){
+                $tempPic = $this->interestCirclePicture->where('patch_num', $circle->patch_num)->first();
+                if($tempPic){
+                    $tempPic->is_main=1;
+                    $tempPic->save();
+                }
+            }
+            $this->interestCircle->where('id',$circle->circle_id)->decrement('picture_count');
+            DB::commit();
+            $key = 'circle_picture_' . $circle->patch_num;
+            Redis::del($key);
+            return Response::create();
+
+        } catch (QueryException $exception) {
+            DB::rollBack();
+            Log::debug('删除相册图片:' . $request['id'] . $exception->getMessage());
+            return Response::create([
+                'message' => '操作失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code' => 500
+            ]);
+        }
+    }
+}

+ 2 - 2
app/Repositories/Post/PostRepository.php

@@ -107,9 +107,9 @@ class PostRepository
         //验证话题
         $topicIdsArray = $this->topic->whereIn('id', explode(',', $request['topic_ids']))->pluck('id')->toArray();
         $topicCount = count($topicIdsArray);
-        if ($topicCount == 0 || $topicCount > 5) {
+        if ($topicCount == 0 || $topicCount > 2) {
             return Response::create([
-                'message' => '所选话题必须1-5个',
+                'message' => '所选话题必须1-2个',
                 'status_code' => 500
             ]);
         }

+ 93 - 75
app/Repositories/TopicRepository.php

@@ -18,49 +18,55 @@ use Illuminate\Database\QueryException;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Redis;
 
-class TopicRepository {
-    public function __construct(Topic $topic,CategoryTopic $categoryTopic,MemberFollowTopic $memberFollowTopic){
+class TopicRepository
+{
+    public function __construct(Topic $topic, CategoryTopic $categoryTopic, MemberFollowTopic $memberFollowTopic)
+    {
         $this->topic = $topic;
         $this->categoryTopic = $categoryTopic;
         $this->memberFollowTopic = $memberFollowTopic;
     }
+
     //列表
-    public function index($request){
+    public function index($request)
+    {
         $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
         $where = [];
-        if(isset($request['name'])){
+        if (isset($request['name'])) {
             $where[] = ['name', 'like', "%{$request['name']}%"];
         }
-        if(isset($request['topic_status'])){
-            if($request['topic_status'] == 'is_suggest'){
+        if (isset($request['topic_status'])) {
+            if ($request['topic_status'] == 'is_suggest') {
                 $where[] = ['is_suggest', 1];
             }
-            if( $request['topic_status'] == 'is_hot'){
+            if ($request['topic_status'] == 'is_hot') {
                 $where[] = ['is_hot', 1];
             }
-            if($request['topic_status'] == 'is_open'){
+            if ($request['topic_status'] == 'is_open') {
                 $where[] = ['is_open', 1];
             }
-            if($request['topic_status'] == 'is_close'){
+            if ($request['topic_status'] == 'is_close') {
                 $where[] = ['is_open', 0];
             }
         }
 
         return $this->topic
             ->where($where)
-            ->orderBy('is_hot','desc')
-            ->orderBy('is_suggest','desc')
-            ->orderBy('is_open','desc')
-            ->orderBy('id','desc')
+            ->orderBy('is_hot', 'desc')
+            ->orderBy('is_suggest', 'desc')
+            ->orderBy('is_open', 'desc')
+            ->orderBy('id', 'desc')
             ->paginate($perPage);
     }
+
     //新增
-    public function create($request){
-        $topic = $this->topic->where(['name'=>$request['name']])->first();
-        if($topic){
+    public function create($request)
+    {
+        $topic = $this->topic->where(['name' => $request['name']])->first();
+        if ($topic) {
             return Response::create([
-                'message'  => '该话题已存在',
-                'status_code'   => 500
+                'message' => '该话题已存在',
+                'status_code' => 500
             ]);
         }
 
@@ -68,20 +74,21 @@ class TopicRepository {
             'name' => $request['name'],
             'img' => $request['img'],
             'desc' => $request['desc'],
+            'circle_id' => $request['desc'] ?? 0,
         ];
-        if(!empty($request['base_count'])){
+        if (!empty($request['base_count'])) {
             $data['base_count'] = $request['base_count'];
         }
-        if(isset($request['category_ids'])){
+        if (isset($request['category_ids'])) {
             $category_ids = explode(',', $request['category_ids']);
         }
         DB::beginTransaction();
-        try{
+        try {
             $topicInfo = $this->topic->create($data);
-            if($topicInfo){
-                if($category_ids){
+            if ($topicInfo) {
+                if ($category_ids) {
                     $category_topic_data = [];
-                    foreach($category_ids as $value){
+                    foreach ($category_ids as $value) {
                         $category_topic_data[] = [
                             'category_id' => $value,
                             'topic_id' => $topicInfo->id,
@@ -93,54 +100,56 @@ class TopicRepository {
             DB::commit();
             Redis::zadd('topic.name', $topicInfo->id, $topicInfo->name);
             return Response::create();
-        }catch (QueryException $exception){
+        } catch (QueryException $exception) {
             DB::rollBack();
-            Log::debug('新增话题:'.$exception->getMessage());
+            Log::debug('新增话题:' . $exception->getMessage());
             return Response::create([
-                'message'  => '新增话题,请重试',
+                'message' => '新增话题,请重试',
                 'error' => $exception->getMessage(),
-                'status_code'   => 500
+                'status_code' => 500
             ]);
         }
     }
 
-    public function edit($request){
-        $topic = $this->topic->where(['id'=>$request['id']])->first();
-        if(!$topic){
+    public function edit($request)
+    {
+        $topic = $this->topic->where(['id' => $request['id']])->first();
+        if (!$topic) {
             return Response::create([
-                'message'  => '该话题不存在',
-                'status_code'   => 500
+                'message' => '该话题不存在',
+                'status_code' => 500
             ]);
         }
         $oldName = $topic->name;
-        $_topic = $this->topic->where(['name'=>$request['name']])->where('id','<>',$topic->id)->first();
-        if($_topic){
+        $_topic = $this->topic->where(['name' => $request['name']])->where('id', '<>', $topic->id)->first();
+        if ($_topic) {
             return Response::create([
-                'message'  => '该话题已存在',
-                'status_code'   => 500
+                'message' => '该话题已存在',
+                'status_code' => 500
             ]);
         }
 
         $topic->name = $request['name'];
         $topic->img = $request['img'];
         $topic->desc = $request['desc'];
-        if(!empty($request['base_count'])){
+        $topic->circle_id = $request['circle_id'] ?? 0;
+        if (!empty($request['base_count'])) {
             $topic->base_count = $request['base_count'];
         }
         $category_ids = [];
-        if(!empty($request['category_ids'])){
+        if (!empty($request['category_ids'])) {
             $category_ids = explode(',', $request['category_ids']);
         }
         DB::beginTransaction();
-        try{
+        try {
             //保存
             $topicInfo = $topic->save();
             //删除原来关联关系
-            $this->categoryTopic->where(['topic_id'=>$topic->id])->delete();
-            if($topicInfo){
-                if($category_ids){
+            $this->categoryTopic->where(['topic_id' => $topic->id])->delete();
+            if ($topicInfo) {
+                if ($category_ids) {
                     $category_topic_data = [];
-                    foreach($category_ids as $value){
+                    foreach ($category_ids as $value) {
                         $category_topic_data[] = [
                             'category_id' => $value,
                             'topic_id' => $topic->id,
@@ -150,68 +159,77 @@ class TopicRepository {
                 }
             }
             DB::commit();
-            if($oldName != $topic->name){
+            if ($oldName != $topic->name) {
                 Redis::zrem('topic.name', $oldName);
                 Redis::zadd('topic.name', $topic->id, $topic->name);
             }
             return Response::create();
-        }catch (QueryException $exception){
+        } catch (QueryException $exception) {
             DB::rollBack();
-            Log::debug('编辑话题:'.$exception->getMessage());
+            Log::debug('编辑话题:' . $exception->getMessage());
             return Response::create([
-                'message'  => '编辑话题,请重试',
+                'message' => '编辑话题,请重试',
                 'error' => $exception->getMessage(),
-                'status_code'   => 500
+                'status_code' => 500
             ]);
         }
     }
+
     //修改
-    public function update($request){
+    public function update($request)
+    {
         $topic = $this->topic->where('id', $request['id'])->first();
-        if(!$topic){
+        if (!$topic) {
             return Response::create([
-                'message'  => '该话题不存在',
-                'status_code'   => 500
+                'message' => '该话题不存在',
+                'status_code' => 500
             ]);
         }
-        if(isset($request['is_open']) && $request['is_open'] !== null){
+        if (isset($request['is_open']) && $request['is_open'] !== null) {
             $topic->is_open = $request['is_open'];
         }
-        if(!empty($request['type'])){
-            if($topic->is_open == 0){
+        if (!empty($request['type'])) {
+            if ($topic->is_open == 0) {
                 return Response::create([
-                    'message'  => '该话题未开启',
-                    'status_code'   => 500
+                    'message' => '该话题未开启',
+                    'status_code' => 500
                 ]);
             }
-            if(isset($request['type']) && $request['type'] == 1){
+            if (isset($request['type']) && $request['type'] == 1) {
                 $topic->is_suggest = $request['status'];
             }
-            if(isset($request['type']) && $request['type'] == 2){
+            if (isset($request['type']) && $request['type'] == 2) {
                 $topic->is_hot = $request['status'];
             }
         }
 
         $res = $topic->save();
-        if($res){
+        if ($res) {
             return Response::create();
         }
     }
+
     //详情
-    public function view($request){
+    public function view($request)
+    {
         return $this->topic->where('id', $request['id'])->first();
     }
+
     //获取多个话题
-    public function getTopics($ids = []){
-        return $this->topic->whereIn('id', $ids)->select('id','name')->get();
+    public function getTopics($ids = [])
+    {
+        return $this->topic->whereIn('id', $ids)->select('id', 'name')->get();
     }
-    public function getMemberTopics($uid){
-       return $this->memberFollowTopic
-            ->leftJoin('topic','topic.id','=','member_follow_topic.topic_id')
-            ->where('member_follow_topic.uid',$uid)
-            ->select('topic.id','topic.name')
+
+    public function getMemberTopics($uid)
+    {
+        return $this->memberFollowTopic
+            ->leftJoin('topic', 'topic.id', '=', 'member_follow_topic.topic_id')
+            ->where('member_follow_topic.uid', $uid)
+            ->select('topic.id', 'topic.name')
             ->get();
     }
+
     /**
      * 重置话题redis
      */
@@ -220,15 +238,15 @@ class TopicRepository {
         $TopicName = $this->topic->pluck('id', 'name')->toArray();
 
         $res = Redis::zadd('topic.name', $TopicName);
-        if($res){
+        if ($res) {
             return Response::create([
-                'message'  => '重置话题成功',
-                'status_code'   => 500
+                'message' => '重置话题成功',
+                'status_code' => 500
             ]);
-        }else{
+        } else {
             return Response::create([
-                'message'  => '重置话题失败',
-                'status_code'   => 500
+                'message' => '重置话题失败',
+                'status_code' => 500
             ]);
         }
     }

+ 12 - 0
app/Traits/UserTrait.php

@@ -11,6 +11,18 @@ use Tymon\JWTAuth\Facades\JWTAuth;
 
 trait UserTrait
 {
+    public function getShortUserInfo($uid) {
+        try {
+            $url = config("customer.manage_service_url").'/user/v2/short/info';
+            $array = [
+                'json' => ['uid' => $uid], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
+            ];
+            return http($url,$array, false, 'get');
+        } catch (\Exception $e) {
+            return [];
+        }
+
+    }
     public function getUserInfo($uid) {
         try {
             $url = config("customer.manage_service_url").'/user/memberView';

+ 38 - 0
app/Transformers/Circle/ArticleListTransformer.php

@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/6
+ * Time: 14:08
+ */
+namespace App\Transformers\Circle;
+
+use App\Models\Post;
+use App\Traits\PostTrait;
+use Illuminate\Support\Carbon;
+use League\Fractal\TransformerAbstract;
+
+class ArticleListTransformer extends TransformerAbstract
+{
+    use PostTrait;
+    public function transform(Post $post)
+    {
+        return [
+            'id' => $post['id'],
+            'created_at' => Carbon::parse($post['created_at'])->toDateTimeString(),
+            'uid' => $post['uid'],
+            'username' => $post['username'],
+            'avatar' => $post['avatar'],
+            'topic' => $this->getTopic($post['topic_ids'], 1),
+            'content' => subtext(strip_tags($post['content']), 20),
+            'pv' => $post->data->pv_real.'/'.$post->data->pv,
+            'praise_count' => $post->data->praise_real_count.'/'.$post->data->praise_count,
+            'share_count' => $post->data->share_real_count.'/'.$post->data->share_count,
+            'comment_count' => $post->data->comment_count,
+            'collect_count' => $post->data->collect_real_count.'/'.$post->data->collect_count,
+            'is_recommend' => $post['is_recommend'],
+            'circle_id' => $post['circle_id'],
+        ];
+    }
+}

+ 31 - 0
app/Transformers/Circle/CircleMemberTransformer.php

@@ -0,0 +1,31 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/6
+ * Time: 14:08
+ */
+namespace App\Transformers\Circle;
+
+use App\Models\InterestCircleUser;
+use App\Models\Post;
+use App\Traits\PostTrait;
+use App\Traits\UserTrait;
+use Illuminate\Support\Carbon;
+use League\Fractal\TransformerAbstract;
+
+class CircleMemberTransformer extends TransformerAbstract
+{
+    use UserTrait;
+    public function transform(InterestCircleUser $interestCircleUser)
+    {
+        $user = $this->getShortUserInfo($interestCircleUser['uid']);
+        return [
+            'user' => $user?$user:new \stdClass(),
+            'created_at' => Carbon::parse($interestCircleUser['created_at'])->toDateTimeString(),
+            'is_black' => $interestCircleUser['is_black'],
+            'circle_id' => $interestCircleUser['circle_id']
+        ];
+    }
+}

+ 37 - 0
app/Transformers/Circle/CommentTransformer.php

@@ -0,0 +1,37 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/10
+ * Time: 10:56
+ */
+
+namespace App\Transformers\Circle;
+use App\Models\InterestCircleMessageComment;
+use Illuminate\Support\Carbon;
+use League\Fractal\TransformerAbstract;
+
+class CommentTransformer extends TransformerAbstract
+{
+    public function transform(InterestCircleMessageComment $interestCircleMessageComment)
+    {
+        if($interestCircleMessageComment['is_delete']){
+            $content = '该评论已被删除';
+        }elseif($interestCircleMessageComment['reply_username']){
+            $content = '回复 @'.subtext($interestCircleMessageComment['reply_username'], 6).': '.$interestCircleMessageComment['content'];
+        }else{
+            $content = $interestCircleMessageComment['content'];
+        }
+        return [
+            'id' => $interestCircleMessageComment['id'],
+            'msg_id' => $interestCircleMessageComment['msg_id'],
+            'parent_id' => $interestCircleMessageComment['parent_id'],
+            'uid' => $interestCircleMessageComment['uid'],
+            'username' => $interestCircleMessageComment['username'],
+            'avatar' => $interestCircleMessageComment['avatar'],
+            'content' => $content,
+            'created_at' => Carbon::parse($interestCircleMessageComment['created_at'])->toDateTimeString(),
+            'is_delete' => $interestCircleMessageComment['is_delete'],
+        ];
+    }
+}

+ 39 - 0
app/Transformers/Circle/DetailTransformer.php

@@ -0,0 +1,39 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/6
+ * Time: 14:08
+ */
+
+namespace App\Transformers\Circle;
+
+use App\Models\InterestCircle;
+use App\Traits\PostTrait;
+use Illuminate\Support\Carbon;
+use League\Fractal\TransformerAbstract;
+
+class DetailTransformer extends TransformerAbstract
+{
+    use PostTrait;
+
+    public function transform(InterestCircle $interestCircle)
+    {
+        return [
+            'id' => $interestCircle['id'],
+            'name' => $interestCircle['name'],
+            'notice' => $interestCircle['notice'],
+            'image' => $interestCircle['image'],
+            'limit_article_ids' => $interestCircle['limit_article_ids']?$this->getTopic($interestCircle['limit_article_ids'], 1):[],
+            'contains_function' => (json_decode($interestCircle['contains_function'],true)),
+            'join_limit' => $interestCircle['join_limit'],
+            'limit_condition' => $interestCircle['limit_condition'],
+            'join_question' => (json_decode($interestCircle['join_question'],true))??[],
+            'picture_count' => $interestCircle['picture_count'],
+            'article_count' => $interestCircle['article_count'],
+            'message_count' => $interestCircle['message_count'],
+            'join_count' => $interestCircle['join_count'],
+        ];
+    }
+}

+ 32 - 0
app/Transformers/Circle/InterestCirclePictureTransformer.php

@@ -0,0 +1,32 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/6
+ * Time: 14:08
+ */
+
+namespace App\Transformers\Circle;
+
+use App\Models\InterestCircle;
+use App\Models\InterestCirclePicture;
+use App\Traits\UserTrait;
+use Illuminate\Support\Carbon;
+use League\Fractal\TransformerAbstract;
+
+class InterestCirclePictureTransformer extends TransformerAbstract
+{
+    use UserTrait;
+
+    public function transform(InterestCirclePicture $interestCirclePicture)
+    {
+        $user = $this->getShortUserInfo($interestCirclePicture['uid']);
+        return [
+            'id' => $interestCirclePicture['id'],
+            'user' => $user ? $user : new \stdClass(),
+            'image' => $interestCirclePicture['image'],
+            'created_at' => Carbon::parse($interestCirclePicture['created_at'])->toDateTimeString(),
+        ];
+    }
+}

+ 32 - 0
app/Transformers/Circle/InterestCircleTransformer.php

@@ -0,0 +1,32 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/6
+ * Time: 14:08
+ */
+namespace App\Transformers\Circle;
+
+use App\Models\InterestCircle;
+use Illuminate\Support\Carbon;
+use League\Fractal\TransformerAbstract;
+
+class InterestCircleTransformer extends TransformerAbstract
+{
+    public function transform(InterestCircle $interestCircle)
+    {
+        return [
+            'id' => $interestCircle['id'],
+            'name' => $interestCircle['name'],
+            'image' => $interestCircle['image'],
+            'created_at' => Carbon::parse($interestCircle['created_at'])->toDateTimeString(),
+            'article_count' => $interestCircle['article_count'],
+            'message_count' => $interestCircle['message_count'],
+            'view_count' => $interestCircle['view_count'],
+            'join_count' => $interestCircle['join_count'],
+            'is_recommend' => $interestCircle['is_recommend'],
+            'is_open' => $interestCircle['is_open'],
+        ];
+    }
+}

+ 44 - 0
app/Transformers/Circle/MessageDetailTransformer.php

@@ -0,0 +1,44 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/6
+ * Time: 14:08
+ */
+
+namespace App\Transformers\Circle;
+
+use App\Models\InterestCircle;
+use App\Models\InterestCircleMessage;
+use App\Models\Post;
+use App\Traits\PostTrait;
+use App\Traits\UserTrait;
+use Illuminate\Support\Carbon;
+use League\Fractal\TransformerAbstract;
+
+class MessageDetailTransformer extends TransformerAbstract
+{
+    use UserTrait;
+
+    public function transform(InterestCircleMessage $interestCircleMessage)
+    {
+        $user = $this->getShortUserInfo($interestCircleMessage['uid']);
+        $imgs = $interestCircleMessage->imgs->toArray();
+        $images=[];
+        foreach($imgs as $key=>$value){
+            $images[$key]['image'] = $value['image'];
+        }
+        return [
+            'id' => $interestCircleMessage['id'],
+            'created_at' => Carbon::parse($interestCircleMessage['created_at'])->toDateTimeString(),
+            'user' => $user ? $user : new \stdClass(),
+            'good' => $interestCircleMessage['good'],
+            'bad' => $interestCircleMessage['bad'],
+            'comment_count' => $interestCircleMessage['comment_count'],
+            'content' => $interestCircleMessage['content'],
+            'imgs' => $images,
+        ];
+    }
+
+}

+ 46 - 0
app/Transformers/Circle/MessageListTransformer.php

@@ -0,0 +1,46 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/6
+ * Time: 14:08
+ */
+
+namespace App\Transformers\Circle;
+
+use App\Models\InterestCircle;
+use App\Models\InterestCircleMessage;
+use App\Models\Post;
+use App\Traits\PostTrait;
+use App\Traits\UserTrait;
+use Illuminate\Support\Carbon;
+use League\Fractal\TransformerAbstract;
+
+class MessageListTransformer extends TransformerAbstract
+{
+    use UserTrait;
+
+    public function transform(InterestCircleMessage $interestCircleMessage)
+    {
+        $user = $this->getShortUserInfo($interestCircleMessage['uid']);
+        return [
+            'id' => $interestCircleMessage['id'],
+            'created_at' => Carbon::parse($interestCircleMessage['created_at'])->toDateTimeString(),
+            'user' => $user ? $user : new \stdClass(),
+            'circle' => $this->getCircleInfo($interestCircleMessage['circle_id']),
+            'good' => $interestCircleMessage['good'],
+            'bad' => $interestCircleMessage['bad'],
+            'comment_count' => $interestCircleMessage['comment_count'],
+            'is_recommend' => $interestCircleMessage['is_recommend'],
+        ];
+    }
+
+    public function getCircleInfo($circleId)
+    {
+        $info = InterestCircle::find($circleId);
+        $circle['id'] = $info->id;
+        $circle['name'] = $info->name;
+        return $circle;
+    }
+}

+ 43 - 0
app/Transformers/Circle/PostListTransformer.php

@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/6
+ * Time: 14:08
+ */
+
+namespace App\Transformers\Circle;
+
+use App\Models\Post;
+use App\Traits\PostTrait;
+use Illuminate\Support\Carbon;
+use Illuminate\Support\Facades\Redis;
+use League\Fractal\TransformerAbstract;
+
+class PostListTransformer extends TransformerAbstract
+{
+    use PostTrait;
+
+    public function __construct($circleId)
+    {
+        $this->circle_id = $circleId;
+    }
+
+    public function transform(Post $post)
+    {
+        $key = 'circle_articles_' . $this->circle_id;
+        $isexists = Redis::zscore($key, $post['id']);
+        return [
+            'id' => $post['id'],
+            'created_at' => Carbon::parse($post['created_at'])->toDateTimeString(),
+            'uid' => $post['uid'],
+            'username' => $post['username'],
+            'topic' => $this->getTopic($post['topic_ids'], 1),
+            'content' => subtext(strip_tags($post['content']), 20),
+            'image' => $post['img'],
+            'is_exists_circle' => $isexists ? 1 : 0,
+            'circle_id' => $this->circle_id,
+        ];
+    }
+}

+ 1 - 0
app/Transformers/DetailTopicTransformer.php

@@ -31,6 +31,7 @@ class DetailTopicTransformer extends TransformerAbstract{
             'page_count' => 0,
             'created_at' => Carbon::parse($topic['created_at'])->toDateTimeString(),
             'category_list'=>$category,
+            'circle_id'=>$topic['circle_id'],
             'base_count'=>$topic['base_count'],
         ];
     }

+ 49 - 0
database/migrations/2019_10_09_055019_create_table_interest_circles.php

@@ -0,0 +1,49 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateTableInterestCircles extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('interest_circles', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->string('name', 20)->default('')->comment('圈子名称');
+            $table->string('notice')->default('')->comment('圈子公告');
+            $table->string('image')->default('')->comment('圈子主图');
+
+            $table->tinyInteger('join_limit')->default(0)->comment('进入限制 0否1是');
+            $table->tinyInteger('limit_condition')->default(0)->comment('回答限制 单位 天');
+            $table->mediumText('join_question')->comment('限制问题');
+            $table->string('limit_article_ids')->default('')->comment('收录话题限制 空为不限制');
+            $table->mediumText('contains_function')->comment('包含功能');
+            $table->integer('article_count')->default(0)->comment('圈子内容数');
+            $table->integer('message_count')->default(0)->comment('圈子留言数');
+            $table->integer('view_count')->default(0)->comment('圈子浏览数');
+            $table->integer('join_count')->default(0)->comment('圈子参与人数');
+            $table->integer('picture_count')->default(0)->comment('相册图片数');
+            $table->tinyInteger('is_recommend')->default(0)->comment('是否推荐 0未推荐1已推荐');
+            $table->tinyInteger('is_open')->default(1)->comment('开启状态 0否1是');
+
+            $table->softDeletes();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('interest_circles');
+    }
+}

+ 36 - 0
database/migrations/2019_10_09_060956_create_table_interest_circle_articles.php

@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateTableInterestCircleArticles extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('interest_circle_articles', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->integer('circle_id')->default(0)->comment('圈子ID');
+            $table->integer('post_id')->default(0)->comment('帖子ID');
+            $table->tinyInteger('is_recommend')->default(0)->comment('是否推荐 0未推荐1已推荐');
+
+            $table->softDeletes();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('interest_circle_articles');
+    }
+}

+ 36 - 0
database/migrations/2019_10_09_061333_create_interest_circle_users_table.php

@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateInterestCircleUsersTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('interest_circle_users', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->integer('circle_id')->default(0)->comment('圈子ID');
+            $table->integer('uid')->default(0)->comment('用户ID');
+            $table->tinyInteger('is_black')->default(0)->comment('是否黑名单 0否1是');
+
+            $table->softDeletes();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('interest_circle_users');
+    }
+}

+ 39 - 0
database/migrations/2019_10_09_061550_create_interest_circle_pictures_table.php

@@ -0,0 +1,39 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateInterestCirclePicturesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('interest_circle_pictures', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->integer('circle_id')->default(0)->comment('圈子ID');
+            $table->integer('uid')->default(0)->comment('用户ID');
+            $table->string('image')->default('')->comment('图片地址');
+            $table->string('patch_num')->default('')->comment('上传批次号');
+
+            $table->softDeletes();
+            $table->timestamps();
+
+            $table->index(['circle_id', 'patch_num'],'idx_search');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('interest_circle_pictures');
+    }
+}

+ 40 - 0
database/migrations/2019_10_09_061822_create_interest_circle_messages_table.php

@@ -0,0 +1,40 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateInterestCircleMessagesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('interest_circle_messages', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->integer('circle_id')->default(0)->comment('圈子ID');
+            $table->integer('uid')->default(0)->comment('用户ID');
+            $table->string('content',255)->default('')->comment('内容');
+            $table->integer('good')->default(0)->comment('顶 次数');
+            $table->integer('bad')->default(0)->comment('踩 次数');
+            $table->integer('comment_count')->default(0)->comment('评论数');
+            $table->tinyInteger('is_recommend')->default(0)->comment('是否推荐 0未推荐1已推荐');
+
+            $table->softDeletes();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('interest_circle_messages');
+    }
+}

+ 35 - 0
database/migrations/2019_10_09_062233_create_interest_circle_message_records_table.php

@@ -0,0 +1,35 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateInterestCircleMessageRecordsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('interest_circle_message_records', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->integer('uid')->default(0)->comment('用户ID');
+            $table->integer('action')->default(0)->comment('动作 1顶 -1踩');
+
+            $table->softDeletes();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('interest_circle_message_records');
+    }
+}

+ 34 - 0
database/migrations/2019_10_09_062401_create_interest_circle_message_imgs_table.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateInterestCircleMessageImgsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('interest_circle_message_imgs', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->integer('circle_id')->default(0)->comment('圈子ID');
+            $table->integer('msg_id')->default(0)->comment('留言ID');
+            $table->string('image')->default('')->comment('图片地址');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('interest_circle_message_imgs');
+    }
+}

+ 41 - 0
database/migrations/2019_10_09_062552_create_interest_circle_message_comments_table.php

@@ -0,0 +1,41 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateInterestCircleMessageCommentsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('interest_circle_message_comments', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->integer('circle_id')->default(0)->comment('圈子ID');
+            $table->integer('uid')->default(0)->comment('用户ID');
+            $table->string('username')->default('')->comment('用户名称');
+            $table->string('avatar')->default('')->comment('用户图像');
+            $table->integer('msg_id')->default(0)->comment('留言ID');
+            $table->integer('parent_id')->default(0)->comment('上级留言ID');
+            $table->integer('reply_uid')->default(0)->comment('回复ID');
+            $table->integer('reply_count')->default(0)->comment('回复数量');
+            $table->string('content')->default('')->comment('评论内容');
+            $table->tinyInteger('is_delete')->default(0)->comment('是否删除:0否,1是');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('interest_circle_message_comments');
+    }
+}

+ 35 - 0
database/migrations/2019_10_11_055646_add_column_circle_id_to_topic.php

@@ -0,0 +1,35 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddColumnCircleIdToTopic extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('topic', function (Blueprint $table) {
+            //
+            $table->integer('circle_id')
+                ->default(0)
+                ->comment('圈子ID');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('topic', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 36 - 0
database/migrations/2019_10_12_012729_add_column_is_fine_to_post.php

@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddColumnIsFineToPost extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('post', function (Blueprint $table) {
+            //
+            $table->integer('is_fine')
+                ->default(0)
+                ->comment('是否精品 0 否 1是')
+                ->after('is_hide');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('post', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 37 - 0
database/migrations/2019_10_15_103836_add_column_weight_to_interest_circle_messages.php

@@ -0,0 +1,37 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddColumnWeightToInterestCircleMessages extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('interest_circle_messages', function (Blueprint $table) {
+            //
+            $table->decimal('weight', 8, 2)
+                ->index('idx_weight')
+                ->after('is_recommend')
+                ->default(0)
+                ->comment('权重');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('interest_circle_messages', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 36 - 0
database/migrations/2019_10_15_113727_add_column_reply_username_to_interest_circle_message_comments.php

@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddColumnReplyUsernameToInterestCircleMessageComments extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('interest_circle_message_comments', function (Blueprint $table) {
+            //
+            $table->string('reply_username',32)
+                ->after('reply_uid')
+                ->default('')
+                ->comment('回复人名称');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('interest_circle_message_comments', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 36 - 0
database/migrations/2019_10_16_004919_add_column_msg_id_to_interest_circle_message_records.php

@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddColumnMsgIdToInterestCircleMessageRecords extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('interest_circle_message_records', function (Blueprint $table) {
+            //
+            $table->integer('msg_id')
+                ->after('uid')
+                ->default(0)
+                ->comment('提问id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('interest_circle_message_records', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 36 - 0
database/migrations/2019_10_16_075004_add_column_is_main_to_interest_circle_pictures.php

@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddColumnIsMainToInterestCirclePictures extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('interest_circle_pictures', function (Blueprint $table) {
+            //
+            $table->integer('is_main')
+                ->after('patch_num')
+                ->default(0)
+                ->comment('是否主数据,主要用于分页');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('interest_circle_message_pictures', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 70 - 21
routes/api.php

@@ -150,27 +150,76 @@ $api->version('v1', [
             $api->get('generalRecord/list', 'GeneralRecordController@index');
         });
 
-            //音乐分类列表
-            $api->get('music/category/list', 'MusicController@categoryList');
-            //新增音乐分类
-            $api->post('music/category/create', 'MusicController@categoryCreate');
-            //编辑音乐分类
-            $api->put('music/category/create', 'MusicController@categoryEdit');
-            //修改音乐分类状态
-            $api->put('music/category/status', 'MusicController@editStatus');
-            //删除音乐分类
-            $api->delete('music/category/delete', 'MusicController@categoryDelete');
-
-            //音乐列表
-            $api->get('music/list', 'MusicController@musicList');
-            //新建音乐
-            $api->post('music/create', 'MusicController@musicCreate');
-            //修改音乐
-            $api->put('music/create', 'MusicController@musicEdit');
-            //删除音乐
-            $api->delete('music/delete', 'MusicController@musicDelete');
-            //用户上传音乐列表
-            $api->get('music/upload/list', 'MusicController@userMusic');
+        //音乐分类列表
+        $api->get('music/category/list', 'MusicController@categoryList');
+        //新增音乐分类
+        $api->post('music/category/create', 'MusicController@categoryCreate');
+        //编辑音乐分类
+        $api->put('music/category/create', 'MusicController@categoryEdit');
+        //修改音乐分类状态
+        $api->put('music/category/status', 'MusicController@editStatus');
+        //删除音乐分类
+        $api->delete('music/category/delete', 'MusicController@categoryDelete');
+
+        //音乐列表
+        $api->get('music/list', 'MusicController@musicList');
+        //新建音乐
+        $api->post('music/create', 'MusicController@musicCreate');
+        //修改音乐
+        $api->put('music/create', 'MusicController@musicEdit');
+        //删除音乐
+        $api->delete('music/delete', 'MusicController@musicDelete');
+        //用户上传音乐列表
+        $api->get('music/upload/list', 'MusicController@userMusic');
+
+        $api->group(['namespace' => 'Circle'], function ($api) {
+            //创建圈子
+            $api->post('circle', 'CircleController@create');
+            //编辑圈子
+            $api->put('circle', 'CircleController@update');
+            //圈子列表
+            $api->get('circle', 'CircleController@index');
+            //查询圈子信息
+            $api->get('circle/detail', 'CircleController@detail');
+            //推荐圈子
+            $api->put('circle/recommend', 'CircleController@recommend');
+            //开启/关闭圈子
+            $api->put('circle/status', 'CircleController@circleStatus');
+            //圈子相册列表
+            $api->get('circle/pictures', 'CircleController@pictureList');
+            //删除相册图片
+            $api->delete('circle/picture', 'CircleController@deletePicture');
+            //圈子精品文章列表
+            $api->get('circle/articles', 'CircleController@articleList');
+            //圈子精品文章来源帖子列表3
+            $api->get('circle/posts', 'CircleController@postList');
+            //推荐精品文章
+            $api->put('circle/article/recommend', 'CircleController@articleRecommend');
+            //移出精品文章
+            $api->delete('circle/article', 'CircleController@articleRemove');
+            //加入精品文章
+            $api->post('circle/article', 'CircleController@articleInsert');
+            //圈子用户列表
+            $api->get('circle/members', 'CircleController@memberList');
+            //设置圈子用户黑名单
+            $api->put('circle/member/black', 'CircleController@setCircleBlack');
+            //圈子留言列表
+            $api->get('circle/messages', 'CircleController@messageList');
+            //圈子留言详情
+            $api->get('circle/message', 'CircleController@messageDetail');
+            //圈子留言推荐
+            $api->put('circle/message/recommend', 'CircleController@messageRecommend');
+            //圈子留言删除
+            $api->delete('circle/message', 'CircleController@deleteMessage');
+            //圈子留言评论列表
+            $api->get('circle/message/comments', 'CircleController@commentList');
+            //圈子留言评论删除
+            $api->delete('circle/message/comment', 'CircleController@commentDelete');
+        });
+    });
+
+    $api->group(['namespace' => 'Circle'], function ($api) {
+        $api->post('circle/article2', 'CircleController@articleInsert');
     });
 
 });