Compare commits

..

No commits in common. "4793909b91d6ed4c919aa3ac00a6fa62ea1b0bbb" and "df7b480517b992cf8d074b37cad74b96ab7946fa" have entirely different histories.

1 changed files with 8 additions and 10 deletions

View File

@ -17,28 +17,26 @@ class CropYieldSeeder extends Seeder
*/
public function run()
{
$type = 2;
$crops = Crop::where('is_end', 1)->where('crop_type', 1)->get();
//假数据逻辑每个地区每年随机一种农作物4个季度随机值
$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 = [];
foreach ($crops as $crop) {
$base = AgriculturalBase::where('type', 1)->inRandomOrder()->first();
for($i = 2019; $i < 2023; $i++){
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(1000, 9999),
'yield' => rand(10000, 99999),
'cultivated'=> rand(100, 999),
'output'=> rand(10000, 99999),
'output'=> rand(100000, 999999),
];
}
}
}
if(count($insertData) > 1){
DB::table('crop_yields')->truncate();
CropYield::insert($insertData);