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