1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Mead
- * Date: 2019/8/6
- * Time: 9:16 PM
- */
- namespace App\Repositories;
- use App\Handlers\BikeStatusInfoSyncHandler;
- use App\Maps\CacheMap;
- use App\Models\LocationLogMongodb;
- use App\Models\Parking;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\Log;
- class LocationLogRepository extends BaseRepository
- {
- public function __construct(LocationLogMongodb $model)
- {
- $this->model = $model;
- }
- /**
- * 获取车的最后定位
- * @param $id
- * @return mixed
- * User: Mead
- */
- public function byBikeNoGetLastLocation($bike_no, $is_open = false)
- {
- if ($is_open === true) {
- return [
- 'lat' => 0,
- 'lng' => 0,
- 'mileage' => 0,
- 'is_yundong' => 0,
- 'speed' => 0
- ];
- }
- $location = (new BikeStatusInfoSyncHandler())->byBikeNoGetLocation($bike_no);
- if ($location['time']) {
- $location['speed'] = 0;
- return $location;
- }
- $location = Cache::remember(CacheMap::BIKE_LOCATION_MONGODB . $bike_no, Carbon::now()->addSeconds(3), function () use ($bike_no) {
- return $this->model->where('day', date('Ymd'))->where('bike_no', $bike_no)->select(['latitude', 'longitude', 'mileage', 'speed', 'is_yundong'])->orderByDesc('_id')->first();
- });
- // $location = Cache::remember(CacheMap::BIKE_LOCATION_MONGODB . $bike_no, Carbon::now()->addSeconds(10), function () use ($bike_no) {
- // return $this->model->where('bike_no', $bike_no)->select(['latitude', 'longitude', 'mileage', 'speed', 'is_yundong'])->orderByDesc('box_time')->first();
- // });
- return [
- 'lat' => $location['latitude'],
- 'lng' => $location['longitude'],
- 'mileage' => $location['mileage'],
- 'is_yundong' => $location['is_yundong'],
- 'speed' => $location['speed']
- ];
- }
- /**
- * 根据订单显示获取最后位置
- * @param $id
- * @return array
- * User: Mead
- */
- public function byOrderIdGetLastLocation($id, $is_open = false)
- {
- if ($is_open === true) {
- return [
- 'lat' => 0,
- 'lng' => 0,
- 'mileage' => 0,
- 'is_yundong' => 0,
- 'speed' => 0
- ];
- }
- $location = Cache::remember(CacheMap::BIKE_LOCATION_MONGODB . $id, Carbon::now()->addSeconds(10), function () use ($id) {
- return $this->model->where('order_id', $id)->select(['latitude', 'longitude', 'mileage', 'speed', 'is_yundong'])->orderByDesc('box_time')->first();
- });
- return [
- 'lat' => $location['latitude'],
- 'lng' => $location['longitude'],
- 'mileage' => $location['mileage'],
- 'is_yundong' => $location['is_yundong'],
- 'speed' => $location['speed']
- ];
- }
- }
|