Files
fdesk/app/ticket/logic/ConversationLogic.php
T
2025-08-13 17:00:16 +08:00

60 lines
1.7 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);
}
}
/**
* 获取工单最新一条记录
* @param array $data
* @return Conversation|\Illuminate\Database\Eloquent\Model|object|null
*/
public function firstByTicket(int $ticketId)
{
$conversation = Conversation::where('ticket_id',$ticketId)
->orderBy('id','desc')
->first();
return $conversation;
}
}