table('t_data_dict')->where('dictKey', 'building')->get(); $newKeywords = []; $buildings = []; foreach($oldDicts as $dict){ if(empty($dict->dictKey) || empty($dict->valid)){ continue; } $_keyword = null; $_parent = Keyword::where('oid', $dict->parentId)->first(); if($_parent){ $_keyword = [ 'key' => $_parent->key.$dict->id, 'name' => $dict->txt, 'sort' => $dict->sorted, 'parent_id' => $_parent->id, 'parent_key'=> $_parent->key, 'lv' => $_parent->lv+1, 'path' => $_parent->path.$_parent->id.'-', 'oid' => $dict->id, 'created_at'=>now(), 'updated_at'=>now() ]; } if($_keyword){ $newKeywords[$dict->id] = $_keyword; } } if(count($newKeywords) > 0){ try { DB::begintransaction(); DB::table('keywords')->insert($newKeywords); DB::commit(); } catch (Throwable $th) { DB::rollBack(); report($th); } } } }