|
@@ -0,0 +1,512 @@
|
|
|
+<?php
|
|
|
+/**
|
|
|
+ * Created by PhpStorm.
|
|
|
+ * User: Administrator
|
|
|
+ * Date: 2019/6/14
|
|
|
+ * Time: 16:23
|
|
|
+ */
|
|
|
+
|
|
|
+namespace App\Http\Controllers\V1;
|
|
|
+
|
|
|
+use Illuminate\Http\Request;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
+use Illuminate\Support\Facades\Redis;
|
|
|
+use Illuminate\Support\Facades\Validator;
|
|
|
+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()
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发布内容
|
|
|
+ */
|
|
|
+ public function create(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'type' => ['required', Rule::in('image', 'video', 'html')],
|
|
|
+ 'img' => 'required|url',
|
|
|
+ 'video' => 'required_if:type,video|string',
|
|
|
+ 'topic_ids' => 'required|string|max:64',
|
|
|
+ 'title' => 'nullable|string|max:20',
|
|
|
+ 'content' => 'required|string|max:1000',
|
|
|
+ 'location' => 'nullable|string|max:32',
|
|
|
+ 'imgs' => 'required_if:type,image|string',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return jsonError($validator->errors()->first());
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->postRepositories->create($request->all());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 评论&回复
|
|
|
+ */
|
|
|
+ public function comment(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'post_id' => 'required|integer',
|
|
|
+ 'content' => 'required|string|max:150',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return jsonError($validator->errors()->first());
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->postRepositories->comment($request->all());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除评论
|
|
|
+ */
|
|
|
+ public function commentDelete(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'id' => 'required|integer',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return jsonError($validator->errors()->first());
|
|
|
+ }
|
|
|
+ return $this->postRepositories->commentDelete($request->all());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 内容列表
|
|
|
+ */
|
|
|
+ public function index(Request $request)
|
|
|
+ {
|
|
|
+ Log::debug('内容搜索' . json_encode($request));
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
+ if ($userInfo) {
|
|
|
+ $uid = $userInfo['uid'];
|
|
|
+ $inviteCode = $userInfo['invite_code'];
|
|
|
+ }else{
|
|
|
+ $uid = 0;
|
|
|
+ $inviteCode = '';
|
|
|
+ }
|
|
|
+ $list = $this->postRepositories->lists($request->all());
|
|
|
+ $fractal = new Manager();
|
|
|
+ $resource = new Collection($list, new ListTransformer($uid, $inviteCode));
|
|
|
+ $resource->setPaginator(new IlluminatePaginatorAdapter($list));
|
|
|
+ $data = $fractal->createData($resource)->toArray();
|
|
|
+
|
|
|
+ return jsonSuccess($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 视频列表
|
|
|
+ */
|
|
|
+ public function video(Request $request)
|
|
|
+ {
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
+ if ($userInfo) {
|
|
|
+ $uid = $userInfo['uid'];
|
|
|
+ $inviteCode = $userInfo['invite_code'];
|
|
|
+ }else{
|
|
|
+ $uid = 0;
|
|
|
+ $inviteCode = '';
|
|
|
+ }
|
|
|
+ $list = $this->postRepositories->video($request->all());
|
|
|
+ $fractal = new Manager();
|
|
|
+ $resource = new Collection($list, new VideoTransformer($uid, $inviteCode));
|
|
|
+ $resource->setPaginator(new IlluminatePaginatorAdapter($list));
|
|
|
+ $data = $fractal->createData($resource)->toArray();
|
|
|
+
|
|
|
+ return jsonSuccess($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 个人中心内容
|
|
|
+ */
|
|
|
+ public function myPost(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'type' => ['required', Rule::in('create', 'collect', 'share')],
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return jsonError($validator->errors()->first());
|
|
|
+ }
|
|
|
+
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
+ if (empty($userInfo)) {
|
|
|
+ Log::debug('获取用户信息失败myPost'.json_encode($request));
|
|
|
+ return jsonError('获取用户信息失败');
|
|
|
+ }
|
|
|
+ $param = $request->all();
|
|
|
+ if (isset($param['uid'])) {
|
|
|
+ $uid = $param['uid'];
|
|
|
+ } else {
|
|
|
+ $uid = $userInfo['uid'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $list = $this->postRepositories->myPost($param, $uid);
|
|
|
+ $fractal = new Manager();
|
|
|
+ $resource = new Collection($list, new MyTransformer());
|
|
|
+ $resource->setPaginator(new IlluminatePaginatorAdapter($list));
|
|
|
+ $data = $fractal->createData($resource)->toArray();
|
|
|
+
|
|
|
+ return jsonSuccess($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 推荐内容列表
|
|
|
+ */
|
|
|
+ public function suggestPost(Request $request)
|
|
|
+ {
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
+ if ($userInfo) {
|
|
|
+ $uid = $userInfo['uid'];
|
|
|
+ $inviteCode = $userInfo['invite_code'];
|
|
|
+ }else{
|
|
|
+ $uid = 0;
|
|
|
+ $inviteCode = '';
|
|
|
+ }
|
|
|
+
|
|
|
+ $param = $request->all();
|
|
|
+ $list = $this->postRepositories->suggestPost($param,$uid);
|
|
|
+ $fractal = new Manager();
|
|
|
+ $resource = new Collection($list, new SuggestTransformer($uid, $inviteCode));
|
|
|
+ $resource->setPaginator(new IlluminatePaginatorAdapter($list));
|
|
|
+ $data = $fractal->createData($resource)->toArray();
|
|
|
+
|
|
|
+ if (!(isset($param['page']) && $param['page'] > 1) && !(isset($param['category_id']) && $param['category_id'])) {
|
|
|
+ $key = 'suggest_post_floor';
|
|
|
+ $floor = Redis::get($key);
|
|
|
+ if (!$floor) {
|
|
|
+ $floor = $this->getFloorInfo();
|
|
|
+ if ($floor) {
|
|
|
+ Redis::set($key, json_encode($floor));
|
|
|
+ Redis::expire($key, 600);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ $floor = json_decode($floor, true);
|
|
|
+ }
|
|
|
+ if ($floor) {
|
|
|
+ $newData = [];
|
|
|
+ foreach ($data['data'] as $key => $val) {
|
|
|
+ if (isset($floor[$key + 1])) {
|
|
|
+ if ($floor[$key + 1]['show_type'] == 'banner') {
|
|
|
+ $bannerData = [];
|
|
|
+ foreach ($floor[$key + 1]['data'] as $item) {
|
|
|
+ if ($item['type'] == 1) {
|
|
|
+ $postInfo = $this->getPostInfo($item['link_content_id'], 1);
|
|
|
+ if (!$postInfo || !$postInfo['type']) {
|
|
|
+ Log::info('banner类型为内容,未找到内容,被丢弃' . json_encode($item));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $bannerData[] = array_merge($item, ['post_type' => $postInfo['type']]);
|
|
|
+ } else {
|
|
|
+ $bannerData[] = $item;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $newData[] = [
|
|
|
+ 'show_type' => 'banner',
|
|
|
+ 'data' => $bannerData,
|
|
|
+ ];
|
|
|
+ } elseif ($floor[$key + 1]['show_type'] == 'user') {
|
|
|
+ $userData = [];
|
|
|
+ foreach ($floor[$key + 1]['data'] as $item) {
|
|
|
+ $followStatus = $uid ? $this->getFollowStatus($userInfo['uid'], $item['uid']) : 0;
|
|
|
+ $userData[] = array_merge($item, ['follow_status' => $followStatus]);
|
|
|
+ }
|
|
|
+ if ($userData) {
|
|
|
+ $newData[] = [
|
|
|
+ 'show_type' => 'user',
|
|
|
+ 'data' => $userData,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ } elseif ($floor[$key + 1]['show_type'] == 'video') {
|
|
|
+ $newData[] = [
|
|
|
+ 'show_type' => 'video',
|
|
|
+ 'data' => $floor[$key + 1]['data'],
|
|
|
+ ];
|
|
|
+ } elseif ($floor[$key + 1]['show_type'] == 'topic') {
|
|
|
+ $newData[] = [
|
|
|
+ 'show_type' => 'topic',
|
|
|
+ 'data' => $floor[$key + 1]['data'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $newData[] = $val;
|
|
|
+ }
|
|
|
+ $data['data'] = $newData;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return jsonSuccess($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 内容详情
|
|
|
+ */
|
|
|
+ public function detail(Request $request)
|
|
|
+ {
|
|
|
+ Log::debug("内容详情-参数".json_encode($request));
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'id' => 'required|integer',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return jsonError($validator->errors()->first());
|
|
|
+ }
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
+ if ($userInfo) {
|
|
|
+ $uid = $userInfo['uid'];
|
|
|
+ $inviteCode = $userInfo['invite_code'];
|
|
|
+ }else{
|
|
|
+ $uid = 0;
|
|
|
+ $inviteCode = '';
|
|
|
+ }
|
|
|
+ $detail = $this->postRepositories->detail($request['id']);
|
|
|
+ if (!$detail) {
|
|
|
+ return jsonError('内容飞走了');
|
|
|
+ }
|
|
|
+ $fractal = new Manager();
|
|
|
+ $res = new Item($detail, new DetailTransformer($uid, $inviteCode));
|
|
|
+ $data = $fractal->createData($res)->toArray();
|
|
|
+
|
|
|
+ return jsonSuccess($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 评论列表
|
|
|
+ */
|
|
|
+ public function commentList(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'post_id' => 'required|integer',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return jsonError($validator->errors()->first());
|
|
|
+ }
|
|
|
+ $exists = $this->postRepositories->detailExists($request['post_id']);
|
|
|
+ if (!$exists) {
|
|
|
+ return jsonError('内容飞走了');
|
|
|
+ }
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
+ if ($userInfo) {
|
|
|
+ $uid = $userInfo['uid'];
|
|
|
+ }else{
|
|
|
+ $uid = 0;
|
|
|
+ }
|
|
|
+ $list = $this->postRepositories->commentList($request->all());
|
|
|
+ $fractal = new Manager();
|
|
|
+ $resource = new Collection($list, new CommentTransformer($request['post_id'], $uid));
|
|
|
+ $resource->setPaginator(new IlluminatePaginatorAdapter($list));
|
|
|
+ $data = $fractal->createData($resource)->toArray();
|
|
|
+
|
|
|
+ $commentCount = $this->postRepositories->getCommentCount($request['post_id']);
|
|
|
+ return jsonSuccess($data, '成功', ['comment_count' => $commentCount]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 回复列表
|
|
|
+ */
|
|
|
+ public function replyList(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'id' => 'required|exists:post_comment',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return jsonError($validator->errors()->first());
|
|
|
+ }
|
|
|
+
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
+ if ($userInfo) {
|
|
|
+ $uid = $userInfo['uid'];
|
|
|
+ }else{
|
|
|
+ $uid = 0;
|
|
|
+ }
|
|
|
+ $postId = $this->postRepositories->getPostId($request['id']);
|
|
|
+ $list = $this->postRepositories->replyList($request->all());
|
|
|
+ $fractal = new Manager();
|
|
|
+ $resource = new Collection($list, new ReplyTransformer($postId, $uid));
|
|
|
+ $resource->setPaginator(new IlluminatePaginatorAdapter($list));
|
|
|
+ $data = $fractal->createData($resource)->toArray();
|
|
|
+
|
|
|
+ return jsonSuccess($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 话题列表
|
|
|
+ */
|
|
|
+ public function topicList(Request $request)
|
|
|
+ {
|
|
|
+ $fractal = new Manager();
|
|
|
+ $param = $request->all();
|
|
|
+ if(isset($param['category_id']) && $param['category_id'] == -1){
|
|
|
+ $list = $this->postRepositories->myTopicList($request->all());
|
|
|
+ $resource = new Collection($list, new MyTopicListTransformer());
|
|
|
+ $resource->setPaginator(new IlluminatePaginatorAdapter($list));
|
|
|
+ }else{
|
|
|
+ $list = $this->postRepositories->topicList($request->all());
|
|
|
+ $resource = new Collection($list, new TopicListTransformer());
|
|
|
+ $resource->setPaginator(new IlluminatePaginatorAdapter($list));
|
|
|
+ }
|
|
|
+ $data = $fractal->createData($resource)->toArray();
|
|
|
+
|
|
|
+ return jsonSuccess($data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 话题详情
|
|
|
+ */
|
|
|
+ public function topicDetail(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'id' => 'required|integer',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return jsonError($validator->errors()->first());
|
|
|
+ }
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
+ if ($userInfo) {
|
|
|
+ $uid = $userInfo['uid'];
|
|
|
+ }else{
|
|
|
+ $uid = 0;
|
|
|
+ }
|
|
|
+ $detail = $this->postRepositories->topicDetail($request['id']);
|
|
|
+ if (!$detail) {
|
|
|
+ return jsonError('获取话题信息失败');
|
|
|
+ }
|
|
|
+ $fractal = new Manager();
|
|
|
+ $res = new Item($detail, new TopicDetailTransformer($uid));
|
|
|
+ $data = $fractal->createData($res)->toArray();
|
|
|
+
|
|
|
+ return jsonSuccess($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 话题内容列表
|
|
|
+ */
|
|
|
+ public function topicPost(Request $request)
|
|
|
+ {
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
+ if ($userInfo) {
|
|
|
+ $uid = $userInfo['uid'];
|
|
|
+ $inviteCode = $userInfo['invite_code'];
|
|
|
+ }else{
|
|
|
+ $uid = 0;
|
|
|
+ $inviteCode = '';
|
|
|
+ }
|
|
|
+ $list = $this->postRepositories->topicPost($request->all());
|
|
|
+ $fractal = new Manager();
|
|
|
+ $resource = new Collection($list, new TopicPostTransformer($uid, $inviteCode));
|
|
|
+ $resource->setPaginator(new IlluminatePaginatorAdapter($list));
|
|
|
+ $data = $fractal->createData($resource)->toArray();
|
|
|
+
|
|
|
+ return jsonSuccess($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取话题
|
|
|
+ */
|
|
|
+ public function getTopic(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'ids' => 'required|string',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return jsonError($validator->errors()->first());
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $this->postRepositories->getTopic($request['ids']);
|
|
|
+ return jsonSuccess($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取内容视频组
|
|
|
+ */
|
|
|
+ public function getPostVideo(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'ids' => 'required|string',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return jsonError($validator->errors()->first());
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $this->postRepositories->getPostVideo($request['ids']);
|
|
|
+ return jsonSuccess($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户内容数统计
|
|
|
+ public function memberPostStatistics(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'uid' => 'required|int',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return jsonError($validator->errors()->first());
|
|
|
+ }
|
|
|
+ return $this->postRepositories->memberPostStatistics($request['uid']);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除内容
|
|
|
+ */
|
|
|
+ public function delete(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'id' => 'required|integer',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return jsonError($validator->errors()->first());
|
|
|
+ }
|
|
|
+ return $this->postRepositories->delete($request->all());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询帖子内容详情(内部接口使用)
|
|
|
+ */
|
|
|
+ public function find(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'id' => 'required|integer',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return jsonError($validator->errors()->first());
|
|
|
+ }
|
|
|
+ $detail = $this->postRepositories->detail($request['id']);
|
|
|
+ if (!$detail) {
|
|
|
+ return jsonError('获取内容信息失败');
|
|
|
+ }
|
|
|
+ $fractal = new Manager();
|
|
|
+ $res = new Item($detail, new PostTransformer());
|
|
|
+ $data = $fractal->createData($res)->toArray();
|
|
|
+ return jsonSuccess($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 图片验证
|
|
|
+ */
|
|
|
+ public function checkImage(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'image' => 'required|url',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return jsonError($validator->errors()->first());
|
|
|
+ }
|
|
|
+ $res = $this->postRepositories->checkImage($request['image']);
|
|
|
+
|
|
|
+ return jsonSuccess($res);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载量
|
|
|
+ */
|
|
|
+ public function downloadCount()
|
|
|
+ {
|
|
|
+ Redis::INCRBY('app_h5_download_count', 1);
|
|
|
+ return jsonSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|