InspectionBanner

This commit is contained in:
2024-12-02 14:48:56 +08:00
parent 410a838e8b
commit 6fcd8f7ce2
8 changed files with 328 additions and 14 deletions

View File

@ -0,0 +1,10 @@
<?php
namespace plugin\inspection\model;
use think\admin\Model;
class InspectionBanner extends Model
{
}

View File

@ -2,6 +2,7 @@
namespace plugin\inspection\model;
use Cassandra\Date;
use plugin\ticket\model\TicketTicket;
use think\admin\Model;
@ -17,14 +18,40 @@ class InspectionRecord extends Model
return $this->hasMany(InspectionRecordPoint::class, 'record_id', 'id')->order('create_at', 'asc');
}
public function autoFix()
{
$this->distance = $this->calculateDistance();
$this->duration = $this->calculateTime();
}
public function calculateTime()
{
$points = $this->points()->select();
$startTime = null;
$endTime = null;
foreach ($points as $point) {
if ($point->is_pause) continue;
if ($startTime === null) {
$startTime = $point->create_at;
}
$endTime = $point->create_at;
}
if ($startTime && $endTime) {
$start = new \DateTime($startTime);
$end = new \DateTime($endTime);
return $end->diff($start)->format('%H:%I:%S');
}
return '0:00:00';
}
public function calculateDistance()
{
$points = $this->points()->select();
$distance = 0;
$previousPoint = null;
foreach ($points as $point) {
$lat = $point->latitude;
$lng = $point->longitude;
$lat = $point->lat;
$lng = $point->lng;
if ($previousPoint) {
$distance += $this->calculateDistanceBetweenPoints($previousPoint[0], $previousPoint[1], $lat, $lng);
}
@ -38,10 +65,10 @@ class InspectionRecord extends Model
$earthRadius = 6371000; // 地球半径,单位为米
$dLat = deg2rad($lat - $lat1);
$dLng = deg2rad($lng - $lng1);
$a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($lat1)) * cos(deg2rad($lat)) * sin($dLng / 2) * sin($dLng / 2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
$distance = $earthRadius * $c;
return $distance;
$lat1 = deg2rad($lat1);
$lat = deg2rad($lat);
$d = $earthRadius * 2 * asin(sqrt(pow(sin($dLat / 2), 2) + cos($lat1) * cos($lat) * pow(sin($dLng / 2), 2)));
return $d;
}
public function ticket()