From e6f39637ca8078ba9a1ef0a1a74105c34948e910 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Mon, 7 Nov 2022 14:32:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BA=A7=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database/seeders/CropYieldSeeder.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/database/seeders/CropYieldSeeder.php b/database/seeders/CropYieldSeeder.php index c5c1816..f5d596d 100644 --- a/database/seeders/CropYieldSeeder.php +++ b/database/seeders/CropYieldSeeder.php @@ -17,26 +17,27 @@ class CropYieldSeeder extends Seeder */ public function run() { - $crops = Crop::where('is_end', 1)->where('crop_type', 1)->get(); + $type = 2; - $insertData = []; - foreach ($crops as $crop) { - $base = AgriculturalBase::where('type', 1)->inRandomOrder()->first(); - for($i = 2019; $i < 2023; $i++){ - for($j = 1; $j< 5; $j++) { + $bases = AgriculturalBase::where('type', $type)->get(); + foreach ($bases as $base){ + for ($i = 2019; $i < 2023; $i++) { + $crop = Crop::where('is_end', 1)->where('crop_type', $type)->inRandomOrder()->first(); + for ($j = 1; $j< 5; $j++) { $insertData[] = [ 'base_id' => $base->id, 'crop_id' => $crop->id, 'category_id' => $crop->category_id, 'time_year' => $i, 'quarter' => $j, - 'yield' => rand(10000, 99999), + 'yield' => rand(1000, 9999), 'cultivated'=> rand(100, 999), - 'output'=> rand(100000, 999999), + 'output'=> rand(10000, 99999), ]; } } } + if(count($insertData) > 1){ DB::table('crop_yields')->truncate(); CropYield::insert($insertData);