コード例 #1
0
ファイル: Backtrack.php プロジェクト: awidarto/jexadmin
 /**
  * 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";
             }
         }
     }
     */
 }
コード例 #2
0
 /**
  * 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);
 }
コード例 #3
0
ファイル: AjaxController.php プロジェクト: awidarto/jexadmin
 public function postLocationlog()
 {
     $device_name = Input::get('device_identifier');
     $timestamp = Input::get('timestamp');
     $courier = Input::get('courier');
     $status = Input::get('status');
     $stepping = Input::get('stepping');
     $device_name = $device_name == '' ? 'all' : $device_name;
     $timestamp = $timestamp == '' ? date('Y-m-d', time()) : $timestamp;
     $courier = $courier == '' ? 'all' : $courier;
     $status = $status == '' ? 'all' : $status;
     //$stepping = ($stepping == '')?10:$stepping;
     $statuses = Config::get('jex.mapdefstatus');
     $model = new Geolog();
     if ($device_name == 'all') {
         $devices = Geolog::distinct('deviceId')->get();
     } else {
         $devices = Geolog::distinct('deviceId')->where('deviceId', 'regexp', '/' . $device_name . '/i')->get('deviceId');
     }
     $locations = array();
     $paths = array();
     $pathdummy = array();
     foreach ($devices->toArray() as $d) {
         $deviceId = $d[0];
         $mapcolor = Prefs::get_device_color($deviceId);
         $timestamps = explode(' - ', $timestamp);
         if (count($timestamps) == 2) {
             $daystart = trim($timestamps[0]) . ' 00:00:00';
             $dayend = trim($timestamps[1]) . ' 23:59:59';
         } else {
             $daystart = $timestamp . ' 00:00:00';
             $dayend = $timestamp . ' 23:59:59';
         }
         $daystart = new MongoDate(strtotime($daystart));
         $dayend = new MongoDate(strtotime($dayend));
         $model = new Geolog();
         $model = $model->where('deviceId', '=', $deviceId)->whereBetween('mtimestamp', array($daystart, $dayend));
         if ($status != 'all') {
             $model = $model->where('status', 'regexp', '/' . $status . '/i');
         }
         /*
                     else{
                         $model = $model->whereIn('status',$statuses);
                     }*/
         $model = $model->where('appname', '=', Config::get('jex.tracker_app'));
         $locs = $model->orderBy('mtimestamp', 'desc')->get();
         //print_r($locs);
         if (count($locs->toArray()) > 0) {
             $path = array();
             $locv = array();
             $curr = null;
             $next = 1;
             $locarr = $locs->toArray();
             //print count($locarr)."|\r\n";
             //for($i = 0; $i < count($locs->toArray());$i++){
             while (!is_null($next)) {
                 if (is_null($curr)) {
                     $curr = array_shift($locarr);
                     $locv[] = (object) $curr;
                 }
                 $next = array_shift($locarr);
                 if (!is_null($next)) {
                     $st = true;
                     $key = strtotime($next['datetimestamp']);
                     if (isset($next['status']) && in_array($next['status'], $statuses)) {
                         $curr = $next;
                         $locv[$key] = (object) $next;
                         $st = false;
                     }
                     if ($st) {
                         $span = doubleval($next['timestamp']) - doubleval($curr['timestamp']);
                         if (abs($span) >= doubleval($stepping) * 60) {
                             $curr = $next;
                             $locv[$key] = (object) $next;
                         }
                     }
                 }
             }
             krsort($locv);
             //print count($locv)."||\r\n";
             foreach ($locv as $t => $l) {
                 //print_r($l);
                 $lat = isset($l->latitude) ? doubleval($l->latitude) : 0;
                 $lng = isset($l->longitude) ? doubleval($l->longitude) : 0;
                 $status = isset($l->status) && $l->status == '' ? $l->status : 'report';
                 if ($lat != 0 && $lng != 0) {
                     $locations[] = array('data' => array('id' => $l->_id, 'lat' => $lat, 'lng' => $lng, 'timestamp' => $l->datetimestamp, 'identifier' => $l->deviceId, 'delivery_id' => $l->deliveryId, 'status' => $status));
                     $path[] = array($lat, $lng);
                     $pathdummy[] = array($l->deviceId, $l->timestamp, $lat, $lng);
                 }
             }
             $paths[] = array('color' => $mapcolor, 'poly' => $path);
         }
     }
     print json_encode(array('result' => 'ok', 'locations' => $locations, 'paths' => $paths, 'pathdummy' => $pathdummy, 'q' => ''));
 }