From b9affdbb9d5b92ec7ddb1de4905ee25de11cfc79 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 2 Aug 2023 16:43:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=B5=84=E4=BA=A7=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../property/PropertyController.php | 108 +++++++++++++++++ app/adminapi/lists/property/PropertyLists.php | 77 ++++++++++++ app/adminapi/logic/property/PropertyLogic.php | 112 ++++++++++++++++++ .../validate/property/PropertyValidate.php | 102 ++++++++++++++++ 4 files changed, 399 insertions(+) create mode 100644 app/adminapi/controller/property/PropertyController.php create mode 100644 app/adminapi/lists/property/PropertyLists.php create mode 100644 app/adminapi/logic/property/PropertyLogic.php create mode 100644 app/adminapi/validate/property/PropertyValidate.php diff --git a/app/adminapi/controller/property/PropertyController.php b/app/adminapi/controller/property/PropertyController.php new file mode 100644 index 000000000..87dcdae9d --- /dev/null +++ b/app/adminapi/controller/property/PropertyController.php @@ -0,0 +1,108 @@ +dataLists(new PropertyLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author likeadmin + * @date 2023/08/02 16:35 + */ + public function add() + { + $params = (new PropertyValidate())->post()->goCheck('add'); + $result = PropertyLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(PropertyLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author likeadmin + * @date 2023/08/02 16:35 + */ + public function edit() + { + $params = (new PropertyValidate())->post()->goCheck('edit'); + $result = PropertyLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(PropertyLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author likeadmin + * @date 2023/08/02 16:35 + */ + public function delete() + { + $params = (new PropertyValidate())->post()->goCheck('delete'); + PropertyLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/08/02 16:35 + */ + public function detail() + { + $params = (new PropertyValidate())->goCheck('detail'); + $result = PropertyLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/property/PropertyLists.php b/app/adminapi/lists/property/PropertyLists.php new file mode 100644 index 000000000..5a42c3e07 --- /dev/null +++ b/app/adminapi/lists/property/PropertyLists.php @@ -0,0 +1,77 @@ + ['company_id', 'name', 'status', 'type'], + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/08/02 16:35 + */ + public function lists(): array + { + return Property::where($this->searchWhere) + ->field(['id', 'company_id', 'name', 'status', 'type']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2023/08/02 16:35 + */ + public function count(): int + { + return Property::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/property/PropertyLogic.php b/app/adminapi/logic/property/PropertyLogic.php new file mode 100644 index 000000000..14c31039c --- /dev/null +++ b/app/adminapi/logic/property/PropertyLogic.php @@ -0,0 +1,112 @@ + $params['company_id'], + 'name' => $params['name'], + 'status' => $params['status'], + 'type' => $params['type'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/08/02 16:35 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + Property::where('id', $params['id'])->update([ + 'company_id' => $params['company_id'], + 'name' => $params['name'], + 'status' => $params['status'], + 'type' => $params['type'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/08/02 16:35 + */ + public static function delete(array $params): bool + { + return Property::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/08/02 16:35 + */ + public static function detail($params): array + { + return Property::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/property/PropertyValidate.php b/app/adminapi/validate/property/PropertyValidate.php new file mode 100644 index 000000000..8f7d2aba4 --- /dev/null +++ b/app/adminapi/validate/property/PropertyValidate.php @@ -0,0 +1,102 @@ + 'require', + 'company_id' => 'require', + 'name' => 'require', + 'status' => 'require', + 'type' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'company_id' => '所属公司id', + 'name' => '资产名称', + 'status' => '资产状态 0:未出租 1:已出租', + 'type' => '资产类型 1:三轮车 2:XXX 3:XXX', + ]; + + + /** + * @notes 添加场景 + * @return PropertyValidate + * @author likeadmin + * @date 2023/08/02 16:35 + */ + public function sceneAdd() + { + return $this->only(['company_id','name','status','type']); + } + + + /** + * @notes 编辑场景 + * @return PropertyValidate + * @author likeadmin + * @date 2023/08/02 16:35 + */ + public function sceneEdit() + { + return $this->only(['id','company_id','name','status','type']); + } + + + /** + * @notes 删除场景 + * @return PropertyValidate + * @author likeadmin + * @date 2023/08/02 16:35 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return PropertyValidate + * @author likeadmin + * @date 2023/08/02 16:35 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file