orderBy('id','asc')->get(); $oldStoreData = DB::table($oldStoreTableName)->pluck('market_id','id'); $bar = $this->output->createProgressBar(count($oldData)); $bar->start(); $startTime = time(); $error = '已存在:'; foreach ($oldData as $key => $value){ $collectionId = $value->id ?? 0; // 判断是否存在 $exist = DB::table($newTableName)->where('id',$collectionId)->exists(); if($exist){ $error .= ','.$collectionId; continue; } // 店铺存在 if(isset($oldStoreData[$value->store_id])){ $newData =[ 'id'=>$collectionId, 'store_id'=>$value->store_id ?? 0, 'user_id'=>$value->user_id ?? 0, 'market_id'=> isset($oldStoreData[$value->store_id])?$oldStoreData[$value->store_id]:0, 'created_at' => $value->time ?? time(), 'updated_at' => time(), ]; $res = DB::table($newTableName)->insert($newData); if(!$res){ $error[] = ['id'=>$collectionId]; break; } } $bar->advance(); } $bar->finish(); var_dump([time()-$startTime]); var_dump($error); return 0; } }