2025-07-03 15:28:19 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\ticket\service;
|
|
|
|
|
|
2025-08-08 09:38:02 +08:00
|
|
|
use app\common\service\OssService;
|
2025-07-03 15:28:19 +08:00
|
|
|
use app\ticket\logic\ConversationLogic;
|
|
|
|
|
use config\constants\Constants;
|
|
|
|
|
use support\Db;
|
|
|
|
|
use support\exception\BusinessException;
|
|
|
|
|
|
|
|
|
|
class ConversationService
|
|
|
|
|
{
|
|
|
|
|
public function list($params)
|
|
|
|
|
{
|
2025-07-04 13:45:50 +08:00
|
|
|
$locale = locale();
|
|
|
|
|
// $locale = 'zh';
|
2025-07-03 15:28:19 +08:00
|
|
|
$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));
|
2025-08-08 09:38:02 +08:00
|
|
|
$ossservice = new OssService();
|
2025-07-03 15:28:19 +08:00
|
|
|
foreach ($result as $key => $value) {
|
|
|
|
|
$result[$key]['content'] = str_replace($status_fanyi,$ticket_status,$value['content']);
|
2025-08-08 09:38:02 +08:00
|
|
|
$result[$key]['attachment'] = explode(",", $value['attachment']);
|
|
|
|
|
foreach ($result[$key]['attachment'] as $k => $attachment) {
|
|
|
|
|
$result[$key]['attachment_full'][$k] = (!empty($attachment))?$ossservice->generatePrivateUrl($attachment):'';
|
|
|
|
|
}
|
2025-07-03 15:28:19 +08:00
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function add(array $data)
|
|
|
|
|
{
|
|
|
|
|
try {
|
2025-08-08 09:38:02 +08:00
|
|
|
$data['attachment'] = implode(",", $data['attachment']);
|
2025-07-03 15:28:19 +08:00
|
|
|
return (new ConversationLogic())->add($data);
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function edit(array $data)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
Db::beginTransaction();
|
2025-08-08 09:38:02 +08:00
|
|
|
$data['attachment'] = implode(",", $data['attachment']);
|
2025-07-03 15:28:19 +08:00
|
|
|
$result = (new ConversationLogic())->edit($data);
|
|
|
|
|
Db::commit();
|
|
|
|
|
return $result;
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
Db::rollback();
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|