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'] ]; } }