链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.6 KiB

  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. class MigrateUserAddr extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'migrateData:userAddr';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'migrate user addr data';
  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 int
  32. */
  33. public function handle()
  34. {
  35. // get old data from old table
  36. $oldData = DB::table('ims_cjdc_useradd')->get();
  37. $bar = $this->output->createProgressBar(count($oldData));
  38. $bar->start();
  39. $newData = [];
  40. foreach ($oldData as $key => $value) {
  41. $newData[] = [
  42. 'user_id' => $value->user_id ?? '',
  43. 'user_name' => $value->user_name ?? '',
  44. 'address' => $value->address ?? '',
  45. 'gender' => $value->sex ?? 0,
  46. 'lat' => $value->lat ?? '',
  47. 'lng' => $value->lng ?? '',
  48. 'tel' => $value->tel ?? '',
  49. 'tags' => json_encode([]),
  50. 'created_at' => time(),
  51. 'updated_at' => time(),
  52. ];
  53. $bar->advance();
  54. }
  55. // insert new data to new table
  56. DB::table('lanzu_user_address')->insert($newData);
  57. $bar->finish();
  58. return 0;
  59. }
  60. }