whereNotNull("user_owner_group_id")->first(); $factory->define(OwnerBillReport::class, function (Faker $faker)use(&$owner) { if (!$owner)$owner = \App\Owner::query()->whereNotNull("user_owner_group_id")->first(); $initial_fee = mt_rand(0,50000) / 10; $confirm_fee = mt_rand(0,50000) / 10; return [ "owner_id" => $owner ? $owner->id : factory(\App\Owner::class), //项目ID "counting_month" => $faker->date(), //结算月 "initial_fee" => $initial_fee, //原始账单金额 "confirm_fee" => $confirm_fee, //确认账单金额 "difference" => $confirm_fee - $initial_fee, //差额 "confirmed" => "否", //确认状态 ]; });