123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Mead
- * Date: 2019/9/10
- * Time: 4:08 PM
- */
- namespace App\Handlers;
- use App\Models\AreaSetting;
- use App\Models\Parking;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Redis;
- class BikeHandler
- {
- public function byLocationCheckIsInBanStopParking($lat, $lng, $area_id = 0)
- {
- $options = ['SORT' => 'ASC', 'COUNT' => 1, 'WITHDIST' => true];
- $redis = Redis::connection();
- $ban_stop_bike_stations = $redis->georadius(Parking::REDIS_BAN_STOP_BIKE_SITE_TAG . "_{$area_id}", $lng, $lat, 17000, 'm', $options);
- if (count($ban_stop_bike_stations) !== 1) {
- //没有找到禁停区
- return false;
- }
- $stop_bike_station = $ban_stop_bike_stations[0];
- $park_id = $stop_bike_station[0];
- $stop_bike_station_db = Cache::remember(Parking::REDIS_BAN_STOP_BIKE_SITE_TAG . $park_id, Carbon::now()->addHours(1), function () use ($park_id) {
- return Parking::where('id', $park_id)->first();
- });
- $ConverHandler = new ConvertHandler();
- $is_in_station = $ConverHandler->is_point_in_polygon([
- 'latitude' => $lat,
- 'longitude' => $lng
- ], $stop_bike_station_db->parking_fence);
- if ($is_in_station) {
- return true;
- }
- //判断是否在辐射范围
- // $is_in_near_station = $ConverHandler->is_point_in_circle([
- // 'latitude' => $lat,
- // 'longitude' => $lng
- // ], ['center' => $stop_bike_station_db->parking_centre, 'radius' => $stop_bike_station_db->parking_radius]);
- //
- // if ($is_in_near_station) {
- // return true;
- // }
- return false;
- }
- /**
- * 判断是否在停车点
- * @param $lat
- * @param $lng
- * @param int $area_id
- * @return array
- * User: Mead
- */
- public function byLocationCheckIsInStopParking($lat, $lng, $area_id = 0)
- {
- // 判断是否有还车点
- $options = ['SORT' => 'ASC', 'COUNT' => 1, 'WITHDIST' => true];
- $redis = Redis::connection();
- $stop_bike_stations = $redis->georadius(Parking::REDIS_STOP_BIKE_SITES_TAG . "_{$area_id}", $lng, $lat, 17000, 'm', $options);
- if (count($stop_bike_stations) !== 1) {
- //没有找到停车点
- return [
- 'status' => false,
- 'distance' => 999999
- ];
- }
- $stop_bike_station = $stop_bike_stations[0];
- $distance = $stop_bike_station[1];
- $park_id = $stop_bike_station[0];
- $stop_bike_station_db = Cache::remember("PARKING_" . $park_id, Carbon::now()->addHours(1), function () use ($park_id) {
- return Parking::where('id', $park_id)->first();
- });
- // 判断是否在还车点内
- $ConverHandler = new ConvertHandler();
- $is_in_station = $ConverHandler->is_point_in_polygon([
- 'latitude' => $lat,
- 'longitude' => $lng
- ], $stop_bike_station_db->parking_fence);
- if ($is_in_station) {
- return [
- 'status' => true,
- 'distance' => $distance
- ];
- }
- $areaSetting = AreaSetting::where('area_id', $area_id)->first();
- $is_parking_fushe = $areaSetting->is_parking_fushe;
- if ($is_parking_fushe == AreaSetting::PARKING_FUSHE_YES) {
- // 判断是否在还车点范围内
- $is_in_near_station = $ConverHandler->is_point_in_circle([
- 'latitude' => $lat,
- 'longitude' => $lng
- ], ['center' => $stop_bike_station_db->parking_centre, 'radius' => $stop_bike_station_db->parking_radius]);
- if ($is_in_near_station) {
- return [
- 'status' => true,
- 'type' => 'circle',
- 'distance' => $distance
- ];
- }
- }
- return [
- 'status' => false,
- 'distance' => $distance
- ];
- }
- /**
- * 通过距离获取调度费
- * @param $distance
- * User: Mead
- */
- public function byDistanceGetDistanceMoney($distance, $areaSetting)
- {
- if ($distance <= 3000) {
- // $over_money = bcmul(ceil($distance / 500), 5, 2);
- // if ($over_money < $areaSetting->min_dispatching_fee) {
- // return $over_money;
- // }
- return $areaSetting->min_dispatching_fee;
- }
- $over_distance = $distance - 3000;
- $over_money = bcadd($areaSetting->min_dispatching_fee, ceil($over_distance / 1000) * 5, 2);
- if ($over_money < $areaSetting->max_dispatching_fee) {
- return $over_money;
- }
- return $areaSetting->max_dispatching_fee;
- }
- }
|