list($params); $status_fanyi = array_map(fn($v) => "{{{$v}}}", array_flip(Constants::TICKET_STATUS)); $ossservice = new OssService(); foreach ($result as $key => $value) { $value=$value->toArray(); $value['content'] = str_replace($status_fanyi,$ticket_status,$value['content']); $value['attachment'] = empty($value['attachment'])?[]:unserialize($value['attachment']); foreach ($value['attachment'] as $k => $attachment) { $value['attachment'][$k]['storage_path_full'] = (!empty($attachment))?$ossservice->generatePrivateUrl($attachment['storage_path']):''; } $user = User::where('id', $value['user_id'])->first(); $value['user_name'] = $user?->name; $value['user_avatar'] = $user?->avatar; $value['created_at'] = date('Y-m-d H:i:s', strtotime($value['created_at'])); $value['updated_at'] = date('Y-m-d H:i:s', strtotime($value['updated_at'])); $result[$key] = $value; } return $result; } public function add(array $data) { try { $data['attachment'] = serialize($data['attachment']); 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'] : ''; $userDefault = [1, 75, 78]; $tiket_content = $ticket['content']; if (empty($conversation)) { //没有沟通记录 $title = '新工单提醒-'.$categorieName; $notice_user_id = $userDefault; }else{ $title = '工单回复'; $tiket = (new TicketLogic())->find($conversation['ticket_id']); if($data['user_id'] != $tiket['user_id']){ $notice_user_id = [$tiket['user_id']]; }else{ $conversationLast = Conversation::where('ticket_id', '=', $conversation['ticket_id']) ->where('user_id', '!=', $data['user_id']) ->orderBy('id', 'desc') ->first(); $notice_user_id = (!empty($conversationLast['user_id']))? [$conversationLast['user_id']]:$userDefault; } $tiket_content = $tiket['content']; $status_fanyi = array_map(fn($v) => "{{{$v}}}", array_flip(Constants::TICKET_STATUS)); $locale = locale(); $ticket_status = $locale == 'zh'? Constants::TICKET_STATUS_ZH:Constants::TICKET_STATUS_EN; $content = str_replace($status_fanyi,$ticket_status,$data['content']); $reply = $content?($content."\n".'工单内容:'):'' ; } $notice = ['sender_id' => 0, //发送人ID 0默认系统 'sender_type' => 'system', //发送者类型 user admin system 'title' => $title, //标题 'content' => ($reply??'') . $tiket_content, //内容 'scene' => 1, //场景 0系统公共 1系统通知 'recipient' => $notice_user_id, //接收人 空为全部 'push_method' => 0 //推送方式0系统推送1手动推送 ]; // 异步推送 \Webman\RedisQueue\Redis::send('notice', $notice); unset($data['categorie_id']); unset($data['code']); return (new ConversationLogic())->add($data); } catch (\Throwable $e) { throw $e; } } public function sendEmail(array $data) { $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' => $ticket['content'], 'reply' => '', ]; //$emailDefault = 'app@hnxinyouhe.com'; //公共邮箱 //$emailDefault = 'support@hnxinyouhe.com'; //公共邮箱 $emailDefault = env('ticket_email_default'); if (empty($conversation)) { $email = $emailDefault; }else{ $tiket = (new TicketLogic())->find($conversation['ticket_id']); if($conversation['user_id'] != $tiket['user_id']){ $email = User::where('id',$tiket['user_id'])->value('email'); }else{ $conversationLast = Conversation::where('ticket_id', '=', $conversation['ticket_id']) ->where('user_id', '!=', $conversation['user_id']) ->orderBy('id', 'desc') ->first(); $email = (!empty($conversationLast['user_id']))?User::where('id',$conversationLast['user_id'])->value('email',$emailDefault):$emailDefault; } $notice['content'] = $tiket['content']; // $notice['reply'] = '