From 788a8cb211e636ffd0b41bfa3652c35ff35153a7 Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Mon, 6 Jan 2025 10:17:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=95=B0=E6=8D=AE=E5=8F=98?= =?UTF-8?q?=E6=9B=B4=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/ChangeLogController.php | 95 +++++++++++++++++ app/admin/lists/ChangeLogLists.php | 66 ++++++++++++ app/admin/logic/ChangeLogLogic.php | 103 +++++++++++++++++++ app/admin/validate/ChangeLogValidate.php | 82 +++++++++++++++ app/common/model/ChangeLog.php | 22 ++++ 5 files changed, 368 insertions(+) create mode 100644 app/admin/controller/ChangeLogController.php create mode 100644 app/admin/lists/ChangeLogLists.php create mode 100644 app/admin/logic/ChangeLogLogic.php create mode 100644 app/admin/validate/ChangeLogValidate.php create mode 100644 app/common/model/ChangeLog.php diff --git a/app/admin/controller/ChangeLogController.php b/app/admin/controller/ChangeLogController.php new file mode 100644 index 00000000..bad91925 --- /dev/null +++ b/app/admin/controller/ChangeLogController.php @@ -0,0 +1,95 @@ +dataLists(new ChangeLogLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author admin + * @date 2025/01/06 10:03 + */ + public function add() + { + $params = (new ChangeLogValidate())->post()->goCheck('add'); + $result = ChangeLogLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ChangeLogLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author admin + * @date 2025/01/06 10:03 + */ + public function edit() + { + $params = (new ChangeLogValidate())->post()->goCheck('edit'); + $result = ChangeLogLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ChangeLogLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author admin + * @date 2025/01/06 10:03 + */ + public function delete() + { + $params = (new ChangeLogValidate())->post()->goCheck('delete'); + ChangeLogLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取详情 + * @return \think\response\Json + * @author admin + * @date 2025/01/06 10:03 + */ + public function detail() + { + $params = (new ChangeLogValidate())->goCheck('detail'); + $result = ChangeLogLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/lists/ChangeLogLists.php b/app/admin/lists/ChangeLogLists.php new file mode 100644 index 00000000..28e0614d --- /dev/null +++ b/app/admin/lists/ChangeLogLists.php @@ -0,0 +1,66 @@ + ['model', 'link_id', 'nums', 'pm', 'url'], + '%like%' => ['mark'], + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2025/01/06 10:03 + */ + public function lists(): array + { + return ChangeLog::where($this->searchWhere) + ->field(['id', 'model', 'link_id', 'nums', 'pm', 'url', 'mark']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author admin + * @date 2025/01/06 10:03 + */ + public function count(): int + { + return ChangeLog::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/logic/ChangeLogLogic.php b/app/admin/logic/ChangeLogLogic.php new file mode 100644 index 00000000..fac0eee1 --- /dev/null +++ b/app/admin/logic/ChangeLogLogic.php @@ -0,0 +1,103 @@ + $params['model'], + 'link_id' => $params['link_id'], + 'nums' => $params['nums'], + 'pm' => $params['pm'], + 'url' => $params['url'], + 'mark' => $params['mark'], + ]); + + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 编辑 + * @param array $params + * @return bool + * @author admin + * @date 2025/01/06 10:03 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + ChangeLog::where('id', $params['id'])->update([ + 'model' => $params['model'], + 'link_id' => $params['link_id'], + 'nums' => $params['nums'], + 'pm' => $params['pm'], + 'url' => $params['url'], + 'mark' => $params['mark'], + ]); + + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 删除 + * @param array $params + * @return bool + * @author admin + * @date 2025/01/06 10:03 + */ + public static function delete(array $params): bool + { + return ChangeLog::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author admin + * @date 2025/01/06 10:03 + */ + public static function detail($params): array + { + return ChangeLog::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/validate/ChangeLogValidate.php b/app/admin/validate/ChangeLogValidate.php new file mode 100644 index 00000000..8861efb1 --- /dev/null +++ b/app/admin/validate/ChangeLogValidate.php @@ -0,0 +1,82 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return ChangeLogValidate + * @author admin + * @date 2025/01/06 10:03 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return ChangeLogValidate + * @author admin + * @date 2025/01/06 10:03 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return ChangeLogValidate + * @author admin + * @date 2025/01/06 10:03 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ChangeLogValidate + * @author admin + * @date 2025/01/06 10:03 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/ChangeLog.php b/app/common/model/ChangeLog.php new file mode 100644 index 00000000..bc74fb9b --- /dev/null +++ b/app/common/model/ChangeLog.php @@ -0,0 +1,22 @@ +