Merge branch 'develop'
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace app\ticket\service;
|
||||
|
||||
use app\queue\translation\service\TranslationService;
|
||||
use app\queue\utils\Translat;
|
||||
use app\ticket\logic\CategorieLogic;
|
||||
use app\ticket\model\CategorieTranslation;
|
||||
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
|
||||
// );
|
||||
CategorieTranslation::updateOrCreate(
|
||||
[
|
||||
'categorie_id' => $data['id'],
|
||||
'locale' => $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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\ticket\service;
|
||||
|
||||
use app\ticket\logic\ConversationLogic;
|
||||
use config\constants\Constants;
|
||||
use support\Db;
|
||||
use support\exception\BusinessException;
|
||||
|
||||
class ConversationService
|
||||
{
|
||||
public function list($params)
|
||||
{
|
||||
$locale = locale();
|
||||
// $locale = 'zh';
|
||||
$ticket_status = $locale == 'zh'? Constants::TICKET_STATUS_ZH:Constants::TICKET_STATUS_EN;
|
||||
// $ticket_status = Constants::TICKET_STATUS_ZH;
|
||||
// $params['locale'] = locale();
|
||||
$result = (new ConversationLogic())->list($params);
|
||||
|
||||
$status_fanyi = array_map(fn($v) => "{{{$v}}}", array_flip(Constants::TICKET_STATUS));
|
||||
foreach ($result as $key => $value) {
|
||||
$result[$key]['content'] = str_replace($status_fanyi,$ticket_status,$value['content']);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function add(array $data)
|
||||
{
|
||||
try {
|
||||
return (new ConversationLogic())->add($data);
|
||||
} catch (\Throwable $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function edit(array $data)
|
||||
{
|
||||
try {
|
||||
Db::beginTransaction();
|
||||
$result = (new ConversationLogic())->edit($data);
|
||||
Db::commit();
|
||||
return $result;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace app\ticket\service;
|
||||
|
||||
use app\ticket\logic\AttachmentLogic;
|
||||
use app\ticket\logic\ConversationLogic;
|
||||
use app\ticket\logic\TicketLogic;
|
||||
use app\ticket\model\Ticket;
|
||||
use config\constants\Constants;
|
||||
use support\Db;
|
||||
use support\exception\BusinessException;
|
||||
use support\Log;
|
||||
|
||||
class TicketService
|
||||
{
|
||||
|
||||
public function list($params)
|
||||
{
|
||||
$res = (new TicketLogic())->list($params);
|
||||
foreach ($res as $k => &$v) {
|
||||
$name = isset($v['categorie']['translation']) ? $v['categorie']['translation']['name'] : '';
|
||||
if(isset($res[$k]['categorie'])){
|
||||
$res[$k]['categorie']['name'] = $name;
|
||||
}
|
||||
if (isset($v['categorie']['translation'])){
|
||||
unset($res[$k]['categorie']['translation']);
|
||||
}
|
||||
foreach ($v['attachments'] as &$attachments) {
|
||||
$attachments['storage_path_full'] = (new \app\common\service\OssService())->generatePrivateUrl($attachments['storage_path']);
|
||||
}
|
||||
}
|
||||
unset($v);
|
||||
unset($attachments);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function add(array $data)
|
||||
{
|
||||
try {
|
||||
$attachment = $data['attachment']??[];
|
||||
$logic = new TicketLogic();
|
||||
$result = $logic->add($data);
|
||||
if(!empty($attachment)){
|
||||
(new AttachmentLogic())->adds($attachment, $result->id, $data['user_id']);
|
||||
}
|
||||
return $result;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function edit(array $data)
|
||||
{
|
||||
try {
|
||||
Db::beginTransaction();
|
||||
$attachment = $data['attachment']??[];
|
||||
$logic = new TicketLogic();
|
||||
$result = $logic->edit($data);
|
||||
|
||||
if(!empty($attachment)){
|
||||
(new AttachmentLogic())->edit($attachment, $result->id, $data['user_id']);
|
||||
}
|
||||
Db::commit();
|
||||
return $result;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function status(array $data)
|
||||
{
|
||||
try {
|
||||
Db::beginTransaction();
|
||||
$msg = $data['msg']??[];
|
||||
$ticket = (new TicketLogic())->find($data['id']);
|
||||
if(empty($ticket)){
|
||||
throw new BusinessException('工单不存在');
|
||||
}
|
||||
if($data['status'] <= $ticket->status){
|
||||
throw new BusinessException(trans('status_not_modified'));
|
||||
}
|
||||
|
||||
// if(!in_array($ticket->status, [Constants::TICKET_STATUS['PENDING'], Constants::TICKET_STATUS['CONFIRM']])
|
||||
// && empty($msg)){
|
||||
// throw new BusinessException('提交失败');
|
||||
// }
|
||||
|
||||
$ticket->status = $data['status'];
|
||||
$result = $ticket->save();
|
||||
|
||||
if(!empty($msg)){
|
||||
$conversation = [
|
||||
'ticket_id' => $ticket->id,
|
||||
'user_id' => $data['user_id'],
|
||||
'content' => '状态更新为{{'.array_search($data['status'],Constants::TICKET_STATUS).'}}:'.$msg
|
||||
];
|
||||
$res = (new ConversationLogic())->add($conversation);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return $result;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function getStatus(array $data)
|
||||
{
|
||||
$locale = locale();
|
||||
$ticket_status = $locale == 'zh'? Constants::TICKET_STATUS_ZH:Constants::TICKET_STATUS_EN;
|
||||
|
||||
$status = [];
|
||||
foreach ($ticket_status as $key => $value) {
|
||||
$status[] = ['value' => $key, 'text' => $value];
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user