예제 #1
0
 /**
  * Process all Topic's (items, payments, questions, orders)
  */
 private function _processTopic()
 {
     $notifications = new Notifications();
     $exist = $notifications->where('resource', '=', $this->topics->resource)->count();
     if ($exist) {
         return;
     }
     $classModel = ucfirst($this->topics->topic);
     if (isset($this->topics->resource)) {
         $topic = $this->getTopic();
         if ($topic) {
             if ($classModel == 'Orders') {
                 $topicModel = new Order($topic);
                 $this->topics->process = $topicModel->send();
                 //var_dump($this->topics->process);die;
             } else {
                 if ($classModel == 'Questions') {
                     $topicModel = new Question($topic);
                     $this->topics->process = $topicModel->send();
                     if ($this->topics->process == null) {
                         return;
                     }
                 } else {
                     if ($classModel == 'Items') {
                         $topicModel = new Item($topic);
                         $this->topics->process = $topicModel->send();
                     } else {
                         if ($classModel == 'Payments') {
                             $topicModel = new Payment();
                             $this->topics->process = $topicModel->send();
                         } else {
                             return;
                         }
                     }
                 }
             }
         } else {
             $this->topics->process = false;
         }
     } else {
         $this->topics->process = false;
     }
     $notifications->saveNotification($this->topics);
 }
예제 #2
0
 public function saveNotification($notitication)
 {
     $resource = explode('/', $notitication->resource);
     $flag = Notifications::where('resource_id', $resource[2])->first();
     if (isset($flag->id)) {
         $notification = Notifications::find($flag->id);
         $notification->attempts = $notification->attempts + 1;
         $notification->save();
     } else {
         $this->resource = $notitication->resource;
         $this->resource_id = $resource[2];
         $this->type = $resource[1];
         $this->user_id = $notitication->user_id;
         $this->application_id = $notitication->application_id;
         $this->attempts = $notitication->attempts;
         $this->status = (int) $notitication->process;
         $this->sent = date('Y-m-d H:i:s', strtotime($notitication->sent));
         $this->received = date('Y-m-d H:i:s', strtotime($notitication->received));
         $this->save();
     }
 }
예제 #3
0
 public function getNotifications()
 {
     $notifications = Notifications::where('is_view', 0)->orderBy('received', 'desc')->take(15)->get();
     return response()->json($notifications);
 }