OwnerFeeDetailFactory.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /** @var \Illuminate\Database\Eloquent\Factory $factory */
  3. use App\OwnerFeeDetail;
  4. use Faker\Generator as Faker;
  5. $owner = \App\Owner::query()->whereNotNull('customer_id')->first();
  6. if ($owner)$shop = \App\Shop::query()->where("owner_id",$owner->id)->first();
  7. else $shop = null;
  8. $logistic = \App\Logistic::query()->first();
  9. $method = \App\ProcessMethod::query()->first();
  10. $factory->define(OwnerFeeDetail::class, function (Faker $faker)use(&$owner,&$shop,&$logistic,&$method) {
  11. if (!$owner)$owner = \App\Owner::query()->whereNotNull('customer_id')->first();
  12. if (!$shop){
  13. if ($owner)$shop = \App\Shop::query()->where("owner_id",$owner->id)->first();
  14. else $shop = null;
  15. }
  16. if (!$logistic) $logistic = \App\Logistic::query()->first();
  17. if (!$method)$method = \App\ProcessMethod::query()->first();
  18. $type = ["发货","收货","增值服务"];
  19. return [
  20. "owner_id" => $owner ? $owner->id : factory(\App\Owner::class), //货主ID
  21. "worked_at" => $faker->date(),//作业时间
  22. "type" =>$type[array_rand($type)],//类型
  23. "shop_id" =>$shop ? $shop->id : factory(\App\Shop::class),//店铺ID
  24. "operation_bill" => \Illuminate\Support\Str::random(10),//发/收/退/提货单号
  25. "consignee_name" => $faker->name, //收件人
  26. "consignee_phone" =>$faker->phoneNumber, //收件人电话
  27. "commodity_amount" =>mt_rand(0,100), //商品数量
  28. "logistic_bill" =>\Illuminate\Support\Str::random(12), //快递单号
  29. "volume" =>mt_rand(10,2600) / 88,//体积
  30. "weight" =>mt_rand(10,2600) / 88, //重量
  31. "logistic_id" =>$logistic ? $logistic->id : factory(\App\Logistic::class), //物流ID
  32. "process_method_id" =>$method ? $method->id : factory(\App\ProcessMethod::class),//加工类型ID
  33. "work_fee" =>mt_rand(100,10000) / 10, //作业费
  34. "logistic_fee" =>mt_rand(100,10000) / 10, //物流费
  35. ];
  36. });