diff --git a/app/controller/admin/Index.php b/app/controller/admin/Index.php index 8d96ac9f..3da23770 100755 --- a/app/controller/admin/Index.php +++ b/app/controller/admin/Index.php @@ -35,11 +35,31 @@ class Index extends Base { */ public function update(){ $version = new \com\Version(); - - $info = $version->check(); - - $this->data['info'] = $info; - return $this->fetch(); + if($this->request->isPost()){ + switch ($type) { + case 'down': + //下载升级包 + $this->data['data'] = $version->downloadZip(); + break; + case 'unzip': + //解压升级包 + $this->data['data'] = $version->unzipFile(); + case 'move': + //覆盖文件 + case 'sql': + //升级数据库 + default: + $this->data['data'] = "无操作"; + break; + } + $this->data['code'] = 1; + return $this->data; + }else{ + $info = $version->check(); + + $this->data['info'] = $info; + return $this->fetch(); + } } /** diff --git a/app/controller/api/Base.php b/app/controller/api/Base.php index 15444421..2f51e866 100644 --- a/app/controller/api/Base.php +++ b/app/controller/api/Base.php @@ -41,8 +41,13 @@ class Base { public function __construct(App $app) { $this->app = $app; $this->request = $this->app->request; + // 控制器初始化 + $this->initialize(); } + // 初始化 + protected function initialize() {} + protected function success($msg, $url = '') { $this->data['code'] = 1; $this->data['msg'] = $msg; diff --git a/app/controller/api/Content.php b/app/controller/api/Content.php index 06080fcc..985b019c 100644 --- a/app/controller/api/Content.php +++ b/app/controller/api/Content.php @@ -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; } } \ No newline at end of file diff --git a/extend/com/Version.php b/extend/com/Version.php index 688bd9a7..8cc93c45 100644 --- a/extend/com/Version.php +++ b/extend/com/Version.php @@ -54,4 +54,18 @@ class Version{ //throw $th; } } + + /** + * @title 下载升级包 + */ + public function downloadZip(){ + + } + + /** + * @title 解压升级包 + */ + public function unzipFile(){ + + } } \ No newline at end of file diff --git a/view/admin/index/update.html b/view/admin/index/update.html index c09c0c94..d0305990 100644 --- a/view/admin/index/update.html +++ b/view/admin/index/update.html @@ -4,7 +4,7 @@

当前版本:{$version}

-

最新版本:{$info['version']}

+

可升级版本:{$info['version']}

{if isset($info['update']) && $info['update'] == 1}

下载手动升级