接口更新
This commit is contained in:
@@ -15,6 +15,15 @@ use app\model\Category;
|
||||
*/
|
||||
class Content extends Base {
|
||||
|
||||
public $modelInfo = [];
|
||||
public $model = null;
|
||||
|
||||
public function initialize() {
|
||||
parent::initialize();
|
||||
$this->modelInfo = Model::where('name', $this->request->param('name'))->find()->append(['grid_list', 'attr_group'])->toArray();
|
||||
$this->model = Db::name($this->modelInfo['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 内容列表
|
||||
* @method GET
|
||||
@@ -22,7 +31,18 @@ class Content extends Base {
|
||||
* @return [json]
|
||||
*/
|
||||
public function lists(Category $category){
|
||||
$param = $this->request->param();
|
||||
$order = "id desc";
|
||||
$map = [];
|
||||
|
||||
if (isset($param['keyword']) && $param['keyword'] != '') {
|
||||
$map[] = ['title', 'LIKE', '%'.$param['keyword'].'%'];
|
||||
}
|
||||
|
||||
$list = $this->model->where($map)->order($order)->paginate($this->request->pageConfig);
|
||||
|
||||
$this->data['data'] = $list;
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,7 +51,14 @@ class Content extends Base {
|
||||
* @return [json]
|
||||
*/
|
||||
public function detail(){
|
||||
$id = $this->request->param('id');
|
||||
if (!$id) {
|
||||
return $this->error("非法操作!");
|
||||
}
|
||||
$info = $this->model->find($id);
|
||||
|
||||
$this->data['data'] = $info;
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,7 +67,20 @@ class Content extends Base {
|
||||
* @return [json]
|
||||
*/
|
||||
public function add(){
|
||||
$data = $this->request->post();
|
||||
$data['create_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$data['uid'] = $this->request->user['uid'];
|
||||
|
||||
$result = $this->model->save($data);
|
||||
if(false !== $result){
|
||||
$this->data['code'] = 1;
|
||||
}else{
|
||||
$this->data['code'] = 0;
|
||||
$this->data['msg'] = "添加失败!";
|
||||
}
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,7 +89,18 @@ class Content extends Base {
|
||||
* @return [json]
|
||||
*/
|
||||
public function edit(){
|
||||
$data = $this->request->post();
|
||||
$data['update_time'] = time();
|
||||
|
||||
$result = $this->model->save($data);
|
||||
if(false !== $result){
|
||||
$this->data['code'] = 1;
|
||||
}else{
|
||||
$this->data['code'] = 0;
|
||||
$this->data['msg'] = "修改失败!";
|
||||
}
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,6 +109,26 @@ class Content extends Base {
|
||||
* @return [json]
|
||||
*/
|
||||
public function delete(){
|
||||
$id = $this->request->param('id', '');
|
||||
|
||||
$map = [];
|
||||
if (!$id) {
|
||||
return $this->error('请选择要操作的数据!');
|
||||
}
|
||||
if (is_array($id)) {
|
||||
$map[] = ['id', 'IN', $id];
|
||||
}else{
|
||||
$map[] = ['id', '=', $id];
|
||||
}
|
||||
|
||||
$result = $this->model->where($map)->delete();
|
||||
if(false !== $result){
|
||||
$this->data['code'] = 1;
|
||||
}else{
|
||||
$this->data['code'] = 0;
|
||||
$this->data['msg'] = "删除失败!";
|
||||
}
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user