コード例 #1
0
 public function updated(WorkOrder $workOrder)
 {
     $sendedUsers = [];
     $messageData = [];
     switch ($workOrder->status) {
         case 0:
             $messageData = ['title' => '工单 #' . $workOrder->id . ' 已关闭', 'template' => 'host.communication.message.template.closed'];
             break;
         case 2:
             $messageData = ['title' => '工单 #' . $workOrder->id . ' 已被受理', 'template' => 'host.communication.message.template.accept'];
             break;
         case 3:
             $messageData = ['title' => '工单 #' . $workOrder->id . ' 已被标记为解决', 'template' => 'host.communication.message.template.solved'];
             break;
     }
     foreach ($workOrder->participants as $participant) {
         if ($participant->id == \Auth::id()) {
             continue;
         }
         $url = \get_uri_path(route('host.work.work-order.show', $workOrder->id));
         $message = new Message();
         $message->title = $messageData['title'];
         $message->content = view($messageData['template'], ['workOrder' => $workOrder, 'url' => $url]);
         $message->sendTo($participant);
         // 当工单解决或关闭则取消关注
         if ($workOrder->status == 0 || $workOrder->status == 3) {
             $workOrder->participants()->detach($participant->id);
         }
         $sendedUsers[] = $participant->id;
     }
     foreach ($workOrder->group->participants as $participant) {
         if ($participant->id == \Auth::id()) {
             continue;
         }
         if (!in_array($participant->id, $sendedUsers)) {
             $url = \get_uri_path(route('host.work.work-order.show', $workOrder->id));
             $message = new Message();
             $message->title = $messageData['title'];
             $message->content = view($messageData['template'], ['workOrder' => $workOrder, 'url' => $url]);
             $message->sendTo($participant);
         }
     }
     // 创建历史
     $history = new WorkOrderHistory();
     $history->event_id = WorkOrderHistory::EVENT_WORK_ORDER_STATUS_CHANGE;
     $history->remark = json_encode(['status' => $workOrder->status]);
     $history->workOrder()->associate($workOrder);
     $history->user()->associate(\Auth::user());
     $history->save();
 }
コード例 #2
0
 public function created(WorkOrderMessage $message)
 {
     if ($message->workOrder->messages()->count() > 1) {
         $workOrder = $message->workOrder;
         $workOrder->increment('activity');
         $sendedUsers = [];
         foreach ($workOrder->participants as $participant) {
             if ($participant->id == \Auth::id()) {
                 continue;
             }
             $url = \get_uri_path(route('host.work.work-order.show', $workOrder->id));
             $message = new Message();
             $message->title = '工单 #' . $workOrder->id . ' 有新的动态';
             $message->content = view('host.communication.message.template.new-work-order-dynamic', ['workOrder' => $workOrder, 'url' => $url]);
             $message->sendTo($participant);
             $sendedUsers[] = $participant->id;
         }
         // 当在一个工单下发布消息,则认为关注了该工单
         if (!$workOrder->participants()->whereId(\Auth::id())->count()) {
             $workOrder->participants()->attach(\Auth::id());
         }
         if (\Auth::id() != $workOrder->user_id && $workOrder->status == 1) {
             $workOrder->status = 2;
             $workOrder->save();
         }
         foreach ($workOrder->group->participants as $participant) {
             if ($participant->id == \Auth::id()) {
                 continue;
             }
             if (!in_array($participant->id, $sendedUsers)) {
                 $url = \get_uri_path(route('host.work.work-order.show', $workOrder->id));
                 $message = new Message();
                 $message->title = '工单 #' . $workOrder->id . ' 有新的动态';
                 $message->content = view('host.communication.message.template.new-work-order-dynamic', ['workOrder' => $workOrder, 'url' => $url]);
                 $message->sendTo($participant);
             }
         }
         $history = new WorkOrderHistory();
         $history->event_id = WorkOrderHistory::EVENT_NEW_WORK_ORDER_MESSAGE;
         $history->remark = json_encode(['message_id' => $message->id]);
         $history->user()->associate(\Auth::user());
         $history->workOrder()->associate($workOrder);
         $history->save();
     }
 }