12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace App\Models;
- use Illuminate\Support\Facades\Log;
- class LocationLogMongodb extends \Jenssegers\Mongodb\Eloquent\Model
- {
- protected $connection = 'mongodb';
- protected $primaryKey = 'id'; //设置主键
- protected $table = 'location_logs';
- protected $guarded = [];
- const STATUS_OK = 1;
- const STATUS_PAUSE = 0;
- public static $statusMaps = [
- self::STATUS_OK => '正常',
- self::STATUS_PAUSE => '暂停'
- ];
- const RENT_YES = 1;
- const RENT_NO = 0;
- public static $rentMaps = [
- self::RENT_NO => '非日租订单',
- self::RENT_YES => '日租订单',
- ];
- /**
- * 获取车辆最新定位
- *
- * @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 = ['longitude' => 0, 'latitude' => 0,'battery_power' => 0];
- // Log::info($newestLocation);
- if (empty($newestLocation)) {
- return $newestLngLat;
- } else {
- $newestLngLat['longitude'] = $newestLocation->longitude;
- $newestLngLat['latitude'] = $newestLocation->latitude;
- $newestLngLat['battery_power'] = $newestLocation->battery_power;
- return $newestLngLat;
- }
- }
- }
|