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

80 lines
1.8 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 MigrateStoreBalance extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'migrateData:storeBalance';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Command 迁移商户余额数据到lanzu_user_balance表';
  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. $oldOrderTableName = 'ims_cjdc_order';
  37. $oldWithdrawalTableName = 'ims_cjdc_withdrawal';
  38. $oldAccountTableName = 'ims_cjdc_store_account';
  39. $newTableName = 'lanzu_user_balance';
  40. // 判断表是否存在
  41. if(!Schema::hasTable($oldAccountTableName)){
  42. var_dump('旧表不存在');
  43. return 0;
  44. }
  45. if(!Schema::hasTable($newTableName)){
  46. var_dump('新表不存在');
  47. return 0;
  48. }
  49. $oldData = DB::table($oldAccountTableName)->orderBy('id','asc')->get();
  50. $bar = $this->output->createProgressBar(count($oldData));
  51. $bar->start();
  52. $startTime = time();
  53. $error = [];
  54. $newData = [];
  55. foreach ($oldData as $key => $value){
  56. $storeId = $value->store_id;
  57. $bar->advance();
  58. }
  59. DB::table($newTableName)->insert($newData);
  60. $bar->finish();
  61. var_dump([time()-$startTime]);
  62. var_dump($error);
  63. return 0;
  64. }
  65. }