产品
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\model\Post;
|
||||
use app\common\model\PostComment;
|
||||
use app\common\model\User;
|
||||
use app\common\service\OssService;
|
||||
@@ -19,6 +20,34 @@ class PostCommentController extends BaseController
|
||||
{
|
||||
$this->service = new PostCommentService();
|
||||
}
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return mixed 返回分页数据及总数
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$scene = $request->get('scene');
|
||||
$raw = $this->service->serviceList($request);
|
||||
$data = $this->transformData($raw, method_exists($this, 'indexFormat')
|
||||
? [$this, 'indexFormat']
|
||||
: null);
|
||||
$records = $data['records'];
|
||||
|
||||
if($scene == 'self'){
|
||||
foreach ($records as $k=>$record){
|
||||
$record['parent'] = PostComment::where('id',$record['parent_id'])->value('content');
|
||||
$record['post'] = Post::where('id',$record['post_id'])->first();
|
||||
$record['post']['user'] = User::where('id',$record['post']['user_id'])->first();
|
||||
}
|
||||
}
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
|
||||
Reference in New Issue
Block a user