97 lines
2.6 KiB
PHP
97 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace app\ticket\service;
|
|
|
|
use app\queue\translation\service\TranslationService;
|
|
use app\queue\utils\Translat;
|
|
use app\ticket\logic\CategorieLogic;
|
|
use support\Db;
|
|
use support\exception\BusinessException;
|
|
|
|
class CategorieService
|
|
{
|
|
public function list($params)
|
|
{
|
|
$result = (new CategorieLogic())->list($params);
|
|
$value=$result[0]->toArray();
|
|
foreach ($result as $key => &$value) {
|
|
$value['name'] = isset($value['translation']) ? $value['translation']['name'] : '';
|
|
unset($value['translation']);
|
|
}
|
|
unset($value);
|
|
|
|
return $result;
|
|
}
|
|
|
|
public function getAll($params)
|
|
{
|
|
$result = (new CategorieLogic())->getAll($params);
|
|
foreach ($result as $key => &$value) {
|
|
$value['name'] = isset($value['translation']) ? $value['translation']['name'] : '';
|
|
unset($value['translation']);
|
|
}
|
|
unset($value);
|
|
|
|
return $result;
|
|
}
|
|
|
|
public $translatFields = ['name'];
|
|
|
|
public function add(array $data)
|
|
{
|
|
try {
|
|
Db::beginTransaction();
|
|
$sourceLocale = locale();
|
|
$traitsourceFields = Translat::extractSourceFields($data, $this->translatFields);
|
|
|
|
$result = (new CategorieLogic())->add($data);
|
|
|
|
(new TranslationService())->queueTranslations(
|
|
'ticket_categorie',
|
|
$result->id,
|
|
$sourceLocale,
|
|
$traitsourceFields
|
|
);
|
|
|
|
Db::commit();
|
|
return $result;
|
|
} catch (\Throwable $e) {
|
|
Db::rollback();
|
|
throw $e;
|
|
}
|
|
}
|
|
public function edit(array $data)
|
|
{
|
|
try {
|
|
Db::beginTransaction();
|
|
$sourceLocale = locale();
|
|
$traitsourceFields = Translat::extractSourceFields($data, $this->translatFields);
|
|
|
|
$result = (new CategorieLogic())->edit($data);
|
|
|
|
(new TranslationService())->queueTranslations(
|
|
'ticket_categorie',
|
|
$data['id'],
|
|
$sourceLocale,
|
|
$traitsourceFields
|
|
);
|
|
Db::commit();
|
|
return $result;
|
|
} catch (\Throwable $e) {
|
|
Db::rollback();
|
|
throw $e;
|
|
}
|
|
}
|
|
public function delete(int $id)
|
|
{
|
|
if(empty($id)){
|
|
throw new BusinessException('id不能为空');
|
|
}
|
|
try {
|
|
$result = (new CategorieLogic())->delete($id);
|
|
return $result;
|
|
} catch (\Throwable $e) {
|
|
throw $e;
|
|
}
|
|
}
|
|
}
|