BikeInitTestDatasCommand.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. class BikeInitTestDatasCommand extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'init:bike';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = '初始化电动车数据';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return mixed
  32. */
  33. public function handle()
  34. {
  35. $init_bike_num = 500;
  36. $start_bike_id = 4101000100001;
  37. $start_box_id = 80000000000000001;
  38. $bikes = [];
  39. $this->line('初始化开始');
  40. for ($i = 0; $i < $init_bike_num; $i++) {
  41. $bike = [
  42. 'bike_no' => bcadd($start_bike_id, $i),
  43. 'box_no' => bcadd($start_box_id, $i),
  44. 'battery_power' => 100,
  45. 'is_link' => 1,
  46. 'is_lock' => 1,
  47. 'is_low_battery_power' => 0,
  48. 'is_riding' => 0,
  49. 'is_trouble' => 0,
  50. 'last_location' => json_encode($this->randomLocation(), true),
  51. 'last_location_time' => date('Y-m-d H:i:s'),
  52. 'put_area_id' => 14,
  53. 'put_status' => 1,
  54. 'put_time' => date('Y-m-d H:i:s'),
  55. 'status' => 1,
  56. ];
  57. $bikes[] = $bike;
  58. if (count($bikes) >= 2200) {
  59. DB::table('bikes')->insert($bikes);
  60. $bikes = [];
  61. }
  62. }
  63. if (count($bikes) >= 1) {
  64. DB::table('bikes')->insert($bikes);
  65. $bikes = [];
  66. }
  67. $this->line('创建成功');
  68. }
  69. public function randomLocation()
  70. {
  71. $lng = '113.' . rand(787038, 836121);
  72. $lat = '34.' . rand(782682, 815406);
  73. return [
  74. 'lat' => $lat,
  75. 'lng' => $lng
  76. ];
  77. }
  78. }