2025-02-26 10:13:24 +08:00

101 lines
2.2 KiB
PHP

<?php
namespace app\admin\logic\setting\cate;
use app\common\model\setting\cate\Cate;
use app\common\logic\BaseLogic;
use support\exception\BusinessException;
use think\facade\Db;
/**
* 首页导航逻辑
* Class CateLogic
* @package app\admin\logic\setting\cate
*/
class CateLogic extends BaseLogic
{
/**
* @notes 添加首页导航
* @param array $params
* @return bool
* @author admin
* @date 2024/12/27 20:14
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
Cate::create([
'pid' => $params['pid'],
'name' => $params['name'],
'paths' => $params['paths'],
'sort' => $params['sort'],
'is_show' => $params['is_show']
]);
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
/**
* @notes 编辑首页导航
* @param array $params
* @return bool
* @author admin
* @date 2024/12/27 20:14
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
Cate::where('id', $params['id'])->update([
'pid' => $params['pid'],
'name' => $params['name'],
'paths' => $params['paths'],
'sort' => $params['sort'],
'is_show' => $params['is_show']
]);
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
/**
* @notes 删除首页导航
* @param array $params
* @return bool
* @author admin
* @date 2024/12/27 20:14
*/
public static function delete(array $params): bool
{
return Cate::destroy($params['id']);
}
/**
* @notes 获取首页导航详情
* @param $params
* @return array
* @author admin
* @date 2024/12/27 20:14
*/
public static function detail($params): array
{
return Cate::findOrEmpty($params['id'])->toArray();
}
}