ImprotDatabase.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Import;
  4. use Illuminate\Console\Command;
  5. class ImprotDatabase extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'database:import {id}';
  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. $info = Import::where('id', $this->argument('id'))->first();
  36. $category = collect(Import::$CATEGORY)->where('id', $info->category)->first();
  37. $fun = $category['function'] ?? 'import';
  38. $re = (new $category['model'])->{$fun}(unserialize($info['data']), $category);
  39. if ($re) {
  40. $info->is_import = 'T';
  41. $info->import_time = date('Y-m-d H:i:s');
  42. $info->save();
  43. }
  44. }
  45. }