From 2a73450bc3b0b7ddd6ee66c6d644990729b2fde7 Mon Sep 17 00:00:00 2001 From: yaooo <272523191@qq.com> Date: Mon, 11 Sep 2023 14:52:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=90=8E=E5=8F=B0=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=B3=BB=E7=BB=9Fapp=E7=89=88=E6=9C=AC=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/system/AppUpdateDao.php | 10 +++++ .../repositories/system/LhappRepository.php | 15 +++++++ app/controller/admin/system/Lhapp.php | 39 +++++++++++++++++++ route/admin/system.php | 4 +- 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/app/common/dao/system/AppUpdateDao.php b/app/common/dao/system/AppUpdateDao.php index 78db6032..15f04f4c 100644 --- a/app/common/dao/system/AppUpdateDao.php +++ b/app/common/dao/system/AppUpdateDao.php @@ -38,5 +38,15 @@ class AppUpdateDao extends BaseDao return AppUpdate::class; } + public function search(array $where = []) + { + return AppUpdate::getDB() + ->when(isset($where['id']) && $where['id'] !== '',function($query) use($where){ + $query->where('id',$where['id']); + }) + ->when(isset($where['type']) && $where['type'] !== '',function($query) use($where){ + $query->where('type',$where['type']); + }); + } } diff --git a/app/common/repositories/system/LhappRepository.php b/app/common/repositories/system/LhappRepository.php index 3d23de07..817bce7a 100644 --- a/app/common/repositories/system/LhappRepository.php +++ b/app/common/repositories/system/LhappRepository.php @@ -40,4 +40,19 @@ class LhappRepository extends BaseRepository $this->dao = $dao; } + public function getList($where, $page, $limit) + { + $query = $this->dao->search($where); + $count = $query->count(); + $list = $query->page($page, $limit)->order('id DESC')->select(); + return compact('count', 'list'); + } + + public function detail($id) + { + $find = $this->dao->search(['id' => $id])->find(); + if (!$find) throw new ValidateException('数据不存在'); + return $find; + } + } diff --git a/app/controller/admin/system/Lhapp.php b/app/controller/admin/system/Lhapp.php index 06fb2fda..224cfbc3 100644 --- a/app/controller/admin/system/Lhapp.php +++ b/app/controller/admin/system/Lhapp.php @@ -11,6 +11,7 @@ namespace app\controller\admin\system; use app\common\repositories\system\LhappRepository; +use think\exception\ValidateException; use crmeb\basic\BaseController; use think\App; @@ -31,4 +32,42 @@ class Lhapp extends BaseController $this->repository = $repository; } + public function list() + { + [$page, $limit] = $this->getPage(); + $where = $this->request->params(['type']); + return app('json')->success($this->repository->getList($where, $page, $limit)); + } + + public function create() + { + $this->repository->create($this->getValidParams()); + return app('json')->success('添加成功'); + } + + public function update($id) + { + if (!$this->repository->exists($id)) { + return app('json')->fail('数据不存在'); + } + $this->repository->update($id, $this->getValidParams()); + return app('json')->success('修改成功'); + } + public function detail($id) + { + $data = $this->repository->detail($id); + return app('json')->success($data); + } + + protected function getValidParams() + { + $data = $this->request->params(['title', 'content', 'type', 'version', 'dow_url', 'force', 'quiet']); + if (empty($data['title'])) throw new ValidateException('title标题不能为空'); + if (empty($data['content'])) throw new ValidateException('content内容不能为空'); + if (empty($data['type'])) throw new ValidateException('type类型不能为空'); + if (empty($data['version'])) throw new ValidateException('version版本号不能为空'); + if (empty($data['dow_url'])) throw new ValidateException('dow_url下载地址不能为空'); + return $data; + } + } diff --git a/route/admin/system.php b/route/admin/system.php index 5d61aec5..588536aa 100644 --- a/route/admin/system.php +++ b/route/admin/system.php @@ -177,10 +177,10 @@ Route::group(function () { Route::get('detail/:id', '/detail')->name('appVersionDetail')->option([ '_alias' => 'APP版本详情', ]); - Route::post('add', '/add')->name('appVersionAdd')->option([ + Route::post('create', '/create')->name('appVersionAdd')->option([ '_alias' => '新增APP版本', ]); - Route::post('edit/:id', '/edit')->name('appVersionEdit')->option([ + Route::post('edit/:id', '/update')->name('appVersionEdit')->option([ '_alias' => '编辑APP版本', ]); })->prefix('admin.system.Lhapp')->option([