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