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..fef9eab 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,41 @@ 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'; //公共邮箱 + $email = 'tuotuo@hnxinyouhe.com'; //范彩凤 + $email = 'beimanr@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'] = '