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

89 lines
2.4 KiB

  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Support\Facades\Schema;
  6. class MigrateCouponReceive extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'migrateData:couponReceive';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'migrate 迁移优惠券领取记录数据';
  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 int
  33. */
  34. public function handle()
  35. {
  36. $oldTableName = 'ims_system_coupon_user_receive';
  37. $newTableName = 'lanzu_coupon_receive_copy';
  38. // 判断表是否存在
  39. if(!Schema::hasTable($oldTableName)){
  40. var_dump('旧表不存在');
  41. return 0;
  42. }
  43. if(!Schema::hasTable($newTableName)){
  44. var_dump('新表不存在');
  45. return 0;
  46. }
  47. $oldData = DB::table($oldTableName)->get();
  48. $bar = $this->output->createProgressBar(count($oldData));
  49. $bar->start();
  50. $newData = [];
  51. foreach ($oldData as $key => $value) {
  52. $newData[] = [
  53. 'id' => $value->id,
  54. 'coupon_id' => $value->system_coupon_user_id ?? 0,
  55. 'user_id' => $value->user_id ?? 0,
  56. 'order_main_id' => $value->order_main_id ?? 0,
  57. 'receive_time' => $value->receive_time ?? 0,
  58. 'number' => $value->number ?? 0,
  59. 'number_remain' => $value->number_remain ?? 0,
  60. 'status' => $value->status ?? 0,
  61. 'update_time' => $value->update_time ?? 0,
  62. 'receive_type' => $value->receive_type ?? 0,
  63. 'rebate_type' => $value->rebate_type ?? 0,
  64. 'send_user_id' => $value->send_user_id ?? 0,
  65. 'phone' => $value->phone ?? '',
  66. 'created_at' => $value->created_at ?? 0,
  67. 'updated_at' => time(),
  68. ];
  69. $bar->advance();
  70. }
  71. // insert new data to new table
  72. DB::table($newTableName)->insert($newData);
  73. $bar->finish();
  74. return 0;
  75. }
  76. }