捕梦者基础框架API接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

85 lines
1.9 KiB

<?php
declare (strict_types=1);
/**
* Created by 安徽云掌.
* User: 云掌.帮德
* Date: 2020/3/8 22:30
* Desc: 字典类型类
*/
namespace app\api\controller;
use think\App;
class ImageStorage extends Common
{
public $model = null;
public function __construct(App $app)
{
parent::__construct($app);
$this->model = new \app\api\model\ImageStorages();
}
public function index()
{
//接受参数
$_get = $this->request->get();
//指定搜索参数
$this->model->search_arr = ['title'];
//数据处理
$_data = $this->model->index();
//返回数据
return send_http_status($_data);
}
public function read(int $id = 0)
{
//验证参数
validate(\app\api\validate\Message::class)->scene('read')->check(['id' => $id]);
//返回数据
return send_http_status($this->model->parentRead($id));
}
public function add()
{
//接收参数
$_post = $this->request->post();
//处理并返回参数
$insertId = $this->model->parentAdd($_post);
return send_http_status($insertId, $insertId ? 201 : 202);
}
public function edit(int $id = 0)
{
//接收参数
$_post = $this->request->post();
$_post['id'] = empty($_post['id']) ? $id : 0; //安全赋值,以免客户端没传id,修改需要id字段
//处理并返回数据
return send_http_status('', $this->model->parentEdit($_post, $id) ? 203 : 204);
}
public function delete()
{
//接收参数
$ids = $this->request->param('id');
//验证参数
validate(['ids|id' => 'require|length:1,1000'])->check(['ids' => $ids]);
//处理并返回数据
return send_http_status('', $this->model->parentDel($ids) ? 205 : 206);
}
}