修改接口类
This commit is contained in:
@@ -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';
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user