From 00830de89a837d00654ef85d974b6d59b3a3b67d Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Wed, 10 Jan 2024 15:59:37 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=A1=A3=E6=A1=88=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/src/api/animal_info.ts | 26 +++ admin/src/views/animal_info/edit.vue | 170 ++++++++++++++++++ admin/src/views/animal_info/index.vue | 144 +++++++++++++++ .../animal_info/AnimalInfoController.php | 108 +++++++++++ .../lists/animal_info/AnimalInfoLists.php | 77 ++++++++ .../logic/animal_info/AnimalInfoLogic.php | 134 ++++++++++++++ .../animal_info/AnimalInfoValidate.php | 94 ++++++++++ app/common/model/animal_info/AnimalInfo.php | 45 +++++ 8 files changed, 798 insertions(+) create mode 100644 admin/src/api/animal_info.ts create mode 100644 admin/src/views/animal_info/edit.vue create mode 100644 admin/src/views/animal_info/index.vue create mode 100644 app/adminapi/controller/animal_info/AnimalInfoController.php create mode 100644 app/adminapi/lists/animal_info/AnimalInfoLists.php create mode 100644 app/adminapi/logic/animal_info/AnimalInfoLogic.php create mode 100644 app/adminapi/validate/animal_info/AnimalInfoValidate.php create mode 100644 app/common/model/animal_info/AnimalInfo.php diff --git a/admin/src/api/animal_info.ts b/admin/src/api/animal_info.ts new file mode 100644 index 0000000..899cd22 --- /dev/null +++ b/admin/src/api/animal_info.ts @@ -0,0 +1,26 @@ +import request from '@/utils/request' + +// 动物档案列表 +export function apiAnimalInfoLists(params: any) { + return request.get({ url: '/animal_info.animal_info/lists', params }) +} + +// 添加动物档案 +export function apiAnimalInfoAdd(params: any) { + return request.post({ url: '/animal_info.animal_info/add', params }) +} + +// 编辑动物档案 +export function apiAnimalInfoEdit(params: any) { + return request.post({ url: '/animal_info.animal_info/edit', params }) +} + +// 删除动物档案 +export function apiAnimalInfoDelete(params: any) { + return request.post({ url: '/animal_info.animal_info/delete', params }) +} + +// 动物档案详情 +export function apiAnimalInfoDetail(params: any) { + return request.get({ url: '/animal_info.animal_info/detail', params }) +} \ No newline at end of file diff --git a/admin/src/views/animal_info/edit.vue b/admin/src/views/animal_info/edit.vue new file mode 100644 index 0000000..9535dd4 --- /dev/null +++ b/admin/src/views/animal_info/edit.vue @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/admin/src/views/animal_info/index.vue b/admin/src/views/animal_info/index.vue new file mode 100644 index 0000000..640b6fb --- /dev/null +++ b/admin/src/views/animal_info/index.vue @@ -0,0 +1,144 @@ + + + + + + + + + + 查询 + 重置 + + + + + + + + + 新增 + + + 删除 + + + + + + + + + + + + + + + + + + + + + + + + + + + 编辑 + + + 删除 + + + + + + + + + + + + + + + diff --git a/app/adminapi/controller/animal_info/AnimalInfoController.php b/app/adminapi/controller/animal_info/AnimalInfoController.php new file mode 100644 index 0000000..215530a --- /dev/null +++ b/app/adminapi/controller/animal_info/AnimalInfoController.php @@ -0,0 +1,108 @@ +dataLists(new AnimalInfoLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/10 15:53 + */ + public function add() + { + $params = (new AnimalInfoValidate())->post()->goCheck('add'); + $result = AnimalInfoLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(AnimalInfoLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/10 15:53 + */ + public function edit() + { + $params = (new AnimalInfoValidate())->post()->goCheck('edit'); + $result = AnimalInfoLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(AnimalInfoLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/10 15:53 + */ + public function delete() + { + $params = (new AnimalInfoValidate())->post()->goCheck('delete'); + AnimalInfoLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/10 15:53 + */ + public function detail() + { + $params = (new AnimalInfoValidate())->goCheck('detail'); + $result = AnimalInfoLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/animal_info/AnimalInfoLists.php b/app/adminapi/lists/animal_info/AnimalInfoLists.php new file mode 100644 index 0000000..7f57fbf --- /dev/null +++ b/app/adminapi/lists/animal_info/AnimalInfoLists.php @@ -0,0 +1,77 @@ + ['sn'], + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/01/10 15:53 + */ + public function lists(): array + { + return AnimalInfo::where($this->searchWhere) + ->field(['id', 'fence_house_id', 'sn', 'animal_type', 'brand', 'physi_stage', 'gender', 'blood_purity', 'animal_source', 'current_estimation', 'algebra', 'birth', 'entry_date', 'birth_estimation', 'health_condition']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2024/01/10 15:53 + */ + public function count(): int + { + return AnimalInfo::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/animal_info/AnimalInfoLogic.php b/app/adminapi/logic/animal_info/AnimalInfoLogic.php new file mode 100644 index 0000000..830cdfe --- /dev/null +++ b/app/adminapi/logic/animal_info/AnimalInfoLogic.php @@ -0,0 +1,134 @@ + $params['fence_house_id'], + 'sn' => $params['sn'], + 'animal_type' => $params['animal_type'], + 'brand' => $params['brand'], + 'physi_stage' => $params['physi_stage'], + 'gender' => $params['gender'], + 'blood_purity' => $params['blood_purity'], + 'animal_source' => $params['animal_source'], + 'current_estimation' => $params['current_estimation'], + 'algebra' => $params['algebra'], + 'birth' => $params['birth'], + 'entry_date' => $params['entry_date'], + 'birth_estimation' => $params['birth_estimation'], + 'health_condition' => $params['health_condition'], + 'image' => $params['image'], + ]); + + 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/10 15:53 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + AnimalInfo::where('id', $params['id'])->update([ + 'fence_house_id' => $params['fence_house_id'], + 'sn' => $params['sn'], + 'animal_type' => $params['animal_type'], + 'brand' => $params['brand'], + 'physi_stage' => $params['physi_stage'], + 'gender' => $params['gender'], + 'blood_purity' => $params['blood_purity'], + 'animal_source' => $params['animal_source'], + 'current_estimation' => $params['current_estimation'], + 'algebra' => $params['algebra'], + 'birth' => $params['birth'], + 'entry_date' => $params['entry_date'], + 'birth_estimation' => $params['birth_estimation'], + 'health_condition' => $params['health_condition'], + 'image' => $params['image'], + ]); + + 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/10 15:53 + */ + public static function delete(array $params): bool + { + return AnimalInfo::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/01/10 15:53 + */ + public static function detail($params): array + { + return AnimalInfo::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/animal_info/AnimalInfoValidate.php b/app/adminapi/validate/animal_info/AnimalInfoValidate.php new file mode 100644 index 0000000..d44783f --- /dev/null +++ b/app/adminapi/validate/animal_info/AnimalInfoValidate.php @@ -0,0 +1,94 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return AnimalInfoValidate + * @author likeadmin + * @date 2024/01/10 15:53 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return AnimalInfoValidate + * @author likeadmin + * @date 2024/01/10 15:53 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return AnimalInfoValidate + * @author likeadmin + * @date 2024/01/10 15:53 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return AnimalInfoValidate + * @author likeadmin + * @date 2024/01/10 15:53 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/animal_info/AnimalInfo.php b/app/common/model/animal_info/AnimalInfo.php new file mode 100644 index 0000000..f50d510 --- /dev/null +++ b/app/common/model/animal_info/AnimalInfo.php @@ -0,0 +1,45 @@ +hasOne(\app\common\model\fence_house\FenceHouse::class, 'id', 'fence_house_id'); + } + +} \ No newline at end of file