46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace app\ticket\logic;
|
|
|
|
use app\ticket\model\Conversation;
|
|
use support\Log;
|
|
use support\exception\BusinessException;
|
|
|
|
class ConversationLogic
|
|
{
|
|
public function list($params)
|
|
{
|
|
$where = [];
|
|
if (!empty($params['ticket_id'])) {
|
|
$where['ticket_id'] = $params['ticket_id'];
|
|
}
|
|
$size = $params['size'] ?? 10;
|
|
$current = $params['current'] ?? 1;
|
|
return Conversation::where($where)->paginate($size, ['*'], 'page', $current);
|
|
}
|
|
public function add(array $data)
|
|
{
|
|
try {
|
|
return Conversation::create($data);
|
|
} catch (\Throwable $e) {
|
|
Log::error('会话创建失败', [
|
|
'data' => $data,
|
|
'error' => $e->getMessage()
|
|
]);
|
|
throw new BusinessException('会话创建失败,请稍后重试', 500);
|
|
}
|
|
}
|
|
public function edit(array $data)
|
|
{
|
|
try {
|
|
$conversation = Conversation::updateOrCreate(['id' => $data['id']], $data);
|
|
return $conversation;
|
|
} catch (\Throwable $e) {
|
|
Log::error('会话编辑失败', [
|
|
'data' => $data,
|
|
'error' => $e->getMessage()
|
|
]);
|
|
throw new BusinessException('会话编辑失败,请稍后重试', 500);
|
|
}
|
|
}
|
|
}
|