LocationLogRepository.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Mead
  5. * Date: 2019/8/6
  6. * Time: 9:16 PM
  7. */
  8. namespace App\Repositories;
  9. use App\Models\LocationLogMongodb;
  10. class LocationLogRepository extends BaseRepository
  11. {
  12. public function __construct(LocationLogMongodb $model)
  13. {
  14. $this->model = $model;
  15. }
  16. /**
  17. * 获取车的最后定位
  18. * @param $id
  19. * @return mixed
  20. * User: Mead
  21. */
  22. public function byBikeNoGetLastLocation($bike_no)
  23. {
  24. $location = $this->model->where('bike_no', $bike_no)->select(['latitude', 'longitude', 'mileage', 'speed', 'is_yundong'])->orderByDesc('box_time')->first();
  25. return [
  26. 'lat' => $location['latitude'],
  27. 'lng' => $location['longitude'],
  28. 'mileage' => $location['mileage'],
  29. 'is_yundong' => $location['is_yundong'],
  30. 'speed' => $location['speed']
  31. ];
  32. }
  33. /**
  34. * 根据订单显示获取最后位置
  35. * @param $id
  36. * @return array
  37. * User: Mead
  38. */
  39. public function byOrderIdGetLastLocation($id)
  40. {
  41. $location = $this->model->where('order_id', $id)->select(['latitude', 'longitude', 'mileage', 'speed', 'is_yundong'])->orderByDesc('box_time')->first();
  42. return [
  43. 'lat' => $location['latitude'],
  44. 'lng' => $location['longitude'],
  45. 'mileage' => $location['mileage'],
  46. 'is_yundong' => $location['is_yundong'],
  47. 'speed' => $location['speed']
  48. ];
  49. }
  50. }