suyuan/app/adminapi/logic/device/MonitorThresholdLogic.php

144 lines
5.1 KiB
PHP
Raw Permalink 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\device;
use app\common\model\device\MonitorThreshold;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* MonitorThreshold逻辑
* Class MonitorThresholdLogic
* @package app\adminapi\logic\device
*/
class MonitorThresholdLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/24 16:17
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
MonitorThreshold::create([
'soil_temp_max' => $params['soil_temp_max'],
'soil_temp_min' => $params['soil_temp_min'],
'soil_mois_max' => $params['soil_mois_max'],
'soil_mois_min' => $params['soil_mois_min'],
'soil_ph_max' => $params['soil_ph_max'],
'soil_ph_min' => $params['soil_ph_min'],
'soil_n_content_max' => $params['soil_n_content_max'],
'soil_n_content_min' => $params['soil_n_content_min'],
'soil_p_content_max' => $params['soil_p_content_max'],
'soil_p_content_min' => $params['soil_p_content_min'],
'soil_k_content_max' => $params['soil_k_content_max'],
'soil_k_content_min' => $params['soil_k_content_min'],
'air_temp_max' => $params['air_temp_max'],
'air_temp_min' => $params['air_temp_min'],
'air_mois_max' => $params['air_mois_max'],
'air_mois_min' => $params['air_mois_min'],
'air_co2_content_max' => $params['air_co2_content_max'],
'air_co2_content_min' => $params['air_co2_content_min'],
'wind_speed_max' => $params['wind_speed_max'],
'wind_speed_min' => $params['wind_speed_min'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/24 16:17
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
MonitorThreshold::where('id', $params['id'])->update([
'soil_temp_max' => $params['soil_temp_max'],
'soil_temp_min' => $params['soil_temp_min'],
'soil_mois_max' => $params['soil_mois_max'],
'soil_mois_min' => $params['soil_mois_min'],
'soil_ph_max' => $params['soil_ph_max'],
'soil_ph_min' => $params['soil_ph_min'],
'soil_n_content_max' => $params['soil_n_content_max'],
'soil_n_content_min' => $params['soil_n_content_min'],
'soil_p_content_max' => $params['soil_p_content_max'],
'soil_p_content_min' => $params['soil_p_content_min'],
'soil_k_content_max' => $params['soil_k_content_max'],
'soil_k_content_min' => $params['soil_k_content_min'],
'air_temp_max' => $params['air_temp_max'],
'air_temp_min' => $params['air_temp_min'],
'air_mois_max' => $params['air_mois_max'],
'air_mois_min' => $params['air_mois_min'],
'air_co2_content_max' => $params['air_co2_content_max'],
'air_co2_content_min' => $params['air_co2_content_min'],
'wind_speed_max' => $params['wind_speed_max'],
'wind_speed_min' => $params['wind_speed_min'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/24 16:17
*/
public static function delete(array $params): bool
{
return MonitorThreshold::destroy($params['id']);
}
/**
* @notes 获取详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/11/24 16:17
*/
public static function detail($params): array
{
return MonitorThreshold::findOrEmpty($params['id'])->toArray();
}
}