调整产值

dev
vine_liutk 2022-11-07 14:32:36 +08:00
parent df7b480517
commit e6f39637ca
1 changed files with 9 additions and 8 deletions

View File

@ -17,26 +17,27 @@ class CropYieldSeeder extends Seeder
*/ */
public function run() public function run()
{ {
$crops = Crop::where('is_end', 1)->where('crop_type', 1)->get(); $type = 2;
$insertData = []; $bases = AgriculturalBase::where('type', $type)->get();
foreach ($crops as $crop) { foreach ($bases as $base){
$base = AgriculturalBase::where('type', 1)->inRandomOrder()->first(); for ($i = 2019; $i < 2023; $i++) {
for($i = 2019; $i < 2023; $i++){ $crop = Crop::where('is_end', 1)->where('crop_type', $type)->inRandomOrder()->first();
for($j = 1; $j< 5; $j++) { for ($j = 1; $j< 5; $j++) {
$insertData[] = [ $insertData[] = [
'base_id' => $base->id, 'base_id' => $base->id,
'crop_id' => $crop->id, 'crop_id' => $crop->id,
'category_id' => $crop->category_id, 'category_id' => $crop->category_id,
'time_year' => $i, 'time_year' => $i,
'quarter' => $j, 'quarter' => $j,
'yield' => rand(10000, 99999), 'yield' => rand(1000, 9999),
'cultivated'=> rand(100, 999), 'cultivated'=> rand(100, 999),
'output'=> rand(100000, 999999), 'output'=> rand(10000, 99999),
]; ];
} }
} }
} }
if(count($insertData) > 1){ if(count($insertData) > 1){
DB::table('crop_yields')->truncate(); DB::table('crop_yields')->truncate();
CropYield::insert($insertData); CropYield::insert($insertData);