Beispiel #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $shipped = Shipment::where('deliverytime', 'like', '2016-01-11%')->get();
     //print_r($shipped);
     foreach ($shipped as $shipment) {
         $is_there = Geolog::where('datetimestamp', '=', $shipment->deliverytime)->where('deliveryId', '=', $shipment->delivery_id)->where('sourceSensor', '=', 'gps')->get();
         if ($is_there) {
             print_r($is_there);
             $stay = array_pop($is_there->toArray());
             foreach ($is_there as $there) {
                 print 'there' . "\r\n";
                 print_r($there);
                 //$there->remove();
             }
             print 'stay' . "\r\n";
             print_r($stay);
             if ($stay) {
                 $stay->latitude = doubleval($shipment->latitude);
                 $stay->longitude = doubleval($shipment->longitude);
                 //$stay->save();
             }
         }
     }
     /*
     $dbox = Orderlog::where('pickupStatus','=',Config::get('jayon.trans_status_pickup'))
                         ->where('pickuptime','!=','0000-00-00 00:00:00')
                         ->orderBy('created_at','desc')
                         //->groupBy('created_at')
                         ->get();
     
     if($dbox){
         print count($dbox)."\r\n";
         foreach($dbox as $dbx){
     
             print_r(array($dbx->pickupStatus, $dbx->pickuptime) );
     
             $ship = Shipment::where('delivery_id','=',$dbx->deliveryId)
                         ->where('pickuptime','!=','0000-00-00 00:00:00')
                         ->first();
             if($ship){
                 print 'before : '.$ship->pickup_status."\r\n";
                 print 'before : '.$ship->pickuptime."\r\n";
     
                 $pickuptime = ($dbx->pickuptime == '0000-00-00 00:00:00')? date('Y-m-d H:i:s', $dbx->created_at->sec ) :$dbx->pickuptime;
     
                 $ship->pickup_status = $dbx->pickupStatus;
                 $ship->pickuptime = $pickuptime;
     
                 $ship->save();
                 //print_r( $ship->toArray());
     
                 print 'after : '.$ship->pickup_status."\r\n";
                 print 'after : '.$ship->pickuptime."\r\n";
             }
         }
     }
     */
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postGeolog()
 {
     $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) {
         if (isset($j['logId'])) {
             if (isset($j['datetimestamp'])) {
                 $j['mtimestamp'] = new \MongoDate(strtotime($j['datetimestamp']));
             }
             $log = \Geolog::where('logId', $j['logId'])->first();
             if ($log) {
                 $result[] = array('status' => 'OK', 'timestamp' => time(), 'message' => $j['logId']);
             } else {
                 \Geolog::insert($j);
                 $result[] = array('status' => 'OK', 'timestamp' => time(), 'message' => $j['logId']);
             }
         }
     }
     //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);
 }