|
@@ -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;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|