LocationLogMongodb.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Support\Facades\Log;
  4. class LocationLogMongodb extends \Jenssegers\Mongodb\Eloquent\Model
  5. {
  6. protected $connection = 'mongodb';
  7. protected $primaryKey = 'id'; //设置主键
  8. protected $table = 'location_logs';
  9. protected $guarded = [];
  10. const STATUS_OK = 1;
  11. const STATUS_PAUSE = 0;
  12. public static $statusMaps = [
  13. self::STATUS_OK => '正常',
  14. self::STATUS_PAUSE => '暂停'
  15. ];
  16. const RENT_YES = 1;
  17. const RENT_NO = 0;
  18. public static $rentMaps = [
  19. self::RENT_NO => '非日租订单',
  20. self::RENT_YES => '日租订单',
  21. ];
  22. /**
  23. * 获取车辆最新定位
  24. *
  25. * @param $bike_no string 车辆编号
  26. *
  27. * @return $newestLngLat array 车辆最新定位
  28. * */
  29. public static function getNewestLocationByBikeNo($bike_no)
  30. {
  31. $newestLocation = self::query()->where('bike_no', (string)$bike_no)->whereBetween('latitude', [3, 53])->whereBetween('longitude', [73, 136])->orderByDesc('created_at')->first();
  32. $newestLngLat = ['longitude' => 0, 'latitude' => 0,'battery_power' => 0];
  33. // Log::info($newestLocation);
  34. if (empty($newestLocation)) {
  35. return $newestLngLat;
  36. } else {
  37. $newestLngLat['longitude'] = $newestLocation->longitude;
  38. $newestLngLat['latitude'] = $newestLocation->latitude;
  39. $newestLngLat['battery_power'] = $newestLocation->battery_power;
  40. return $newestLngLat;
  41. }
  42. }
  43. }