12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace App\Console\Commands;
- use App\Models\Area;
- use App\Models\Parking;
- use Illuminate\Console\Command;
- class SettingFuSheParkingCommand extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'setting:fushe_parking';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '设置还车点辐射范围';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- //
- $type = $this->choice('请选择您要根据什么设置?', ['area_id' => '运营区域id', 'parking_id' => '停车点id'], 'parking_id');
- if ($type == 'area_id') {
- $area_id = $this->ask('请输入区域id');
- $area = Area::query()->find($area_id);
- if (empty($area)) {
- $this->error('找不到该区域,请检查参数');
- return;
- }
- $parkings = Parking::query()->where('area_id', $area_id)->get();
- if (count($parkings) !== 0) {
- $fushe = $this->ask('请输入辐射增加半径(米)');
- foreach ($parkings as $v) {
- $this->updateFuSheParking($v, $fushe);
- }
- } else {
- $this->error('该区域找不到该停车区域,请检查参数');
- }
- } elseif ($type == 'parking_id') {
- $parking_id = $this->ask('请输入停车点id');
- $parking = Parking::query()->find($parking_id);
- if (!empty($parking)) {
- $fushe = $this->ask('请输入辐射增加半径(米)');
- $this->updateFuSheParking($parking, $fushe);
- } else {
- $this->error('找不到该停车区域,请检查参数');
- }
- } else {
- $this->error('输入错误');
- }
- }
- public function updateFuSheParking($parking, $fushe)
- {
- $parking_centre = json_decode($parking->parking_centre);
- $parking_fence = json_decode($parking->parking_fence);
- foreach ($parking_fence as $v) {
- $distanceArr[] = GetDistance($parking_centre[1], $parking_centre[0], $v[1], $v[0]);
- }
- $this->info(max($distanceArr));
- $this->info($fushe);
- $parking->parking_radius = bcadd(max($distanceArr), $fushe, 4);
- $parking->save();
- $this->info('已更新停车区域名称:' . $parking->name);
- }
- }
|