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

99 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. $error[] = ['id'=>$withdrawalId,'msg'=>'已存在'];
  59. continue;
  60. }
  61. $newData =[
  62. 'id'=>$withdrawalId,
  63. 'store_id'=>$value->store_id ?? 0,
  64. 'name'=> (empty($value->name) || $value->name == 'undefined') ? '': $value->name,
  65. 'tel'=>$value->tel ?? 0,
  66. 'type'=> isset($typeData[$value->type])?$typeData[$value->type]:0,
  67. 'check_time'=>strtotime($value->sh_time),
  68. 'state'=>$value->state ?? 0,
  69. 'apply_cash'=>$value->tx_cost ?? 0,
  70. 'real_cash'=>$value->sj_cost ?? 0,
  71. 'bank_card'=>$value->yhk_num ?? 0,
  72. 'bank_info'=>$value->yh_info ?? 0,
  73. 'created_at' => $value->time ? strtotime($value->time) :0,
  74. 'updated_at' => $value->sh_time ? strtotime($value->sh_time) :0,
  75. ];
  76. $res = DB::table($newTableName)->insert($newData);
  77. if(!$res){
  78. $error[] = ['id'=>$withdrawalId];
  79. break;
  80. }
  81. $bar->advance();
  82. }
  83. $bar->finish();
  84. var_dump([time()-$startTime]);
  85. var_dump($error);
  86. return 0;
  87. }
  88. }