From 38b429ec3d81a8065860067a1f72f9db2f582be3 Mon Sep 17 00:00:00 2001 From: xucong <850806214@qq.com> Date: Sun, 8 Jun 2025 17:04:22 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=8F=90=E4=BA=A4=E7=BC=BA=E5=A4=B1=E7=9A=84?= =?UTF-8?q?=E4=B8=9C=E8=A5=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminapi/controller/DeviceController.php | 108 +++++++++++++++++ route/app/adminapi/lists/DeviceLists.php | 77 ++++++++++++ route/app/adminapi/logic/DeviceLogic.php | 112 ++++++++++++++++++ .../app/adminapi/validate/DeviceValidate.php | 94 +++++++++++++++ route/app/common/model/Device.php | 34 ++++++ 5 files changed, 425 insertions(+) create mode 100644 route/app/adminapi/controller/DeviceController.php create mode 100644 route/app/adminapi/lists/DeviceLists.php create mode 100644 route/app/adminapi/logic/DeviceLogic.php create mode 100644 route/app/adminapi/validate/DeviceValidate.php create mode 100644 route/app/common/model/Device.php diff --git a/route/app/adminapi/controller/DeviceController.php b/route/app/adminapi/controller/DeviceController.php new file mode 100644 index 0000000..5484ec9 --- /dev/null +++ b/route/app/adminapi/controller/DeviceController.php @@ -0,0 +1,108 @@ +dataLists(new DeviceLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author likeadmin + * @date 2025/06/08 16:46 + */ + public function add() + { + $params = (new DeviceValidate())->post()->goCheck('add'); + $result = DeviceLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(DeviceLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author likeadmin + * @date 2025/06/08 16:46 + */ + public function edit() + { + $params = (new DeviceValidate())->post()->goCheck('edit'); + $result = DeviceLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(DeviceLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author likeadmin + * @date 2025/06/08 16:46 + */ + public function delete() + { + $params = (new DeviceValidate())->post()->goCheck('delete'); + DeviceLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取详情 + * @return \think\response\Json + * @author likeadmin + * @date 2025/06/08 16:46 + */ + public function detail() + { + $params = (new DeviceValidate())->goCheck('detail'); + $result = DeviceLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/route/app/adminapi/lists/DeviceLists.php b/route/app/adminapi/lists/DeviceLists.php new file mode 100644 index 0000000..7a3acc3 --- /dev/null +++ b/route/app/adminapi/lists/DeviceLists.php @@ -0,0 +1,77 @@ + ['name', 'model', 'state', 'dtime'], + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2025/06/08 16:46 + */ + public function lists(): array + { + return Device::where($this->searchWhere) + ->field(['id', 'name', 'model', 'state', 'dtime']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2025/06/08 16:46 + */ + public function count(): int + { + return Device::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/route/app/adminapi/logic/DeviceLogic.php b/route/app/adminapi/logic/DeviceLogic.php new file mode 100644 index 0000000..6a9f9f8 --- /dev/null +++ b/route/app/adminapi/logic/DeviceLogic.php @@ -0,0 +1,112 @@ + $params['name'], + 'model' => $params['model'], + 'state' => $params['state'], + 'dtime' => $params['dtime'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑 + * @param array $params + * @return bool + * @author likeadmin + * @date 2025/06/08 16:46 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + Device::where('id', $params['id'])->update([ + 'name' => $params['name'], + 'model' => $params['model'], + 'state' => $params['state'], + 'dtime' => $params['dtime'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除 + * @param array $params + * @return bool + * @author likeadmin + * @date 2025/06/08 16:46 + */ + public static function delete(array $params): bool + { + return Device::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author likeadmin + * @date 2025/06/08 16:46 + */ + public static function detail($params): array + { + return Device::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/route/app/adminapi/validate/DeviceValidate.php b/route/app/adminapi/validate/DeviceValidate.php new file mode 100644 index 0000000..cb11d2d --- /dev/null +++ b/route/app/adminapi/validate/DeviceValidate.php @@ -0,0 +1,94 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return DeviceValidate + * @author likeadmin + * @date 2025/06/08 16:46 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return DeviceValidate + * @author likeadmin + * @date 2025/06/08 16:46 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return DeviceValidate + * @author likeadmin + * @date 2025/06/08 16:46 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return DeviceValidate + * @author likeadmin + * @date 2025/06/08 16:46 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/route/app/common/model/Device.php b/route/app/common/model/Device.php new file mode 100644 index 0000000..6e43ae6 --- /dev/null +++ b/route/app/common/model/Device.php @@ -0,0 +1,34 @@ +