BikeHandler.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Mead
  5. * Date: 2019/9/10
  6. * Time: 4:08 PM
  7. */
  8. namespace App\Handlers;
  9. use App\Models\AreaSetting;
  10. use App\Models\Parking;
  11. use Carbon\Carbon;
  12. use Illuminate\Support\Facades\Cache;
  13. use Illuminate\Support\Facades\Log;
  14. use Illuminate\Support\Facades\Redis;
  15. class BikeHandler
  16. {
  17. public function byLocationCheckIsInBanStopParking($lat, $lng, $area_id = 0)
  18. {
  19. $options = ['SORT' => 'ASC', 'COUNT' => 1, 'WITHDIST' => true];
  20. $redis = Redis::connection();
  21. $ban_stop_bike_stations = $redis->georadius(Parking::REDIS_BAN_STOP_BIKE_SITE_TAG . "_{$area_id}", $lng, $lat, 17000, 'm', $options);
  22. if (count($ban_stop_bike_stations) !== 1) {
  23. //没有找到禁停区
  24. return false;
  25. }
  26. $stop_bike_station = $ban_stop_bike_stations[0];
  27. $park_id = $stop_bike_station[0];
  28. $stop_bike_station_db = Cache::remember(Parking::REDIS_BAN_STOP_BIKE_SITE_TAG . $park_id, Carbon::now()->addHours(1), function () use ($park_id) {
  29. return Parking::where('id', $park_id)->first();
  30. });
  31. $ConverHandler = new ConvertHandler();
  32. $is_in_station = $ConverHandler->is_point_in_polygon([
  33. 'latitude' => $lat,
  34. 'longitude' => $lng
  35. ], $stop_bike_station_db->parking_fence);
  36. if ($is_in_station) {
  37. return true;
  38. }
  39. //判断是否在辐射范围
  40. // $is_in_near_station = $ConverHandler->is_point_in_circle([
  41. // 'latitude' => $lat,
  42. // 'longitude' => $lng
  43. // ], ['center' => $stop_bike_station_db->parking_centre, 'radius' => $stop_bike_station_db->parking_radius]);
  44. //
  45. // if ($is_in_near_station) {
  46. // return true;
  47. // }
  48. return false;
  49. }
  50. /**
  51. * 判断是否在停车点
  52. * @param $lat
  53. * @param $lng
  54. * @param int $area_id
  55. * @return array
  56. * User: Mead
  57. */
  58. public function byLocationCheckIsInStopParking($lat, $lng, $area_id = 0)
  59. {
  60. // 判断是否有还车点
  61. $options = ['SORT' => 'ASC', 'COUNT' => 1, 'WITHDIST' => true];
  62. $redis = Redis::connection();
  63. $stop_bike_stations = $redis->georadius(Parking::REDIS_STOP_BIKE_SITES_TAG . "_{$area_id}", $lng, $lat, 17000, 'm', $options);
  64. if (count($stop_bike_stations) !== 1) {
  65. //没有找到停车点
  66. return [
  67. 'status' => false,
  68. 'distance' => 999999
  69. ];
  70. }
  71. $stop_bike_station = $stop_bike_stations[0];
  72. $distance = $stop_bike_station[1];
  73. $park_id = $stop_bike_station[0];
  74. $stop_bike_station_db = Cache::remember("PARKING_" . $park_id, Carbon::now()->addHours(1), function () use ($park_id) {
  75. return Parking::where('id', $park_id)->first();
  76. });
  77. // 判断是否在还车点内
  78. $ConverHandler = new ConvertHandler();
  79. $is_in_station = $ConverHandler->is_point_in_polygon([
  80. 'latitude' => $lat,
  81. 'longitude' => $lng
  82. ], $stop_bike_station_db->parking_fence);
  83. if ($is_in_station) {
  84. return [
  85. 'status' => true,
  86. 'distance' => $distance
  87. ];
  88. }
  89. $areaSetting = AreaSetting::where('area_id', $area_id)->first();
  90. $is_parking_fushe = $areaSetting->is_parking_fushe;
  91. if ($is_parking_fushe == AreaSetting::PARKING_FUSHE_YES) {
  92. // 判断是否在还车点范围内
  93. $is_in_near_station = $ConverHandler->is_point_in_circle([
  94. 'latitude' => $lat,
  95. 'longitude' => $lng
  96. ], ['center' => $stop_bike_station_db->parking_centre, 'radius' => $stop_bike_station_db->parking_radius]);
  97. if ($is_in_near_station) {
  98. return [
  99. 'status' => true,
  100. 'type' => 'circle',
  101. 'distance' => $distance
  102. ];
  103. }
  104. }
  105. return [
  106. 'status' => false,
  107. 'distance' => $distance
  108. ];
  109. }
  110. /**
  111. * 通过距离获取调度费
  112. * @param $distance
  113. * User: Mead
  114. */
  115. public function byDistanceGetDistanceMoney($distance, $areaSetting)
  116. {
  117. if ($distance <= 3000) {
  118. // $over_money = bcmul(ceil($distance / 500), 5, 2);
  119. // if ($over_money < $areaSetting->min_dispatching_fee) {
  120. // return $over_money;
  121. // }
  122. return $areaSetting->min_dispatching_fee;
  123. }
  124. $over_distance = $distance - 3000;
  125. $over_money = bcadd($areaSetting->min_dispatching_fee, ceil($over_distance / 1000) * 5, 2);
  126. if ($over_money < $areaSetting->max_dispatching_fee) {
  127. return $over_money;
  128. }
  129. return $areaSetting->max_dispatching_fee;
  130. }
  131. }