登录
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace app\ticket\logic;
|
||||
|
||||
use app\ticket\model\Categorie;
|
||||
use support\Log;
|
||||
use support\exception\BusinessException;
|
||||
|
||||
class CategorieLogic
|
||||
{
|
||||
public function list($params)
|
||||
{
|
||||
$where = [];
|
||||
$size = $params['size'] ?? 10;
|
||||
$current = $params['current'] ?? 1;
|
||||
return Categorie::with('translation')->where($where)->paginate($size, ['*'], 'page', $current);
|
||||
}
|
||||
|
||||
public function getAll($params)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['status', '=', 1];
|
||||
return Categorie::with('translation')->where($where)->get();
|
||||
}
|
||||
|
||||
public function find($id)
|
||||
{
|
||||
return Categorie::with(['translation' => function ($query) {
|
||||
$query->where('locale', locale());
|
||||
}])->where('status', 1)
|
||||
->find($id);
|
||||
}
|
||||
|
||||
public function add(array $data)
|
||||
{
|
||||
try {
|
||||
return Categorie::create($data);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('分类创建失败', [
|
||||
'data' => $data,
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
throw new BusinessException('分类创建失败,请稍后重试', 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function edit(array $data)
|
||||
{
|
||||
try {
|
||||
$categorie = Categorie::updateOrCreate(['id' => $data['id']], $data);
|
||||
return $categorie;
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('分类编辑失败', [
|
||||
'data' => $data,
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
throw new BusinessException('分类编辑失败,请稍后重试', 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(int $id)
|
||||
{
|
||||
try {
|
||||
$categorie = Categorie::where(['id'=>$id])->delete();
|
||||
return $categorie;
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('分类删除失败', [
|
||||
'id' => $id,
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
throw new BusinessException('分类删除失败,请稍后重试', 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user