suyuan-breed/app/adminapi/logic/animal_info/AnimalInfoLogic.php

134 lines
4.1 KiB
PHP
Raw Normal View History

2024-01-10 15:59:37 +08:00
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\animal_info;
use app\common\model\animal_info\AnimalInfo;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* AnimalInfo逻辑
* Class AnimalInfoLogic
* @package app\adminapi\logic\animal_info
*/
class AnimalInfoLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/10 15:53
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
AnimalInfo::create([
'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'],
2024-01-29 16:29:31 +08:00
'pic' => $params['pic'],
2024-01-10 15:59:37 +08:00
]);
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'],
2024-01-29 16:29:31 +08:00
'pic' => $params['pic'],
2024-01-10 15:59:37 +08:00
]);
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();
}
}