链街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.

79 lines
2.0 KiB

  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. class MigrateMarketData extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'migrateData:market';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'migrate market 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_market')->get();
  37. $bar = $this->output->createProgressBar(count($oldData));
  38. $bar->start();
  39. $newData = [];
  40. foreach ($oldData as $key => $value) {
  41. $coordinates = explode(',', $value->coordinates);
  42. $newData[] = [
  43. 'mp_id' => $value->mp_id ?? 0,
  44. 'name' => $value->name ?? '',
  45. 'logo' => $value->logo ?? '',
  46. 'introduce' => $value->introduce ?? '',
  47. 'imgs' => $value->imgs ?? '',
  48. 'province_id' => 2162,
  49. 'city_id' => 2163,
  50. 'region_id' => 0,
  51. 'address' => $value->address ?? '',
  52. 'tel' => $value->tel ?? '',
  53. 'lat' => $coordinates[0] ?? '',
  54. 'lng' => $coordinates[1] ?? '',
  55. 'status' => $value->status ?? 1,
  56. 'sort' => $value->sort ?? 1,
  57. 'created_at' => $value->addtime ? strtotime($value->addtime) : 0,
  58. 'updated_at' => $value->addtime ? strtotime($value->addtime) : 0,
  59. ];
  60. $bar->advance();
  61. }
  62. // insert new data to new table
  63. DB::table('lanzu_market')->insert($newData);
  64. $bar->finish();
  65. return 0;
  66. }
  67. }