139 lines
4.1 KiB
PHP
139 lines
4.1 KiB
PHP
<?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\fence_house;
|
||
|
||
|
||
use app\common\model\farm\Farm;
|
||
use app\common\model\fence_house\FenceHouse;
|
||
use app\common\logic\BaseLogic;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* FenceHouse逻辑
|
||
* Class FenceHouseLogic
|
||
* @package app\adminapi\logic\fence_house
|
||
*/
|
||
class FenceHouseLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/01/10 15:15
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
FenceHouse::create([
|
||
'farm_id' => $params['farm_id'],
|
||
'fence_house_name' => $params['fence_house_name'],
|
||
'animal_type' => $params['animal_type'],
|
||
'fence_house_type' => $params['fence_house_type'],
|
||
'capacity' => $params['capacity'],
|
||
'master' => $params['master'],
|
||
'status' => $params['status'],
|
||
'qr_code' => $params['qr_code'],
|
||
]);
|
||
|
||
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:15
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
FenceHouse::where('id', $params['id'])->update([
|
||
'farm_id' => $params['farm_id'],
|
||
'fence_house_name' => $params['fence_house_name'],
|
||
'animal_type' => $params['animal_type'],
|
||
'fence_house_type' => $params['fence_house_type'],
|
||
'capacity' => $params['capacity'],
|
||
'master' => $params['master'],
|
||
'status' => $params['status'],
|
||
'qr_code' => $params['qr_code'],
|
||
]);
|
||
|
||
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:15
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return FenceHouse::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2024/01/10 15:15
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
return FenceHouse::findOrEmpty($params['id'])->toArray();
|
||
}
|
||
|
||
|
||
public static function datas($params)
|
||
{
|
||
$queryWhere = [];
|
||
if (!empty($params['fence_house_name'])) {
|
||
$queryWhere[] = ['fence_house_name', 'like', '%' . $params['fence_house_name'] . '%'];
|
||
}
|
||
if (!empty($params['user_id'])) {
|
||
$farmIds = Farm::where('user_id', $params['user_id'])->column('id');
|
||
$queryWhere[] = ['farm_id', 'in', $farmIds];
|
||
}
|
||
$lists = Db::name('fence_house')->where($queryWhere)->order(['id' => 'desc'])->select()->toArray();
|
||
foreach ($lists as &$item) {
|
||
$item['fencehouseinfo'] = 'ID:' . $item['id'] . ' / 名称:' . $item['fence_house_name'];
|
||
}
|
||
return $lists;
|
||
}
|
||
} |