|
@@ -11,8 +11,10 @@ namespace App\Http\Controllers\V1;
|
|
|
use App\Repositories\PostRepositories;
|
|
|
use App\Traits\UserTrait;
|
|
|
use App\Transformers\Post\CommentTransformer;
|
|
|
+use App\Transformers\Post\ReplyTransformer;
|
|
|
use App\Transformers\Post\SuggestTransformer;
|
|
|
use Illuminate\Http\Request;
|
|
|
+use Illuminate\Support\Carbon;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
use Illuminate\Validation\Rule;
|
|
@@ -40,10 +42,10 @@ class PostController extends Controller
|
|
|
return jsonError('获取用户信息失败');
|
|
|
}
|
|
|
$param = $request->all();
|
|
|
- $purchaseList = $this->postRepositories->suggestPost($param);
|
|
|
+ $list = $this->postRepositories->suggestPost($param);
|
|
|
$fractal = new Manager();
|
|
|
- $resource = new Collection($purchaseList, new SuggestTransformer($userInfo['uid']));
|
|
|
- $resource->setPaginator(new IlluminatePaginatorAdapter($purchaseList));
|
|
|
+ $resource = new Collection($list, new SuggestTransformer($userInfo['uid']));
|
|
|
+ $resource->setPaginator(new IlluminatePaginatorAdapter($list));
|
|
|
$data = $fractal->createData($resource)->toArray();
|
|
|
|
|
|
if(!(isset($param['current_page']) && $param['current_page'] > 1)){
|
|
@@ -70,12 +72,45 @@ class PostController extends Controller
|
|
|
if ($validator->fails()) {
|
|
|
return jsonError($validator->errors()->first());
|
|
|
}
|
|
|
- $purchaseList = $this->postRepositories->commentList($request->all());
|
|
|
+ $list = $this->postRepositories->commentList($request->all());
|
|
|
$fractal = new Manager();
|
|
|
- $resource = new Collection($purchaseList, new CommentTransformer());
|
|
|
- $resource->setPaginator(new IlluminatePaginatorAdapter($purchaseList));
|
|
|
+ $resource = new Collection($list, new CommentTransformer());
|
|
|
+ $resource->setPaginator(new IlluminatePaginatorAdapter($list));
|
|
|
$data = $fractal->createData($resource)->toArray();
|
|
|
|
|
|
return jsonSuccess($data);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 回复列表
|
|
|
+ */
|
|
|
+ public function replyList(Request $request)
|
|
|
+ {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'id' => 'required|integer',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return jsonError($validator->errors()->first());
|
|
|
+ }
|
|
|
+ $detail = $this->postRepositories->commentDetail($request->all());
|
|
|
+ if(!$detail){
|
|
|
+ return jsonError('获取评论信息失败');
|
|
|
+ }
|
|
|
+ $list = $this->postRepositories->replyList($request->all());
|
|
|
+ $fractal = new Manager();
|
|
|
+ $resource = new Collection($list, new ReplyTransformer());
|
|
|
+ $resource->setPaginator(new IlluminatePaginatorAdapter($list));
|
|
|
+ $data = $fractal->createData($resource)->toArray();
|
|
|
+
|
|
|
+ $data['data']['extra'] = [
|
|
|
+ 'id' => $detail['id'],
|
|
|
+ 'uid' => $detail['uid'],
|
|
|
+ 'username' => $detail['username'],
|
|
|
+ 'reply_count' => $detail->reply->count(),
|
|
|
+ 'avatar' => $detail['avatar'],
|
|
|
+ 'content' => $detail['is_delete']?'该评论已被删除':$detail['content'],
|
|
|
+ 'created_at' => Carbon::parse($detail['created_at'])->diffForHumans(),
|
|
|
+ ];
|
|
|
+ return jsonSuccess($data);
|
|
|
+ }
|
|
|
}
|