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

143 lines
4.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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
{
$repeat = AnimalInfo::where('sn', $params['sn'])->count();
if ($repeat > 0) {
self::setError('耳号已使用');
return false;
}
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'],
'pic' => $params['pic'],
]);
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'],
'pic' => $params['pic'],
]);
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
{
if (isset($params['sn'])) {
return AnimalInfo::with(['fenceHouseAttr'])->where('sn', $params['sn'])->toArray();
}
return AnimalInfo::with(['fenceHouseAttr'])->findOrEmpty($params['id'])->toArray();
}
}