示例#1
0
 public function parse(GmailEvent $event)
 {
     if (!$event->isHandled()) {
         MSupportTicket::unguard();
         MSupportReply::unguard();
         $info = $event->getFrom();
         $now = Carbon::now();
         if ($email = $info['email'] ?? null) {
             $user = User::where('email', '=', $email)->orWhere('contact_email', '=', $email)->first();
             if (empty($user) || empty($user->user_id)) {
                 $signup = new UserSignupEvent(array_merge($info, ['verified' => 'true']));
                 $this->dispatcher->fire(UserSignupEvent::USER_SIGNUP_BEGIN, $signup);
                 $user = $signup->getUser();
             }
             if (preg_match('/^T(\\d+)$/', $event->getRef(), $matches)) {
                 $ticket = MSupportTicket::find($matches[1]);
             }
             if (empty($ticket) || empty($ticket->ticket_id)) {
                 $ticket = MSupportTicket::where('user_id', '=', $user->user_id)->where('title', '=', $event->getSubject())->first();
                 if (empty($ticket) || empty($ticket->support_ticket_id)) {
                     $ticket = MSupportTicket::create(['user_id' => $user->user_id, 'created_at' => $now, 'updated_at' => $now, 'title' => $event->getSubject(), 'category' => 'General', 'state' => 'open']);
                 }
             }
             /** @var MSupportReply $reply */
             $reply = MSupportReply::create(['support_ticket_id' => $ticket->support_ticket_id, 'user_id' => $user->user_id, 'created_at' => $now, 'reply_safe' => $event->getText()]);
             $event->setHandled($reply->support_reply_id > 0);
         }
     }
 }
示例#2
0
 public function index(string $_mode, array $_models, RouteEx $_route, array $_parents, string $alias)
 {
     $return = $this->postHandler->index($_mode, $_models, $_route, $_parents, $alias);
     $model = $_models[0];
     if ($model instanceof MSupportTicket) {
         $eventName = 'admin.support.' . 'status';
         $ticketData = $model->attributesToArray();
     } elseif ($model instanceof MSupportReply) {
         $eventName = 'admin.support.' . 'reply';
         /** @var MSupportTicket $ticket */
         if ($ticket = MSupportTicket::find($model->support_ticket_id)) {
             $ticketData = array_merge($model->attributesToArray(), $ticket->attributesToArray());
         }
     }
     if (!empty($eventName) && !empty($ticketData)) {
         $this->dispatcher->fire($eventName, new SupportEvent($model->user_id, $ticketData));
     }
     return $return;
 }