12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- class BikeInitTestDatasCommand extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'init:bike';
- /**
- * 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()
- {
- $init_bike_num = 500;
- $start_bike_id = 4101000100001;
- $start_box_id = 80000000000000001;
- $bikes = [];
- $this->line('初始化开始');
- for ($i = 0; $i < $init_bike_num; $i++) {
- $bike = [
- 'bike_no' => bcadd($start_bike_id, $i),
- 'box_no' => bcadd($start_box_id, $i),
- 'battery_power' => 100,
- 'is_link' => 1,
- 'is_lock' => 1,
- 'is_low_battery_power' => 0,
- 'is_riding' => 0,
- 'is_trouble' => 0,
- 'last_location' => json_encode($this->randomLocation(), true),
- 'last_location_time' => date('Y-m-d H:i:s'),
- 'put_area_id' => 14,
- 'put_status' => 1,
- 'put_time' => date('Y-m-d H:i:s'),
- 'status' => 1,
- ];
- $bikes[] = $bike;
- if (count($bikes) >= 2200) {
- DB::table('bikes')->insert($bikes);
- $bikes = [];
- }
- }
- if (count($bikes) >= 1) {
- DB::table('bikes')->insert($bikes);
- $bikes = [];
- }
- $this->line('创建成功');
- }
- public function randomLocation()
- {
- $lng = '113.' . rand(787038, 836121);
- $lat = '34.' . rand(782682, 815406);
- return [
- 'lat' => $lat,
- 'lng' => $lng
- ];
- }
- }
|