From b258e7ff6367cc7e3788dee4231e777e8bc0c9b1 Mon Sep 17 00:00:00 2001 From: tensent Date: Tue, 20 Oct 2020 17:34:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 5 +++-- app/controller/api/Content.php | 37 +++++++++++++++++++++++++++++++++- app/http/middleware/Api.php | 2 +- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/app/common.php b/app/common.php index 9dfd5f18..12919a5f 100755 --- a/app/common.php +++ b/app/common.php @@ -260,9 +260,10 @@ function get_attach($id, $field = false, $is_list = false) { } else { $map[] = ['id', '=', $id]; $picture = \app\model\Attach::where($map)->find(); + $picture['url'] = $basePath . $picture['url']; if ($field == 'path') { - if (!empty($picture['url'])) { - $picture['path'] = $picture['url'] ? $basePath . $picture['url'] : $basePath . '/static/common/images/default.png'; + if ($picture['path'] == '') { + $picture['path'] = $picture['url'] ? $picture['url'] : $basePath . '/static/common/images/default.png'; } else { $picture['path'] = $picture['path'] ? $basePath . $picture['path'] : $basePath . '/static/common/images/default.png'; } diff --git a/app/controller/api/Content.php b/app/controller/api/Content.php index dd7109f9..d9f31fc8 100644 --- a/app/controller/api/Content.php +++ b/app/controller/api/Content.php @@ -18,6 +18,12 @@ use app\model\Attribute; */ class Content extends Base { + public $middleware = [ + '\app\http\middleware\Validate', + '\app\http\middleware\ApiAuth' => ['except' => ['lists', 'detail', 'category']], + '\app\http\middleware\Api', + ]; + public $modelInfo = []; public $model = null; @@ -41,8 +47,16 @@ class Content extends Base { if (isset($param['keyword']) && $param['keyword'] != '') { $map[] = ['title', 'LIKE', '%'.$param['keyword'].'%']; } + if (isset($param['category_id']) && $param['category_id']) { + $map[] = ['category_id', '=', $param['category_id']]; + } - $list = $this->model->where($map)->order($order)->paginate($this->request->pageConfig); + $list = $this->model->where($map)->order($order)->paginate($this->request->pageConfig)->each(function($item) { + if(isset($item['cover_id'])){ + $item['cover'] = get_attach($item['cover_id'], 'url'); + return $item; + } + }); $this->data['code'] = 1; $this->data['data'] = $list; return $this->data; @@ -64,6 +78,27 @@ class Content extends Base { return $this->data; } + /** + * @title 栏目列表 + * @method GET + * @return [json] + */ + public function category(){ + $param = $this->request->param(); + $map = []; + + $map[] = ['model_id', '=', $this->modelInfo['id']]; + if(isset($param['pid']) && $param['pid']){ + $map[] = ['pid', '=', $param['pid']]; + } + + $list = Category::where($map)->select(); + + $this->data['code'] = 1; + $this->data['data'] = $list; + return $this->data; + } + /** * @title 添加内容 * @method POST diff --git a/app/http/middleware/Api.php b/app/http/middleware/Api.php index 014e1102..e5a75ab3 100644 --- a/app/http/middleware/Api.php +++ b/app/http/middleware/Api.php @@ -21,7 +21,7 @@ class Api { public function handle($request, \Closure $next) { $request->pageConfig = array( 'list_rows' => $request->param('limit', 30), - 'page' => $request->param('page', 1), + 'page' => $request->param('page', 1), ); $this->cacheData($request); //缓存基础数据 $response = $next($request);