From 67f2020170f5203dfc1496a7f004902dede00463 Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Mon, 15 Jan 2024 10:05:18 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E9=A9=B1=E8=99=AB=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OperationDewormingLogController.php | 108 ++++++++++++++++ .../OperationDewormingLogLists.php | 77 +++++++++++ .../OperationDewormingLogLogic.php | 120 ++++++++++++++++++ .../OperationDewormingLogValidate.php | 94 ++++++++++++++ .../OperationDewormingLog.php | 56 ++++++++ 5 files changed, 455 insertions(+) create mode 100644 app/api/controller/suyuan_operation/OperationDewormingLogController.php create mode 100644 app/api/lists/suyuan_operation/OperationDewormingLogLists.php create mode 100644 app/api/logic/suyuan_operation/OperationDewormingLogLogic.php create mode 100644 app/api/validate/suyuan_operation/OperationDewormingLogValidate.php create mode 100644 app/common/model/suyuan_operation/OperationDewormingLog.php diff --git a/app/api/controller/suyuan_operation/OperationDewormingLogController.php b/app/api/controller/suyuan_operation/OperationDewormingLogController.php new file mode 100644 index 0000000..97c4800 --- /dev/null +++ b/app/api/controller/suyuan_operation/OperationDewormingLogController.php @@ -0,0 +1,108 @@ +dataLists(new OperationDewormingLogLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/15 10:04 + */ + public function add() + { + $params = (new OperationDewormingLogValidate())->post()->goCheck('add'); + $result = OperationDewormingLogLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(OperationDewormingLogLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/15 10:04 + */ + public function edit() + { + $params = (new OperationDewormingLogValidate())->post()->goCheck('edit'); + $result = OperationDewormingLogLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(OperationDewormingLogLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/15 10:04 + */ + public function delete() + { + $params = (new OperationDewormingLogValidate())->post()->goCheck('delete'); + OperationDewormingLogLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/15 10:04 + */ + public function detail() + { + $params = (new OperationDewormingLogValidate())->goCheck('detail'); + $result = OperationDewormingLogLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/api/lists/suyuan_operation/OperationDewormingLogLists.php b/app/api/lists/suyuan_operation/OperationDewormingLogLists.php new file mode 100644 index 0000000..d585dc8 --- /dev/null +++ b/app/api/lists/suyuan_operation/OperationDewormingLogLists.php @@ -0,0 +1,77 @@ + ['fence_house_id', 'animal_info_id'], + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/01/15 10:04 + */ + public function lists(): array + { + return OperationDewormingLog::where($this->searchWhere) + ->field(['id', 'fence_house_id', 'animal_info_id', 'vermifuge_name', 'deworming_date', 'deworming_method', 'operator', 'remark']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2024/01/15 10:04 + */ + public function count(): int + { + return OperationDewormingLog::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/api/logic/suyuan_operation/OperationDewormingLogLogic.php b/app/api/logic/suyuan_operation/OperationDewormingLogLogic.php new file mode 100644 index 0000000..2ecde7c --- /dev/null +++ b/app/api/logic/suyuan_operation/OperationDewormingLogLogic.php @@ -0,0 +1,120 @@ + $params['fence_house_id'], + 'animal_info_id' => $params['animal_info_id'], + 'vermifuge_name' => $params['vermifuge_name'], + 'deworming_date' => $params['deworming_date'], + 'deworming_method' => $params['deworming_method'], + 'operator' => $params['operator'], + 'image' => $params['image'], + 'remark' => $params['remark'], + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/01/15 10:04 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + OperationDewormingLog::where('id', $params['id'])->update([ + 'fence_house_id' => $params['fence_house_id'], + 'animal_info_id' => $params['animal_info_id'], + 'vermifuge_name' => $params['vermifuge_name'], + 'deworming_date' => $params['deworming_date'], + 'deworming_method' => $params['deworming_method'], + 'operator' => $params['operator'], + 'image' => $params['image'], + 'remark' => $params['remark'], + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/01/15 10:04 + */ + public static function delete(array $params): bool + { + return OperationDewormingLog::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/01/15 10:04 + */ + public static function detail($params): array + { + return OperationDewormingLog::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/api/validate/suyuan_operation/OperationDewormingLogValidate.php b/app/api/validate/suyuan_operation/OperationDewormingLogValidate.php new file mode 100644 index 0000000..040da70 --- /dev/null +++ b/app/api/validate/suyuan_operation/OperationDewormingLogValidate.php @@ -0,0 +1,94 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return OperationDewormingLogValidate + * @author likeadmin + * @date 2024/01/15 10:04 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return OperationDewormingLogValidate + * @author likeadmin + * @date 2024/01/15 10:04 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return OperationDewormingLogValidate + * @author likeadmin + * @date 2024/01/15 10:04 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return OperationDewormingLogValidate + * @author likeadmin + * @date 2024/01/15 10:04 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/suyuan_operation/OperationDewormingLog.php b/app/common/model/suyuan_operation/OperationDewormingLog.php new file mode 100644 index 0000000..32ce5c3 --- /dev/null +++ b/app/common/model/suyuan_operation/OperationDewormingLog.php @@ -0,0 +1,56 @@ +hasOne(\app\common\model\fence_house\FenceHouse::class, 'id', 'fence_house_id'); + } + + /** + * @notes 关联animalInfo + * @return \think\model\relation\HasOne + * @author likeadmin + * @date 2024/01/15 10:04 + */ + public function animalInfo() + { + return $this->hasOne(\app\common\model\animal_info\AnimalInfo::class, 'id', 'animal_info_id'); + } + +} \ No newline at end of file