52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace app\ticket\logic;
|
|
|
|
use app\ticket\model\TicketCategorie;
|
|
use support\Log;
|
|
use support\exception\BusinessException;
|
|
|
|
class CategorieLogic
|
|
{
|
|
public function list($params)
|
|
{
|
|
$where = [];
|
|
$size = $params['size'] ?? 10;
|
|
$current = $params['current'] ?? 1;
|
|
return TicketCategorie::with('translation')->where($where)->paginate($size, ['*'], 'page', $current);
|
|
}
|
|
|
|
public function getAll($params)
|
|
{
|
|
$where = [];
|
|
$where[] = ['status', '=', 1];
|
|
return TicketCategorie::with('translation')->where($where)->get();
|
|
}
|
|
|
|
public function add(array $data)
|
|
{
|
|
try {
|
|
return TicketCategorie::create($data);
|
|
} catch (\Throwable $e) {
|
|
Log::error('分类创建失败', [
|
|
'data' => $data,
|
|
'error' => $e->getMessage()
|
|
]);
|
|
throw new BusinessException($e->getMessage().'分类创建失败,请稍后重试', 500);
|
|
}
|
|
}
|
|
|
|
public function edit(array $data)
|
|
{
|
|
try {
|
|
$categorie = TicketCategorie::updateOrCreate(['id' => $data['id']], $data);
|
|
return $categorie;
|
|
} catch (\Throwable $e) {
|
|
Log::error('分类编辑失败', [
|
|
'data' => $data,
|
|
'error' => $e->getMessage()
|
|
]);
|
|
throw new BusinessException($e->getMessage().'分类编辑失败,请稍后重试', 500);
|
|
}
|
|
}
|
|
}
|