Ver código fonte

change the onlinetime

git 5 anos atrás
pai
commit
ca8706ede4
3 arquivos alterados com 72 adições e 12 exclusões
  1. 1 0
      Home/Conf/config.php
  2. 70 11
      Home/Lib/Action/ApiAction.class.php
  3. 1 1
      czapp

+ 1 - 0
Home/Conf/config.php

@@ -18,4 +18,5 @@ return array(
     'FENCE_ALARM_INTERVAL' 	=> 5, // 围栏告警时间间隔
     ######### 车主页 #########
     'DRIVING_STATISTICS_DAYS' => 5, //行驶数据统计默认5天
+    'IS_ONOFFLINE_INTERVAL_SECONDS' => 300,
 );

+ 70 - 11
Home/Lib/Action/ApiAction.class.php

@@ -21,6 +21,9 @@ class ApiAction extends Action {
 		if(!$userinfo){
 			$this->api_fail(C('FAIL'),'用户名或者密码不正确');
 		}
+		
+		$cityid = $userinfo['CityId'];
+		$defaultCity = M('jms_city')->where(array('ID' => $cityid))->field('CenterLng as lng, CenterLat as lat')->find();
 		$token = md5($data['username'].I('post.loginMark').$data['password'].date('Y-m-d H:i:s'));
 		$result = \Jiaruan\RedisCache::setSessionRules(I('post.loginMark'),$token);
 		if($result === false){
@@ -71,8 +74,12 @@ class ApiAction extends Action {
 			"plate" => $userinfo['LicensePlate'],
 			'deviceNumber' => $userinfo['DeviceNumber'],
 			'gpsNumber' => $userinfo['GpsDeviceNumber'],
-			'cityid' => $userinfo['CityId']
+			'cityid' => $userinfo['CityId'],
+			'defaultCity' => $defaultCity
 		);
+		
+		
+		
 		$data = array(
 			"baseinfo" => $baseinfo,
 			"post" => array(),
@@ -147,23 +154,48 @@ class ApiAction extends Action {
 		$fence = $rlfd_vehicle_fence->get($licensePlate);
 		//$fence = json_decode($fence, true);
 		
+		//末次位置和时间
 		$lastLocReis = Redis('rfld_gps_last_location','hash');
 		$lastLoction = $lastLocReis->get($gpsNumber);
 		//var_dump($lastLoction);
 		if($lastLoction){
 			$lastLoction = json_decode($lastLoction, true);
-			$alterVehLoction = \Jms\Algo\Geometry::convertBd09ToGcj02($lastLoction['GpsLatitude'], $lastLoction['GpsLongitude']);	
-		}
+			$alterVehLoction = \Jms\Algo\Geometry::convertBd09ToGcj02($lastLoction['GpsLatitude'], $lastLoction['GpsLongitude']);
+			$onlineTime = $lastLoction['GpsOnlineTime'];
 			
-		/*
-		if(!$result){
-			$this->api_fail(C('FAIL'),'cant find this vehicle !');
+		}else{
+			$onlineTime = false;
 		}
-		*/
-		$onlineTimeStamp = strtotime($lastLoction['GpsOnlineTime']);
-		if(!$onlineTimeStamp){
-			$onlineTimeStamp = 0;
+		$lastLoactionTime = $onlineTime;
+		//心跳时间
+		$gpsHeart = Redis('rfld_gps_last_location','hash');
+		$heartTime = $gpsHeart->get($gpsNumber);
+		if(!$heartTime){
+			$heartTime = false;
 		}
+		//心跳时间和末次GPS位置时间比较取最新
+		$onlineTime = (strtotime($onlineTime) > strtotime($heartTime) ? $onlineTime: $heartTime);
+		
+		if(!$onlineTime){
+			$onlineTimeInfo = false;
+		}else{
+			$interval = time() - strtotime($onlineTime);
+			if($interval > C('IS_ONOFFLINE_INTERVAL_SECONDS')){
+				$offlineDisplay = $this->getFormatTime($interval);
+				$onlineTimeInfo = array(
+					'online' => false,
+					'time' => $onlineTime,
+					'humenDisplay' => $offlineDisplay
+				);
+			}else{
+				$onlineTimeInfo = array(
+					'online' => true,
+					'time' => $onlineTime
+				);
+			}
+				
+		}
+		
 		
 		/*
 		if(!$result['GpsLongitude'] || !$result['GpsLatitude']){
@@ -181,7 +213,8 @@ class ApiAction extends Action {
 			'fenceShapeInfo' => $fence,
 			'battery' => $lastLoction['Battery'],
 		//	'fenceAlarmStatus' => $result['FenceAlarmEnable'],
-			'onlineTime' => $onlineTimeStamp,
+			'onlineTime' => $onlineTimeInfo,
+			'lastLoactionTime' => $lastLoactionTime,
 			'speed' => $result['Speed']
 		);
 		
@@ -759,6 +792,8 @@ class ApiAction extends Action {
 	
  
 	public  function test_function(  ){
+		//距离测试
+		/*
 		$lat1 = '31.253411';
 		$lng1 = '121.518998';
 		
@@ -767,6 +802,12 @@ class ApiAction extends Action {
 		
 		$distance = $this->get_2points_distance($lat1, $lng1, $lat2, $lng2);
 		var_dump($distance);
+		*/
+		
+		//离线时间测试
+		$interval = 343088;
+		$time = $this->getFormatTime($interval);
+		echo $time;
 	}
 	
  
@@ -809,5 +850,23 @@ class ApiAction extends Action {
 		
 	}
 	
+ 
+	private  function getFormatTime( $timeInterval ){
+		if ($timeInterval < 60){         
+			$formatime = $timeInterval.'秒';     
+		}elseif($timeInterval < 60 * 60){         
+			$min = floor($timeInterval/60);         
+			$formatime = $min.'分钟';     
+		}elseif($timeInterval < 60 * 60 * 24){         
+			$h = floor($timeInterval/(60*60));         
+			$formatime = $h.'小时';     
+		}else{         
+			$d = floor($timeInterval/(60*60*24));         
+			$formatime = $d.'天';
+		}
+		   
+		return $formatime; 
+	}
+	
 
 }

+ 1 - 1
czapp

@@ -1 +1 @@
-Subproject commit 56747b468d56f638a2dee0dd1399db7556287654
+Subproject commit 1bed89af5dccd732b29ad10bffd78db5ca6a8dd1