12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Mead
- * Date: 2019/8/6
- * Time: 9:16 PM
- */
- namespace App\Repositories;
- use App\Maps\CacheMap;
- use App\Models\LocationLogMongodb;
- use App\Models\Parking;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\Cache;
- 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 = 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']
- ];
- }
- }
|