orderBy('id','asc')->get(); $oldStoreData = DB::table($oldStoreTableName)->pluck('market_id','id'); $bar = $this->output->createProgressBar(count($oldData)); $bar->start(); $startTime = time(); $total = 0; $error = []; foreach ($oldData as $value){ $goodsId = $value->id; // 判断店铺是否存在,如果商品的店铺不在,则不存这个商品 $storeExist = DB::table($oldStoreTableName)->where('id',$value->store_id)->exists(); if(!$storeExist){ continue; } $goodsData =[ // 'id'=>$value->id, 'market_id' => $oldStoreData[$value->store_id], 'store_id'=>$value->store_id, 'on_sale'=> $value->is_show == 1 ? 1 : 0, 'sort'=>$value->num, 'price'=>$value->money, 'original_price'=>$value->money2, 'vip_price'=>$value->vip_money, 'sales'=>$value->sales, 'start_num'=>$value->start_num, 'restrict_num'=>$value->restrict_num, 'is_infinite'=> $value->is_max == 1 ? 1 :0, 'inventory'=>$value->inventory, 'name'=>$value->name, 'cover_img'=>$value->logo, 'goods_unit'=>$value->good_unit, 'content'=> strip_tags($value->content), 'details'=> strip_tags($value->details), 'created_at' => time(), 'updated_at' => time(), ]; $specs = DB::table($oldSpecTableName)->where('good_id',$goodsId)->get(); if(count($specs) > 0){ foreach($specs as $vs){ $spec = ['spec_key'=>'净含量','spec_value'=>$vs->combination]; if(strstr($vs->combination,'辣')){ $spec['spec_key'] = '口味'; }else if(strstr($vs->combination,'馅')){ $spec['spec_key'] = '馅料'; }else if(strstr($vs->combination,'mm')){ $spec['spec_key'] = '尺寸'; } $goodsData['spec'] = json_encode([$spec]); $newData = $goodsData; $newBanner = [ 'type' =>1, 'path' =>$value->logo, 'created_at' =>time(), 'updated_at' =>time(), ]; $id = DB::table($newTableName)->insertGetId($newData); if(!$id){ $error[] = ['id'=>$goodsId]; break; } $newBanner['goods_id'] = $id; DB::table($newBannerTableName)->insertGetId($newBanner); $total++; } }else{ $newData = $goodsData; $res= $id = DB::table($newTableName)->insertGetId($newData); if(!$res){ $error[] = ['id'=>$goodsId]; break; } $newBanner['goods_id'] = $id; DB::table($newBannerTableName)->insertGetId($newBanner); $total++; } $bar->advance(); } $bar->finish(); var_dump([time()-$startTime]); var_dump($total); var_dump($error); return 0; } }