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 @@
  • 工单编号:{{code}}
  • 工单分类:{{category}}
  • 问题描述:{{content}}
  • + {{reply}}

    请点击下方按钮立即查看详情:

    diff --git a/app/ticket/logic/CategorieLogic.php b/app/ticket/logic/CategorieLogic.php index c11bd64..7eefaed 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' => function ($query) { + $query->where('locale', locale()); + }])->where('status', 1) + ->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..4417284 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,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'] = '
  • 最新回复:' . $data['content'] . '
  • '; + } + \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; diff --git a/app/ticket/service/TicketService.php b/app/ticket/service/TicketService.php index 5d451be..d12c4e7 100644 --- a/app/ticket/service/TicketService.php +++ b/app/ticket/service/TicketService.php @@ -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'],