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

98 lines
2.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 MigrateStoreWithdrawal extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'migrateData:storeWithdrawal';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Command 迁移店铺提现记录数据';
  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_cjdc_withdrawal';
  37. $newTableName = 'lanzu_store_withdrawal';
  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. $typeData = [2 => 1,3 => 3, 1 => 4];
  48. $oldData = DB::table($oldTableName)->orderBy('id','asc')->get();
  49. $bar = $this->output->createProgressBar(count($oldData));
  50. $bar->start();
  51. $startTime = time();
  52. $error = [];
  53. foreach ($oldData as $key => $value){
  54. $withdrawalId = $value->id ?? 0;
  55. // 判断是否存在
  56. $exist = DB::table($newTableName)->where('id',$withdrawalId)->exists();
  57. if($exist){
  58. continue;
  59. }
  60. $newData =[
  61. 'id'=>$withdrawalId,
  62. 'store_id'=>$value->store_id ?? 0,
  63. 'name'=> (empty($value->name) || $value->name == 'undefined') ? '': $value->name,
  64. 'tel'=>$value->tel ?? 0,
  65. 'type'=> isset($typeData[$value->type])?$typeData[$value->type]:0,
  66. 'check_time'=>strtotime($value->sh_time),
  67. 'state'=>$value->state ?? 0,
  68. 'apply_cash'=>$value->tx_cost ?? 0,
  69. 'real_cash'=>$value->sj_cost ?? 0,
  70. 'bank_card'=>$value->yhk_num ?? 0,
  71. 'bank_info'=>$value->yh_info ?? 0,
  72. 'created_at' => $value->time ? strtotime($value->time) :0,
  73. 'updated_at' => $value->sh_time ? strtotime($value->sh_time) :0,
  74. ];
  75. $res = DB::table($newTableName)->insert($newData);
  76. if(!$res){
  77. $error[] = ['id'=>$withdrawalId];
  78. break;
  79. }
  80. $bar->advance();
  81. }
  82. $bar->finish();
  83. var_dump([time()-$startTime]);
  84. var_dump($error);
  85. return 0;
  86. }
  87. }