调整产量假数据

dev
vine_liutk 2022-11-07 14:57:07 +08:00
parent 4793909b91
commit 35373b4bcd
1 changed files with 22 additions and 19 deletions

View File

@ -18,30 +18,33 @@ class CropYieldSeeder extends Seeder
public function run() public function run()
{ {
$type = 2; $type = 2;
//假数据逻辑每个地区每年随机一种农作物4个季度随机值 //假数据逻辑每个地区每年随机一种农作物4个季度随机值
$bases = AgriculturalBase::where('type', $type)->get(); $bases = AgriculturalBase::where('type', $type)->get();
foreach ($bases as $base){ foreach ($bases as $base){
for ($i = 2019; $i < 2023; $i++) { $insertData = [];
$crop = Crop::where('is_end', 1)->where('crop_type', $type)->inRandomOrder()->first(); //随机剔除一个农作物不加数据
for ($j = 1; $j< 5; $j++) { $uncrop = Crop::where('is_end', 1)->where('crop_type', $type)->inRandomOrder()->first();
$insertData[] = [ $crops = Crop::where('is_end', 1)->where('crop_type', $type)->where('id', '<>', $uncrop->id)->get();
'base_id' => $base->id, foreach ($crops as $crop){
'crop_id' => $crop->id, for ($i = 2019; $i < 2023; $i++) {
'category_id' => $crop->category_id, for ($j = 1; $j< 5; $j++) {
'time_year' => $i, $insertData[] = [
'quarter' => $j, 'base_id' => $base->id,
'yield' => rand(1000, 9999), 'crop_id' => $crop->id,
'cultivated'=> rand(100, 999), 'category_id' => $crop->category_id,
'output'=> rand(10000, 99999), 'time_year' => $i,
]; 'quarter' => $j,
'yield' => rand(1000, 9999),
'cultivated'=> rand(100, 999),
'output'=> rand(10000, 99999),
];
}
} }
} }
} if(count($insertData) > 1){
// DB::table('crop_yields')->truncate();
if(count($insertData) > 1){ CropYield::insert($insertData);
DB::table('crop_yields')->truncate(); }
CropYield::insert($insertData);
} }
} }
} }