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;
|
|
|
|
|
|
|
|
|
|
|
2024-02-21 14:25:33 +08:00
|
|
|
|
use app\common\logic\RemoteRequestLogic;
|
2024-01-10 15:59:37 +08:00
|
|
|
|
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
|
|
|
|
|
{
|
2024-01-31 10:18:59 +08:00
|
|
|
|
$repeat = AnimalInfo::where('sn', $params['sn'])->count();
|
|
|
|
|
if ($repeat > 0) {
|
|
|
|
|
self::setError('耳号已使用');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-01-10 15:59:37 +08:00
|
|
|
|
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
|
|
|
|
|
{
|
2024-02-21 14:25:33 +08:00
|
|
|
|
$data = AnimalInfo::with(['fenceHouseAttr'])->findOrEmpty($params['id'])->toArray();
|
2024-01-31 15:58:18 +08:00
|
|
|
|
if (isset($params['sn'])) {
|
2024-02-21 14:25:33 +08:00
|
|
|
|
$data = AnimalInfo::with(['fenceHouseAttr'])->where('sn', $params['sn'])->findOrEmpty()->toArray();
|
2024-01-31 15:58:18 +08:00
|
|
|
|
}
|
2024-02-21 14:25:33 +08:00
|
|
|
|
// 查动物体温
|
|
|
|
|
$res = RemoteRequestLogic::requestAnimalTemperature($data['sn']);
|
|
|
|
|
if (!empty($res['values'])) {
|
|
|
|
|
$temperature = $res['values'][1];
|
|
|
|
|
} else {
|
2024-02-21 14:31:58 +08:00
|
|
|
|
$temperature = '暂无数据';
|
2024-02-21 14:25:33 +08:00
|
|
|
|
}
|
|
|
|
|
$data['temperature'] = $temperature;
|
|
|
|
|
return $data;
|
2024-01-31 15:58:18 +08:00
|
|
|
|
|
2024-01-10 15:59:37 +08:00
|
|
|
|
}
|
|
|
|
|
}
|