Files
fdesk/app/ticket/service/ConversationService.php
T
2025-08-11 10:27:05 +08:00

61 lines
2.0 KiB
PHP

<?php
namespace app\ticket\service;
use app\common\service\OssService;
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));
$result = $result??$result->toArray();
$ossservice = new OssService();
foreach ($result as $key => $value) {
$result[$key]['content'] = str_replace($status_fanyi,$ticket_status,$value['content']);
$result[$key]['attachment'] = empty($value['attachment'])?[]:unserialize($value['attachment']);
foreach ($result[$key]['attachment'] as $k => $attachment) {
$result[$key]['attachment']['storage_path_full'][$k] = (!empty($attachment))?$ossservice->generatePrivateUrl($attachment['storage_path']):'';
}
}
return $result;
}
public function add(array $data)
{
try {
$data['attachment'] = serialize($data['attachment']);
if (empty($data['content'])) {
throw new BusinessException('消息内容不能为空');
}
return (new ConversationLogic())->add($data);
} catch (\Throwable $e) {
throw $e;
}
}
public function edit(array $data)
{
try {
Db::beginTransaction();
$data['attachment'] = serialize($data['attachment']);
$result = (new ConversationLogic())->edit($data);
Db::commit();
return $result;
} catch (\Throwable $e) {
Db::rollback();
throw $e;
}
}
}