Merge branch 'feature/ticket0813' into develop

This commit is contained in:
2025-08-18 13:58:20 +08:00
5 changed files with 65 additions and 0 deletions
@@ -80,6 +80,7 @@
<li>工单编号:{{code}}</li>
<li>工单分类:{{category}}</li>
<li>问题描述:{{content}}</li>
{{reply}}
</ul>
<p>请点击下方按钮立即查看详情:</p>
+8
View File
@@ -23,6 +23,14 @@ class CategorieLogic
return Categorie::with('translation')->where($where)->get();
}
public function find($id)
{
return Categorie::with(['translation' => function ($query) {
$query->where('locale', locale());
}])->where('status', 1)
->find($id);
}
public function add(array $data)
{
try {
+14
View File
@@ -18,6 +18,7 @@ class ConversationLogic
$current = $params['current'] ?? 1;
return Conversation::where($where)->paginate($size, ['*'], 'page', $current);
}
public function add(array $data)
{
try {
@@ -43,4 +44,17 @@ class ConversationLogic
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;
}
}
@@ -4,7 +4,10 @@ namespace app\ticket\service;
use app\common\model\User;
use app\common\service\OssService;
use app\ticket\logic\CategorieLogic;
use app\ticket\logic\ConversationLogic;
use app\ticket\logic\TicketLogic;
use app\ticket\model\Conversation;
use config\constants\Constants;
use support\Db;
use support\exception\BusinessException;
@@ -44,6 +47,42 @@ class ConversationService
if (empty($data['content'])) {
throw new BusinessException('消息内容不能为空');
}
$conversation = (new ConversationLogic())->firstByTicket($data['ticket_id']);
$ticket = (new TicketLogic())->find($data['ticket_id']);
$categorie= (new CategorieLogic())->find($ticket['categorie_id']);
$categorieName = isset($categorie['translation']) ? $categorie['translation']['name'] : '';
$notice = [
'code' => $ticket['code'],
'category' => $categorieName,
'content' => $data['content'],
'reply' => '',
];
//$emailDefault = 'app@hnxinyouhe.com'; //公共邮箱
$emailDefault = 'tuotuo@hnxinyouhe.com'; //范彩凤
if (empty($conversation)) {
$email = $emailDefault;
}else{
$tiket = (new TicketLogic)->find($conversation['ticket_id']);
if($data['user_id'] != $tiket['user_id']){
$email = User::find($tiket['user_id'])->value('email');
}else{
$conversationLast = Conversation::where('ticket_id', '=', $conversation['ticket_id'])
->where('user_id', '!=', $data['user_id'])
->orderBy('id', 'desc')
->first();
$email = (!empty($conversationLast['user_id']))?User::find($conversationLast['user_id'])->value('email',$emailDefault):$emailDefault;
}
$notice['content'] = $tiket['content'];
$notice['reply'] = '<li>最新回复:' . $data['content'] . '</li>';
}
\app\common\utils\email\MailSend::send($email, '【XYH】新的工单提醒', replaceTpl($notice, 'work_order'));
unset($data['categorie_id']);
unset($data['code']);
return (new ConversationLogic())->add($data);
} catch (\Throwable $e) {
throw $e;
+3
View File
@@ -45,6 +45,7 @@ class TicketService
try {
$attachment = $data['attachment']??[];
$logic = new TicketLogic();
$data['code'] = $logic::generateSimpleTicketNo();
$result = $logic->add($data);
if(!empty($attachment)){
(new AttachmentLogic())->adds($attachment, $result->id, $data['user_id']);
@@ -53,6 +54,8 @@ class TicketService
$cleanContent = trim(preg_replace('/\s+/', ' ', strip_tags($data['content'] ?? '')));
$conversation = [
'ticket_id' => $result->id,
'categorie_id' => $data['categorie_id'],
'code' => $data['code'],
'content' => $cleanContent,
'user_id' => $data['user_id'],
'attachment' => $data['attachment'],