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

75 lines
1.8 KiB

  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. class MigrateOrder extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'migrateData:order';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'migrate order 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_order')->get();
  37. $bar = $this->output->createProgressBar(count($oldData));
  38. $bar->start();
  39. $newData = [];
  40. foreach ($oldData as $key => $value) {
  41. $newData[] = [
  42. 'order_main_id' => $value->order_main_id ?? 0,
  43. 'user_id' => $value->user_id ?? 0,
  44. 'store_id' => $value->store_id ?? 0,
  45. 'status' => 1,
  46. 'refund_time' => 0,
  47. 'order_num' => $value->order_num ?? '',
  48. 'money' => $value->money ?? 0,
  49. 'oid' => $value->oid ?? 0,
  50. 'refuse_refund_note' => '',
  51. 'refund_note' => '',
  52. 'note' => $value->note ?? '',
  53. 'created_at' => $value->time_add ? strtotime($value->time_add) : 0,
  54. 'updated_at' => $value->time_add ? strtotime($value->time_add) : 0,
  55. ];
  56. $bar->advance();
  57. }
  58. // insert new data to new table
  59. DB::table('lanzu_order')->insert($newData);
  60. $bar->finish();
  61. return 0;
  62. }
  63. }