Procházet zdrojové kódy

Merge branch 'circle' into develop

xielin před 5 roky
rodič
revize
401cbe5d17
24 změnil soubory, kde provedl 1445 přidání a 0 odebrání
  1. 501 0
      app/Http/Controllers/Circle/CircleController.php
  2. 20 0
      app/Models/InterestCircle.php
  3. 19 0
      app/Models/InterestCircleArticle.php
  4. 25 0
      app/Models/InterestCircleMessage.php
  5. 17 0
      app/Models/InterestCircleMessageComment.php
  6. 20 0
      app/Models/InterestCircleMessageImg.php
  7. 17 0
      app/Models/InterestCircleMessageRecord.php
  8. 19 0
      app/Models/InterestCirclePicture.php
  9. 19 0
      app/Models/InterestCircleUser.php
  10. 63 0
      app/Repositories/Circle/CircleArticleRepository.php
  11. 251 0
      app/Repositories/Circle/CircleRepository.php
  12. 12 0
      app/Traits/UserTrait.php
  13. 39 0
      app/Transformers/Circle/DetailTransformer.php
  14. 32 0
      app/Transformers/Circle/InterestCirclePictureTransformer.php
  15. 32 0
      app/Transformers/Circle/InterestCircleTransformer.php
  16. 49 0
      database/migrations/2019_10_09_055019_create_table_interest_circles.php
  17. 36 0
      database/migrations/2019_10_09_060956_create_table_interest_circle_articles.php
  18. 36 0
      database/migrations/2019_10_09_061333_create_interest_circle_users_table.php
  19. 39 0
      database/migrations/2019_10_09_061550_create_interest_circle_pictures_table.php
  20. 40 0
      database/migrations/2019_10_09_061822_create_interest_circle_messages_table.php
  21. 35 0
      database/migrations/2019_10_09_062233_create_interest_circle_message_records_table.php
  22. 33 0
      database/migrations/2019_10_09_062401_create_interest_circle_message_imgs_table.php
  23. 39 0
      database/migrations/2019_10_09_062552_create_interest_circle_message_comments_table.php
  24. 52 0
      routes/api.php

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

@@ -0,0 +1,501 @@
+<?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\CircleRepository;
+use App\Transformers\Circle\DetailTransformer;
+use App\Transformers\Circle\InterestCirclePictureTransformer;
+use App\Transformers\Circle\InterestCircleTransformer;
+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)
+    {
+        $this->circleRepository = $circleRepository;
+        $this->circleArticleRepository = $circleArticleRepository;
+    }
+
+    /**
+     * 创建圈子
+     */
+    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)
+    {
+        $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)
+    {
+        $articleList = $this->circleArticleRepository->lists($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($articleList, new InterestCircleTransformer());
+        $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 commentList(Request $request)
+    {
+        $commentList = $this->postRepository->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',
+                'post_id',
+                'parent_id',
+                'uid',
+                'content',
+                'like_count',
+                'created_at',
+                'is_delete',
+            ]
+        ];
+        return $data;
+    }
+
+
+    /**
+     * 评论&回复
+     */
+    public function comment(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'post_id' => 'required|integer',
+            'uid' => 'required|integer',
+            'content' => 'required|string|max:150',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->postRepository->comment($request->all());
+    }
+
+    /**
+     * 增加数据
+     */
+    public function addData(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'post_id' => 'required|exists:post,id',
+            'add_pv' => 'required|integer|min:0',
+            'add_praise_count' => 'required|integer|min:0',
+            'add_collect_count' => 'required|integer|min:0',
+            'add_share_count' => 'required|integer|min:0',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->postRepository->addData($request->all());
+    }
+
+    /**
+     * 推荐内容
+     */
+    public function suggest(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|integer',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->postRepository->suggest($request->all());
+    }
+
+    /**
+     * 删除内容
+     */
+    public function delete(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|integer',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->postRepository->delete($request->all());
+    }
+
+    /**
+     * 复原内容
+     */
+    public function restore(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|integer',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->postRepository->restore($request->all());
+    }
+
+    /**
+     * 删除评论
+     */
+    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->postRepository->commentDelete($request->all());
+    }
+
+    /**
+     * 隐藏内容
+     */
+    public function hide(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|integer',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->postRepository->hide($request->all());
+    }
+
+    /**
+     * 日志列表
+     */
+    public function log(Request $request)
+    {
+        $commentList = $this->postRepository->log($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($commentList, new LogTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($commentList));
+        $data = $fractal->createData($resource)->toArray();
+
+        $data['extra'] = [
+            'filters' => [
+                'log_type',
+                'created_at',
+            ],
+            'columns' => [
+                'id',
+                'username',
+                'log_type',
+                'created_at',
+                'content',
+            ]
+        ];
+        return $data;
+    }
+
+    public function statistics(Request $request)
+    {
+        $request = $request->all();
+        $start = Carbon::parse(!empty($request['start']) ? Carbon::parse($request['start'])->startOfDay()->toDateTimeString() : Carbon::yesterday())->startOfDay()->toDateTimeString();
+        $end = Carbon::parse(!empty($request['end']) ? Carbon::parse($request['end'])->endOfDay()->toDateTimeString() : Carbon::yesterday())->endOfDay()->toDateTimeString();
+        return $this->postRepository->statistics($start, $end);
+    }
+
+    /**
+     * 编辑内容话题
+     */
+    public function updateTopic(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|integer',
+            'topic_ids' => 'required|string|max:64',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->postRepository->updateTopic($request->all());
+    }
+
+    /**
+     * 获取网站内容
+     */
+    public function createStore(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'start_page' => 'required|integer',
+            'end_page' => 'required|integer',
+            'size' => 'required|integer',
+            'category_id' => 'required|integer',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+
+        return $this->postRepository->createStore($request['start_page'], $request['end_page'], $request['size'], $request['category_id']);
+    }
+
+    /**
+     * 获取网站内容
+     */
+    public function getStore(Request $request)
+    {
+        $productList = $this->postRepository->getStore($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($productList, new PostStoreTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($productList));
+        $data = $fractal->createData($resource)->toArray();
+        $data['extra'] = [
+            'filters' => [
+                'type',
+                'category_id',
+                'title',
+                'content',
+                'source',
+                'is_used',
+            ],
+            'columns' => [
+                'id',
+                'source',
+                'type',
+                'category_id',
+                'title',
+                'content',
+                'img',
+                'is_used',
+                'created_at',
+            ]
+        ];
+        return $data;
+    }
+
+    /**
+     * 网站内容详情
+     */
+    public function getStoreDetail(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|exists:post_store'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+
+        $post = $this->postRepository->getStoreDetail($request->all());
+        return $this->response->item($post, new StoreDetailTransformer());
+    }
+
+    /**
+     * 内容列表(批量替换话题)
+     */
+    public function topicList(Request $request)
+    {
+        $productList = $this->postRepository->topicList($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($productList, new PostTopicTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($productList));
+        $data = $fractal->createData($resource)->toArray();
+        $data['extra'] = [
+            'filters' => [
+                'topic_id'
+            ],
+            'columns' => [
+                'id',
+                'created_at',
+                'uid',
+                'topic',
+                'img',
+                'content',
+            ]
+        ];
+        return $data;
+    }
+
+    /**
+     * 批量替换话题
+     */
+    public function TopicUpdate(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'topic_id' => 'required|integer',
+            'to_topic_id' => 'required|integer',
+            'ids' => 'required|array',
+            'ids.*' => 'required|integer',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return $this->postRepository->TopicUpdate($request->all());
+    }
+}

+ 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', 'circle_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 = [];
+}

+ 19 - 0
app/Models/InterestCirclePicture.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 InterestCirclePicture extends Model
+{
+    //
+    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 = [];
+
+}

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

@@ -0,0 +1,63 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/5
+ * Time: 16:03
+ */
+
+namespace App\Repositories\Circle;
+
+use App\Models\InterestCircleArticle;
+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)
+    {
+        $this->interestCircleArticle = $interestCircleArticle;
+    }
+
+    /**
+     * 内容列表
+     */
+    public function lists($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+        $where = [];
+
+        if (isset($request['uid'])) {
+            $where[] = ['uid', $request['uid']];
+        }
+
+        $articleModel = $this->interestCircleArticle;
+
+        return $articleModel
+            ->join('post', 'post.id', '=', 'post_id')
+            ->join('post_data', 'post_data.post_id', '=', 'post.id')
+            ->with('data')
+            ->select('post.*')
+            ->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);
+    }
+}

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

@@ -0,0 +1,251 @@
+<?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' => $request['join_question'] ?? '',
+            'limit_article_ids' => $request['limit_article_ids'] ?? '',
+            'contains_function' => $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' => $request['join_question'] ?? '',
+            'limit_article_ids' => $request['limit_article_ids'] ?? '',
+            'contains_function' => $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();
+            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
+            ]);
+        }
+    }
+}

+ 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';

+ 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'],
+        ];
+    }
+}

+ 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');
+    }
+}

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

@@ -0,0 +1,33 @@
+<?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->string('image')->default('')->comment('图片地址');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('interest_circle_message_imgs');
+    }
+}

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

@@ -0,0 +1,39 @@
+<?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->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');
+    }
+}

+ 52 - 0
routes/api.php

@@ -173,4 +173,56 @@ $api->version('v1', [
             $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/delete', 'CircleController@deletePicture');
+        //圈子精品文章列表
+        $api->get('circle/articles', 'CircleController@articleList');
+
+        //推荐内容
+        $api->put('circle/suggest', 'PostController@suggest');
+
+        //隐藏内容
+        $api->put('circle/hide', 'PostController@hide');
+
+        //增加数据
+        $api->put('circle/addData', 'PostController@addData');
+
+        //评论列表
+        $api->get('circle/comment', 'PostController@commentList');
+        //评论&回复
+        $api->post('circle/comment', 'PostController@comment');
+        //删除评论
+        $api->delete('circle/comment/delete', 'PostController@commentDelete');
+
+        //回收站列表
+        $api->get('circle/waste', 'PostController@waste');
+        //回收站复原
+        $api->put('circle/waste', 'PostController@restore');
+
+        //日志列表
+        $api->get('circle/log', 'PostController@log');
+
+        //添加网站内容
+        $api->post('circle/store', 'PostController@createStore');
+        //获取网站内容
+        $api->get('circle/store', 'PostController@getStore');
+        //网站内容详情
+        $api->get('circle/store/detail', 'PostController@getStoreDetail');
+
+    });
 });