1,3 => 3, 1 => 4]; $oldData = DB::table($oldTableName)->orderBy('id','asc')->get(); $bar = $this->output->createProgressBar(count($oldData)); $bar->start(); $startTime = time(); $error = []; foreach ($oldData as $key => $value){ $withdrawalId = $value->id ?? 0; // 判断是否存在 $exist = DB::table($newTableName)->where('id',$withdrawalId)->exists(); if($exist){ continue; } $newData =[ 'id'=>$withdrawalId, 'store_id'=>$value->store_id ?? 0, 'name'=> (empty($value->name) || $value->name == 'undefined') ? '': $value->name, 'tel'=>$value->tel ?? 0, 'type'=> isset($typeData[$value->type])?$typeData[$value->type]:0, 'check_time'=>strtotime($value->sh_time), 'state'=>$value->state ?? 0, 'apply_cash'=>$value->tx_cost ?? 0, 'real_cash'=>$value->sj_cost ?? 0, 'bank_card'=>$value->yhk_num ?? 0, 'bank_info'=>$value->yh_info ?? 0, 'created_at' => $value->time ? strtotime($value->time) :0, 'updated_at' => $value->sh_time ? strtotime($value->sh_time) :0, ]; $res = DB::table($newTableName)->insert($newData); if(!$res){ $error[] = ['id'=>$withdrawalId]; break; } $bar->advance(); } $bar->finish(); var_dump([time()-$startTime]); var_dump($error); return 0; } }