ImportData.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Handlers\LoadExcelHandler;
  4. use App\Trace;
  5. use Illuminate\Console\Command;
  6. class ImportData extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'import:data';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Command 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. $data = (new LoadExcelHandler)->load(public_path('uploads') . '/禾美988-6w.xls');
  37. unset($data[0]);
  38. $insert = [];
  39. foreach ($data as $item) {
  40. $key = str_replace('http://code.hnhemeile.cn/key/', '', $item[3]);
  41. if ($key) {
  42. $insert[] = [
  43. 'key' => $item[0],
  44. 'group' => (int)$item[2],
  45. 'slug' => $key,
  46. 'gid' => 4,
  47. 'status' => 1,
  48. 'product_id' => 0,
  49. 'dealer_id' => 0
  50. ];
  51. }
  52. if (count($insert) >= 2000) {
  53. Trace::query()->insert($insert);
  54. $insert = [];
  55. }
  56. }
  57. $this->line("ok");
  58. }
  59. }