SettingFuSheParkingCommand.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Area;
  4. use App\Models\Parking;
  5. use Illuminate\Console\Command;
  6. class SettingFuSheParkingCommand extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'setting:fushe_parking';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '设置还车点辐射范围';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. //
  37. $type = $this->choice('请选择您要根据什么设置?', ['area_id' => '运营区域id', 'parking_id' => '停车点id'], 'parking_id');
  38. if ($type == 'area_id') {
  39. $area_id = $this->ask('请输入区域id');
  40. $area = Area::query()->find($area_id);
  41. if (empty($area)) {
  42. $this->error('找不到该区域,请检查参数');
  43. return;
  44. }
  45. $parkings = Parking::query()->where('area_id', $area_id)->get();
  46. if (count($parkings) !== 0) {
  47. $fushe = $this->ask('请输入辐射增加半径(米)');
  48. foreach ($parkings as $v) {
  49. $this->updateFuSheParking($v, $fushe);
  50. }
  51. } else {
  52. $this->error('该区域找不到该停车区域,请检查参数');
  53. }
  54. } elseif ($type == 'parking_id') {
  55. $parking_id = $this->ask('请输入停车点id');
  56. $parking = Parking::query()->find($parking_id);
  57. if (!empty($parking)) {
  58. $fushe = $this->ask('请输入辐射增加半径(米)');
  59. $this->updateFuSheParking($parking, $fushe);
  60. } else {
  61. $this->error('找不到该停车区域,请检查参数');
  62. }
  63. } else {
  64. $this->error('输入错误');
  65. }
  66. }
  67. public function updateFuSheParking($parking, $fushe)
  68. {
  69. $parking_centre = json_decode($parking->parking_centre);
  70. $parking_fence = json_decode($parking->parking_fence);
  71. foreach ($parking_fence as $v) {
  72. $distanceArr[] = GetDistance($parking_centre[1], $parking_centre[0], $v[1], $v[0]);
  73. }
  74. $this->info(max($distanceArr));
  75. $this->info($fushe);
  76. $parking->parking_radius = bcadd(max($distanceArr), $fushe, 4);
  77. $parking->save();
  78. $this->info('已更新停车区域名称:' . $parking->name);
  79. }
  80. }