예제 #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postOrder()
 {
     $key = \Input::get('key');
     //$user = \Apiauth::user($key);
     $user = \Device::where('key', '=', $key)->first();
     if (!$user) {
         $actor = 'no id : no name';
         \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'device not found, upload image failed'));
         return \Response::json(array('status' => 'ERR:NODEVICE', 'timestamp' => time(), 'message' => 'Device Unregistered'));
     }
     $json = \Input::all();
     $batch = \Input::get('batch');
     $result = array();
     foreach ($json as $j) {
         //$j['mtimestamp'] = new \MongoDate(time());
         if (is_array($j)) {
             $olog = new \Orderlog();
             foreach ($j as $k => $v) {
                 $olog->{$k} = $v;
             }
             $olog->mtimestamp = new \MongoDate(time());
             $r = $olog->save();
             $shipment = \Shipment::where('delivery_id', '=', $olog->deliveryId)->first();
             if ($shipment) {
                 //$shipment->status = $olog->status;
                 $shipment->courier_status = $olog->courierStatus;
                 $shipment->pending_count = new \MongoInt32($olog->pendingCount);
                 if ($olog->courierStatus == \Config::get('jayon.trans_cr_oncr') || $olog->courierStatus == \Config::get('jayon.trans_cr_oncr_partial')) {
                     $shipment->pickup_status = \Config::get('jayon.trans_status_pickup');
                 }
                 $shipment->save();
             }
             if ($r) {
                 $result[] = array('status' => 'OK', 'timestamp' => time(), 'message' => 'log inserted');
             } else {
                 $result[] = array('status' => 'NOK', 'timestamp' => time(), 'message' => 'insertion failed');
             }
         }
     }
     //print_r($result);
     //die();
     $actor = $user->identifier . ' : ' . $user->devname;
     \Event::fire('log.api', array($this->controller_name, 'get', $actor, 'sync scan log'));
     return Response::json($result);
 }
예제 #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postOrder()
 {
     date_default_timezone_set('Asia/Jakarta');
     $key = \Input::get('key');
     $appname = \Input::has('app') ? \Input::get('app') : 'app.name';
     //$user = \Apiauth::user($key);
     $user = \Device::where('key', '=', $key)->first();
     if (!$user) {
         $actor = 'no id : no name';
         \Event::fire('log.api', array($this->controller_name, 'post', $actor, 'device not found, upload image failed'));
         return \Response::json(array('status' => 'ERR:NODEVICE', 'timestamp' => time(), 'message' => $image_id));
     }
     $json = \Input::all();
     $batch = \Input::get('batch');
     $result = array();
     foreach ($json as $j) {
         //$j['mtimestamp'] = new \MongoDate(time());
         if (is_array($j)) {
             $olog = new \Orderlog();
             foreach ($j as $k => $v) {
                 $olog->{$k} = $v;
             }
             $olog->mtimestamp = new \MongoDate(time());
             $olog->appname = $appname;
             $olog->deviceActor = isset($user->identifier) ? $user->identifier : '';
             $olog->deliveryDevId = $user->identifier;
             $r = $olog->save();
             $shipment = \Shipment::where('delivery_id', '=', $olog->deliveryId)->first();
             $changes = false;
             if ($shipment) {
                 if ($shipment->status == 'delivered' || $shipment->status == 'returned') {
                     $changes = false;
                 } else {
                     $changes = true;
                 }
                 $shipment->courier_status = $olog->courierStatus;
                 if ($olog->deliveryNote != '') {
                     $shipment->delivery_note = $olog->deliveryNote;
                 }
                 if ($olog->latitude != '') {
                     $shipment->latitude = doubleval($olog->latitude);
                     $shipment->dir_lat = doubleval($olog->latitude);
                 }
                 if ($olog->longitude != '') {
                     $shipment->longitude = doubleval($olog->longitude);
                     $shipment->dir_lon = doubleval($olog->longitude);
                 }
                 $shipment->save();
                 /*
                 if($olog->status == 'pending'){
                     $shipment->status = $olog->status;
                     if($shipment->delivery_note != $olog->deliveryNote){
                         $shipment->pending_count = $shipment->pending_count + 1;
                     }
                     $shipment->delivery_note = $olog->deliveryNote;
                 
                 }else
                 */
                 if ($olog->status == 'delivered' || $olog->status == 'returned' || $olog->status == 'pending') {
                     if ($olog->status == 'pending') {
                         if ($shipment->delivery_note != $olog->deliveryNote) {
                             //$shipment->pending_count = $shipment->pending_count + 1;
                         }
                     }
                     if ($olog->status == 'delivered' && $shipment->status != 'delivered') {
                         if ($olog->deliverytime == '' || $olog->deliverytime == '0000-00-00 00:00:00') {
                             $shipment->deliverytime = date('Y-m-d H:i:s', time());
                             $shipment->eventtime = date('Y-m-d H:i:s', time());
                         } else {
                             $shipment->deliverytime = $olog->deliverytime;
                             $shipment->eventtime = $olog->deliverytime;
                         }
                     } else {
                         if ($olog->deliverytime == '' || $olog->deliverytime == '0000-00-00 00:00:00') {
                             $shipment->eventtime = date('Y-m-d H:i:s', time());
                         } else {
                             $shipment->eventtime = $olog->deliverytime;
                         }
                     }
                     $shipment->status = $olog->status;
                 }
                 //$shipment->status = $olog->status;
                 //$shipment->courier_status = $olog->courierStatus;
                 /*
                                     if($olog->disposition == $key && isset($user->node_id)){
                 
                                         $shipment->position = $user->node_id;
                                     }*/
                 /*
                 $shipment->pending_count = new \MongoInt32($olog->pendingCount) ;
                 
                 if($olog->courierStatus == \Config::get('jayon.trans_cr_oncr') || $olog->courierStatus == \Config::get('jayon.trans_cr_oncr_partial'))
                 {
                     $shipment->pickup_status = \Config::get('jayon.trans_status_pickup');
                 }
                 */
                 if ($changes == true) {
                     $shipment->save();
                 }
                 $is_there = \Geolog::where('datetimestamp', '=', $shipment->deliverytime)->where('deliveryId', '=', $shipment->delivery_id)->where('deviceId', '=', $user->identifier)->where('appname', '=', $appname)->where('status', '=', $olog->status)->where('sourceSensor', '=', 'gps')->count();
                 if ($is_there == 0) {
                     $geolog = array('datetimestamp' => $shipment->deliverytime, 'deliveryId' => $shipment->delivery_id, 'deviceId' => $user->identifier, 'status' => $olog->status, 'deviceKey' => $user->key, 'extId' => 'noid', 'latitude' => doubleval($olog->latitude), 'longitude' => doubleval($olog->longitude), 'sourceSensor' => 'gps', 'timestamp' => strval(strtotime($shipment->deliverytime)), 'uploaded' => 1, 'appname' => $appname, 'mtimestamp' => new \MongoDate(strtotime($shipment->deliverytime)));
                     \Geolog::insert($geolog);
                 }
             }
             if ($r) {
                 $result[] = array('status' => 'OK', 'timestamp' => time(), 'message' => 'log inserted');
             } else {
                 $result[] = array('status' => 'NOK', 'timestamp' => time(), 'message' => 'insertion failed');
             }
         }
     }
     //print_r($result);
     //die();
     $actor = $user->identifier . ' : ' . $user->devname;
     \Event::fire('log.api', array($this->controller_name, 'get', $actor, 'sync scan log'));
     return Response::json($result);
 }