From 9ae23153f640dee3accd6a870f7003aade5d651e Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 13 Aug 2025 17:00:16 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=B7=A5=E5=8D=95=E5=8F=91=E9=80=81?= =?UTF-8?q?=E9=82=AE=E4=BB=B6=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/scaffold/templates/workOrder.stub | 1 + app/ticket/logic/CategorieLogic.php | 8 +++++ app/ticket/logic/ConversationLogic.php | 14 ++++++++ app/ticket/service/ConversationService.php | 36 +++++++++++++++++++ app/ticket/service/TicketService.php | 3 ++ 5 files changed, 62 insertions(+) diff --git a/app/common/utils/scaffold/templates/workOrder.stub b/app/common/utils/scaffold/templates/workOrder.stub index c7b6ab0..9f592dd 100644 --- a/app/common/utils/scaffold/templates/workOrder.stub +++ b/app/common/utils/scaffold/templates/workOrder.stub @@ -80,6 +80,7 @@
请点击下方按钮立即查看详情:
diff --git a/app/ticket/logic/CategorieLogic.php b/app/ticket/logic/CategorieLogic.php index c11bd64..f9f1014 100644 --- a/app/ticket/logic/CategorieLogic.php +++ b/app/ticket/logic/CategorieLogic.php @@ -23,6 +23,14 @@ class CategorieLogic return Categorie::with('translation')->where($where)->get(); } + public function find($id) + { + return Categorie::with('translation') + ->where('status',1) + ->where('locale', locale()) + ->find($id); + } + public function add(array $data) { try { diff --git a/app/ticket/logic/ConversationLogic.php b/app/ticket/logic/ConversationLogic.php index d47a709..53a5a18 100644 --- a/app/ticket/logic/ConversationLogic.php +++ b/app/ticket/logic/ConversationLogic.php @@ -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; + } } \ No newline at end of file diff --git a/app/ticket/service/ConversationService.php b/app/ticket/service/ConversationService.php index c9cbd17..ea52002 100644 --- a/app/ticket/service/ConversationService.php +++ b/app/ticket/service/ConversationService.php @@ -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,39 @@ class ConversationService if (empty($data['content'])) { throw new BusinessException('消息内容不能为空'); } + + $conversation = (new ConversationLogic())->firstByTicket($data['ticket_id']); + $categorie= (new CategorieLogic())->find($data['categorie_id']); + $categorieName = isset($categorie['translation']) ? $categorie['translation']['name'] : ''; + + $notice = [ + 'code' => $data['code'], + 'category' => $categorieName, + 'content' => $data['content'], + 'reply' => '', + ]; + if (empty($conversation)) { + $email = 'app@hnxinyouhe.com'; + }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('user_id', '=', $conversation['user_id']) + ->where('ticket_id', '=', $conversation['ticket_id']) + ->where('user_id', '!=', $conversation['user_id']) + ->orderBy('id', 'desc') + ->first(); + $email = User::find($conversationLast['user_id'])->value('email','app@hnxinyouhe.com'); + } + $notice['content'] = $tiket['content']; + $notice['reply'] = '