修改接口类

This commit is contained in:
2020-10-20 17:34:42 +08:00
parent eaa683a4bb
commit b258e7ff63
3 changed files with 40 additions and 4 deletions

View File

@@ -260,9 +260,10 @@ function get_attach($id, $field = false, $is_list = false) {
} else { } else {
$map[] = ['id', '=', $id]; $map[] = ['id', '=', $id];
$picture = \app\model\Attach::where($map)->find(); $picture = \app\model\Attach::where($map)->find();
$picture['url'] = $basePath . $picture['url'];
if ($field == 'path') { if ($field == 'path') {
if (!empty($picture['url'])) { if ($picture['path'] == '') {
$picture['path'] = $picture['url'] ? $basePath . $picture['url'] : $basePath . '/static/common/images/default.png'; $picture['path'] = $picture['url'] ? $picture['url'] : $basePath . '/static/common/images/default.png';
} else { } else {
$picture['path'] = $picture['path'] ? $basePath . $picture['path'] : $basePath . '/static/common/images/default.png'; $picture['path'] = $picture['path'] ? $basePath . $picture['path'] : $basePath . '/static/common/images/default.png';
} }

View File

@@ -18,6 +18,12 @@ use app\model\Attribute;
*/ */
class Content extends Base { 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 $modelInfo = [];
public $model = null; public $model = null;
@@ -41,8 +47,16 @@ class Content extends Base {
if (isset($param['keyword']) && $param['keyword'] != '') { if (isset($param['keyword']) && $param['keyword'] != '') {
$map[] = ['title', 'LIKE', '%'.$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['code'] = 1;
$this->data['data'] = $list; $this->data['data'] = $list;
return $this->data; return $this->data;
@@ -64,6 +78,27 @@ class Content extends Base {
return $this->data; 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 添加内容 * @title 添加内容
* @method POST * @method POST

View File

@@ -21,7 +21,7 @@ class Api {
public function handle($request, \Closure $next) { public function handle($request, \Closure $next) {
$request->pageConfig = array( $request->pageConfig = array(
'list_rows' => $request->param('limit', 30), 'list_rows' => $request->param('limit', 30),
'page' => $request->param('page', 1), 'page' => $request->param('page', 1),
); );
$this->cacheData($request); //缓存基础数据 $this->cacheData($request); //缓存基础数据
$response = $next($request); $response = $next($request);