123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace App\Models;
- use Carbon\Carbon;
- use Illuminate\Database\Eloquent\Model;
- class LocationsLog extends \Jenssegers\Mongodb\Eloquent\Model
- {
- protected $connection = 'mongodb';
- protected $primaryKey = 'id'; //设置主键
- protected $table = 'location_logs';
- protected $guarded = [];
- const RENT_YES = 1;
- const RENT_NO = 0;
- public static $rentMaps = [
- self::RENT_NO => '非日租订单',
- self::RENT_YES => '日租订单',
- ];
- const USER_LOCATION = 'user';
- const WORKER_LOCATION = 'worker';
- const NO_LOCATION = 'no';
- /**
- * 获取车辆最新定位
- *
- * @param $bike_no string 车辆编号
- *
- * @return $newestLngLat array 车辆最新定位
- * */
- public static function getNewestLocationByBikeNo($bike_no)
- {
- $newestLocation = self::query()->where('bike_no', (string)$bike_no)->whereBetween('latitude', [3, 53])->whereBetween('longitude', [73, 136])->orderByDesc('created_at')->first();
- $newestLngLat = ['lng' => 0, 'lat' => 0];
- if (empty($newestLocation)) {
- return $newestLngLat;
- } else {
- $newestLngLat['lng'] = $newestLocation->longitude;
- $newestLngLat['lat'] = $newestLocation->latitude;
- return $newestLngLat;
- }
- }
- /**
- * 获取车辆最新定位 以及时间
- *
- * @param $bike_no string 车辆编号
- *
- * @return $newestLngLat array 车辆最新定位 及时间
- * */
- public static function getNewestLocationTimeByBikeNo($bike_no)
- {
- $newestLocation = self::query()->where('bike_no', (string)$bike_no)->whereBetween('latitude', [3, 53])->whereBetween('longitude', [73, 136])->orderByDesc('created_at')->first();
- $newestLngLat = ['lng' => 0, 'lat' => 0];
- if (empty($newestLocation)) {
- return ['location' => $newestLngLat, 'time' => '获取失败'];
- } else {
- $newestLngLat['lng'] = $newestLocation->longitude;
- $newestLngLat['lat'] = $newestLocation->latitude;
- return ['location' => $newestLngLat, 'time' => Carbon::make($newestLocation->created_at)->format('Y/m/d H:i:s')];
- }
- }
- }
|