model = new PrintModel; } /** * 获取 */ private function createWhere() { $data = $this->request->param(); $where = []; if(!empty($data['keyword'])){ $where[] = ['title|code','LIKE',"%{$data['keyword']}%"]; } return ['where'=>$where,'whereOr'=>[]]; } /** *获取列表 */ public function getList(int $pageNo=0,int $pageSize=10) { $whereAry = $this->createWhere(); if(!empty($pageNo)){ $res = $this->model->where($whereAry['where'])->where(function($query)use($whereAry){ $query->where($whereAry['whereOr']); })->with([])->paginate(['page'=>$pageNo,'list_rows'=>$pageSize]); return pageRes(1,'获取成功',$res->total(),$res->items()); }else{ $list = $this->model->where($whereAry['where'])->where(function($query)use($whereAry){ $query->where($whereAry['whereOr']); })->with([])->select(); return res(1,'获取成功',$list); } } public function doEdit() { $data = $this->request->param(); $this->model->replace()->save($data); slog(1,"编辑了打印模板".$data['title']); return res(1,"保存成功"); } public function getInfo(string $code='') { $info = $this->model->where('code',$code)->find(); return res(1,"获取成功",$info); } public function doDelete(int $id=0) { $info = $this->model->where("id",$id)->find(); if(empty($info)){ return res(1,"删除成功"); } $info->delete(); slog(1,"删除了打印模板".$info->title); return res(1,"删除成功"); } public function getOptions() { $option = []; return res(1,"获取成功",$option); } public function __call($name,$arguments) { return res(2,"控制器方法{$name}不存在"); } }