// +---------------------------------------------------------------------- namespace app\controller\admin; use app\controller\Admin; use app\model\Form as FormModel; class Form extends Admin{ /** * @title 系统首页 */ public function index(FormModel $form){ if ($this->request->isAjax()) { $res = $form->paginate($this->request->pageConfig); $data = $res->toArray(); $this->data['data'] = $data; return $this->data; } } /** * @title 添加客户端 */ public function add(FormModel $form){ if ($this->request->isPost()) { $data = $this->request->post(); $result = $form->save($data); if (false !== $result) { return $this->success('成功添加', url('/admin/form/index')); }else{ return $this->error($this->model->getError()); } }else{ $info['appid'] = rand_string(10, 1); //八位数字appid $info['appsecret'] = rand_string(32); //32位数字加字母秘钥 $this->data['data'] = array( 'info' => $info ); return $this->data; } } /** * @title 编辑客户端 */ public function edit(FormModel $form){ if ($this->request->isPost()) { $data = $this->request->post(); if (!isset($data['id']) || !$data['id']) { return $this->error('非法操作!'); } $result = $form->exists(true)->save($data); if (false !== $result) { return $this->success('修改成功', url('/admin/form/index')); }else{ return $this->error($this->model->getError()); } }else{ $info = $form->where('id', $this->request->param('id'))->find(); $this->data['template'] = "add"; $this->data['data'] = array( 'info' => $info ); return $this->data; } } /** * @title 删除客户端 */ public function del(FormModel $form){ $ids = $this->request->param('ids', 0); if(!$ids){ return $this->error('非法操作!'); }else{ $ids = \explode(",", $ids); } $result = $form->where('id', 'IN', $ids)->delete(); if(false !== $result){ return $this->success('删除成功!'); }else{ return $this->error('删除失败!'); } } }