105 lines
2.2 KiB
PHP
105 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace app\admin\logic;
|
|
|
|
|
|
use app\common\model\ProductCategory;
|
|
use app\common\logic\BaseLogic;
|
|
use think\facade\Db;
|
|
|
|
|
|
/**
|
|
* ProductCategory逻辑
|
|
* Class ProductCategoryLogic
|
|
* @package app\admin\logic
|
|
*/
|
|
class ProductCategoryLogic extends BaseLogic
|
|
{
|
|
|
|
|
|
/**
|
|
* @notes 添加
|
|
* @param array $params
|
|
* @return bool
|
|
* @author likeadmin
|
|
* @date 2025/07/11 11:41
|
|
*/
|
|
public static function add(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
ProductCategory::create([
|
|
'pid' => $params['pid'],
|
|
'name' => $params['name'],
|
|
]);
|
|
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
self::setError($e->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 编辑
|
|
* @param array $params
|
|
* @return bool
|
|
* @author likeadmin
|
|
* @date 2025/07/11 11:41
|
|
*/
|
|
public static function edit(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
ProductCategory::where('id', $params['id'])->update([
|
|
'pid' => $params['pid'],
|
|
'name' => $params['name'],
|
|
]);
|
|
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
self::setError($e->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 删除
|
|
* @param array $params
|
|
* @return bool
|
|
* @author likeadmin
|
|
* @date 2025/07/11 11:41
|
|
*/
|
|
public static function delete(array $params): bool
|
|
{
|
|
return ProductCategory::destroy($params['id']);
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 获取详情
|
|
* @param $params
|
|
* @return array
|
|
* @author likeadmin
|
|
* @date 2025/07/11 11:41
|
|
*/
|
|
public static function detail($params): array
|
|
{
|
|
return ProductCategory::findOrEmpty($params['id'])->toArray();
|
|
}
|
|
|
|
public static function all($params)
|
|
{
|
|
$query = ProductCategory::field(['id', 'pid', 'name', 'create_time']);
|
|
$list = $query->order(['id' => 'desc'])->select()->toArray();
|
|
return linear_to_tree($list, 'children');
|
|
}
|
|
|
|
}
|